BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 1/3] selftests/bpf: Update ima_setup.sh for busybox
@ 2020-12-02 22:39 KP Singh
  2020-12-02 22:39 ` [PATCH bpf-next v2 2/3] selftests/bpf: Ensure securityfs mount before writing ima policy KP Singh
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: KP Singh @ 2020-12-02 22:39 UTC (permalink / raw)
  To: bpf; +Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann

From: KP Singh <kpsingh@google.com>

* losetup on busybox does not output the name of loop device on using
  -f with --show. It also dosn'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.
* 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: 34b82d3ac105 ("bpf: Add a selftest for bpf_ima_inode_hash")
Reported-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: KP Singh <kpsingh@google.com>
---
 tools/testing/selftests/bpf/ima_setup.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/ima_setup.sh b/tools/testing/selftests/bpf/ima_setup.sh
index 15490ccc5e55..d864c62c1207 100755
--- a/tools/testing/selftests/bpf/ima_setup.sh
+++ b/tools/testing/selftests/bpf/ima_setup.sh
@@ -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
-- 
2.29.2.576.ga3fc446d84-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-03  0:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-02 22:39 [PATCH bpf-next v2 1/3] selftests/bpf: Update ima_setup.sh for busybox KP Singh
2020-12-02 22:39 ` [PATCH bpf-next v2 2/3] selftests/bpf: Ensure securityfs mount before writing ima policy KP Singh
2020-12-02 22:44   ` KP Singh
2020-12-02 23:13   ` Andrii Nakryiko
2020-12-03  0:49     ` KP Singh
2020-12-02 22:39 ` [PATCH bpf-next v2 3/3] selftests/bpf: Add config dependency on BLK_DEV_LOOP KP Singh
2020-12-02 22:43   ` KP Singh
2020-12-02 23:13 ` [PATCH bpf-next v2 1/3] selftests/bpf: Update ima_setup.sh for busybox Andrii Nakryiko
2020-12-03  0:51   ` KP Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox