From: KP Singh <kpsingh@chromium.org>
To: bpf@vger.kernel.org
Cc: Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Subject: [PATCH bpf-next v4 1/4] selftests/bpf: Update ima_setup.sh for busybox
Date: Thu, 3 Dec 2020 19:14:34 +0000 [thread overview]
Message-ID: <20201203191437.666737-2-kpsingh@chromium.org> (raw)
In-Reply-To: <20201203191437.666737-1-kpsingh@chromium.org>
From: KP Singh <kpsingh@google.com>
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: 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>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
---
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..137f2d32598f 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
next prev parent reply other threads:[~2020-12-03 19:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-03 19:14 [PATCH bpf-next v4 0/4] Fixes for ima selftest KP Singh
2020-12-03 19:14 ` KP Singh [this message]
2020-12-03 19:14 ` [PATCH bpf-next v4 2/4] selftests/bpf: Ensure securityfs mount before writing ima policy KP Singh
2020-12-03 19:14 ` [PATCH bpf-next v4 3/4] selftests/bpf: Add config dependency on BLK_DEV_LOOP KP Singh
2020-12-03 19:14 ` [PATCH bpf-next v4 4/4] selftests/bpf: Indent ima_setup.sh with tabs KP Singh
2020-12-03 19:26 ` [PATCH bpf-next v4 0/4] Fixes for ima selftest Andrii Nakryiko
2020-12-04 0:53 ` KP Singh
2020-12-03 19:30 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201203191437.666737-2-kpsingh@chromium.org \
--to=kpsingh@chromium.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).