Commit 3db98044 authored by KP Singh's avatar KP Singh Committed by Andrii Nakryiko

selftests/bpf: Update ima_setup.sh for busybox

losetup on busybox does not output the name of loop device on using
-f with --show. It also doesn't support -j to find the loop devices
for a given backing file. losetup is updated to use "-a" which is
available on busybox.

blkid does not support options (-s and -o) to only display the uuid, so
parse the output instead.

Not all environments have mkfs.ext4, the test requires a loop device
with a backing image file which could formatted with any filesystem.
Update to using mkfs.ext2 which is available on busybox.

Fixes: 34b82d3a ("bpf: Add a selftest for bpf_ima_inode_hash")
Reported-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarKP Singh <kpsingh@google.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201203191437.666737-2-kpsingh@chromium.org
parent 61b75948
......@@ -3,6 +3,7 @@
set -e
set -u
set -o pipefail
IMA_POLICY_FILE="/sys/kernel/security/ima/policy"
TEST_BINARY="/bin/true"
......@@ -23,13 +24,15 @@ setup()
dd if=/dev/zero of="${mount_img}" bs=1M count=10
local loop_device="$(losetup --find --show ${mount_img})"
losetup -f "${mount_img}"
local loop_device=$(losetup -a | grep ${mount_img:?} | cut -d ":" -f1)
mkfs.ext4 "${loop_device}"
mkfs.ext2 "${loop_device:?}"
mount "${loop_device}" "${mount_dir}"
cp "${TEST_BINARY}" "${mount_dir}"
local mount_uuid="$(blkid -s UUID -o value ${loop_device})"
local mount_uuid="$(blkid ${loop_device} | sed 's/.*UUID="\([^"]*\)".*/\1/')"
echo "measure func=BPRM_CHECK fsuuid=${mount_uuid}" > ${IMA_POLICY_FILE}
}
......@@ -38,7 +41,8 @@ cleanup() {
local mount_img="${tmp_dir}/test.img"
local mount_dir="${tmp_dir}/mnt"
local loop_devices=$(losetup -j ${mount_img} -O NAME --noheadings)
local loop_devices=$(losetup -a | grep ${mount_img:?} | cut -d ":" -f1)
for loop_dev in "${loop_devices}"; do
losetup -d $loop_dev
done
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment