Skip to content

Commit 75a2725

Browse files
sinkapkernel-patches-bot
authored andcommitted
selftests/bpf: Update ima test helper's mount uuid logic
The test uses blkid to determine the uuid which may not be available on every system. Switch the logic to a good-old for loop iterating over /dev/disk/by-uuid and reading the symlinks to find the correct UUID for a given loop device Fixes: 34b82d3 ("bpf: Add a selftest for bpf_ima_inode_hash") Signed-off-by: KP Singh <kpsingh@google.com>
1 parent 8fe9580 commit 75a2725

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tools/testing/selftests/bpf/ima_setup.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,24 @@ setup()
3131
mount "${loop_device}" "${mount_dir}"
3232

3333
cp "${TEST_BINARY}" "${mount_dir}"
34-
local mount_uuid="$(blkid -s UUID -o value ${loop_device})"
35-
echo "measure func=BPRM_CHECK fsuuid=${mount_uuid}" > ${IMA_POLICY_FILE}
34+
local mount_uuid=""
35+
# This can be done with blkid -s UUID -o value ${loop_device} but
36+
# blkid might not be available everywhere, especially in busybox
37+
# environments.
38+
for uuid in $(ls /dev/disk/by-uuid); do
39+
local link_target="$(readlink -f /dev/disk/by-uuid/${uuid})"
40+
if [[ "${loop_device}" == "${link_target}" ]]; then
41+
mount_uuid="${uuid}"
42+
break;
43+
fi
44+
done
45+
46+
if [[ -z "${mount_uuid}" ]]; then
47+
echo "Could not find mount_uuid for ${loop_device}"
48+
exit 1;
49+
fi
50+
51+
echo "measure func=BPRM_CHECK fsuuid=${mount_uuid:?}" > ${IMA_POLICY_FILE}
3652
}
3753

3854
cleanup() {

0 commit comments

Comments
 (0)