diff mbox series

[bpf-next,2/2] selftests/bpf: Update ima test helper's mount uuid logic

Message ID 20201201143924.2908241-2-kpsingh@chromium.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next,1/2] selftests/bpf: Update ima test helper's losetup commands | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

KP Singh Dec. 1, 2020, 2:39 p.m. UTC
From: KP Singh <kpsingh@google.com>

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: 34b82d3ac105 ("bpf: Add a selftest for bpf_ima_inode_hash")
Signed-off-by: KP Singh <kpsingh@google.com>
---
 tools/testing/selftests/bpf/ima_setup.sh | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/ima_setup.sh b/tools/testing/selftests/bpf/ima_setup.sh
index ed29bde26a12..7b8615c30c09 100755
--- a/tools/testing/selftests/bpf/ima_setup.sh
+++ b/tools/testing/selftests/bpf/ima_setup.sh
@@ -31,8 +31,24 @@  setup()
         mount "${loop_device}" "${mount_dir}"
 
         cp "${TEST_BINARY}" "${mount_dir}"
-        local mount_uuid="$(blkid -s UUID -o value ${loop_device})"
-        echo "measure func=BPRM_CHECK fsuuid=${mount_uuid}" > ${IMA_POLICY_FILE}
+        local mount_uuid=""
+        # This can be done with blkid -s UUID -o value ${loop_device} but
+        # blkid might not be available everywhere, especially in busybox
+        # environments.
+        for uuid in $(ls /dev/disk/by-uuid); do
+                local link_target="$(readlink -f /dev/disk/by-uuid/${uuid})"
+                if [[ "${loop_device}" == "${link_target}" ]]; then
+                        mount_uuid="${uuid}"
+                        break;
+                fi
+        done
+
+        if [[ -z "${mount_uuid}" ]]; then
+                echo "Could not find mount_uuid for ${loop_device}"
+                exit 1;
+        fi
+
+        echo "measure func=BPRM_CHECK fsuuid=${mount_uuid:?}" > ${IMA_POLICY_FILE}
 }
 
 cleanup() {