summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/ima_setup.sh
diff options
context:
space:
mode:
authorRoberto Sassu <roberto.sassu@huawei.com>2022-03-02 12:14:01 +0100
committerAlexei Starovoitov <ast@kernel.org>2022-03-10 18:57:54 -0800
commit91e8fa254dbd0890c34286acdc12e96412305840 (patch)
tree104a74b7fb4da33feca8414534af9c66594ca898 /tools/testing/selftests/bpf/ima_setup.sh
parent27a77d0d460cdeec57fda2bb6c4f8820ab6e8b38 (diff)
selftests/bpf: Check if the digest is refreshed after a file write
Verify that bpf_ima_inode_hash() returns a non-fresh digest after a file write, and that bpf_ima_file_hash() returns a fresh digest. Verification is done by requesting the digest from the bprm_creds_for_exec hook, called before ima_bprm_check(). Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20220302111404.193900-7-roberto.sassu@huawei.com
Diffstat (limited to 'tools/testing/selftests/bpf/ima_setup.sh')
-rwxr-xr-xtools/testing/selftests/bpf/ima_setup.sh24
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/ima_setup.sh b/tools/testing/selftests/bpf/ima_setup.sh
index 8e62581113a3..a3de1cd43ba0 100755
--- a/tools/testing/selftests/bpf/ima_setup.sh
+++ b/tools/testing/selftests/bpf/ima_setup.sh
@@ -12,7 +12,7 @@ LOG_FILE="$(mktemp /tmp/ima_setup.XXXX.log)"
usage()
{
- echo "Usage: $0 <setup|cleanup|run> <existing_tmp_dir>"
+ echo "Usage: $0 <setup|cleanup|run|modify-bin|restore-bin> <existing_tmp_dir>"
exit 1
}
@@ -77,6 +77,24 @@ run()
exec "${copied_bin_path}"
}
+modify_bin()
+{
+ local tmp_dir="$1"
+ local mount_dir="${tmp_dir}/mnt"
+ local copied_bin_path="${mount_dir}/$(basename ${TEST_BINARY})"
+
+ echo "mod" >> "${copied_bin_path}"
+}
+
+restore_bin()
+{
+ local tmp_dir="$1"
+ local mount_dir="${tmp_dir}/mnt"
+ local copied_bin_path="${mount_dir}/$(basename ${TEST_BINARY})"
+
+ truncate -s -4 "${copied_bin_path}"
+}
+
catch()
{
local exit_code="$1"
@@ -105,6 +123,10 @@ main()
cleanup "${tmp_dir}"
elif [[ "${action}" == "run" ]]; then
run "${tmp_dir}"
+ elif [[ "${action}" == "modify-bin" ]]; then
+ modify_bin "${tmp_dir}"
+ elif [[ "${action}" == "restore-bin" ]]; then
+ restore_bin "${tmp_dir}"
else
echo "Unknown action: ${action}"
exit 1