From: KP Singh <kpsingh@chromium.org>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Subject: [PATCH bpf-next v2 2/3] selftests/bpf: Ensure securityfs mount before writing ima policy
Date: Wed, 2 Dec 2020 22:39:43 +0000 [thread overview]
Message-ID: <20201202223944.456903-2-kpsingh@chromium.org> (raw)
In-Reply-To: <20201202223944.456903-1-kpsingh@chromium.org>
From: KP Singh <kpsingh@google.com>
SecurityFS may not be mounted even if it is enabled in the kernel
config.
Signed-off-by: KP Singh <kpsingh@google.com>
---
tools/testing/selftests/bpf/ima_setup.sh | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/bpf/ima_setup.sh b/tools/testing/selftests/bpf/ima_setup.sh
index d864c62c1207..1da2d97a0e72 100755
--- a/tools/testing/selftests/bpf/ima_setup.sh
+++ b/tools/testing/selftests/bpf/ima_setup.sh
@@ -14,6 +14,20 @@ usage()
exit 1
}
+ensure_mount_securityfs()
+{
+ local securityfs_dir=$(grep "securityfs" /proc/mounts | awk '{print $2}')
+
+ if [ -z "${securityfs_dir}" ]; then
+ securityfs_dir=/sys/kernel/security
+ mount -t securityfs security "${securityfs_dir}"
+ fi
+
+ if [ ! -d "${securityfs_dir}" ]; then
+ echo "${securityfs_dir} :securityfs is not mounted" && exit 1
+ fi
+}
+
setup()
{
local tmp_dir="$1"
@@ -33,6 +47,7 @@ setup()
cp "${TEST_BINARY}" "${mount_dir}"
local mount_uuid="$(blkid ${loop_device} | sed 's/.*UUID="\([^"]*\)".*/\1/')"
+ ensure_mount_securityfs
echo "measure func=BPRM_CHECK fsuuid=${mount_uuid}" > ${IMA_POLICY_FILE}
}
--
2.29.2.576.ga3fc446d84-goog
next prev parent reply other threads:[~2020-12-02 22:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` KP Singh [this message]
2020-12-02 22:44 ` [PATCH bpf-next v2 2/3] selftests/bpf: Ensure securityfs mount before writing ima policy 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
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=20201202223944.456903-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