summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/ima.c
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-11 03:57:54 +0100
commit91e8fa254dbd0890c34286acdc12e96412305840 (patch)
tree104a74b7fb4da33feca8414534af9c66594ca898 /tools/testing/selftests/bpf/progs/ima.c
parentselftests/bpf: Add test for bpf_ima_file_hash() (diff)
downloadlinux-91e8fa254dbd0890c34286acdc12e96412305840.tar.xz
linux-91e8fa254dbd0890c34286acdc12e96412305840.zip
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 '')
-rw-r--r--tools/testing/selftests/bpf/progs/ima.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/ima.c b/tools/testing/selftests/bpf/progs/ima.c
index e0b073dcfb5d..9633e5f2453d 100644
--- a/tools/testing/selftests/bpf/progs/ima.c
+++ b/tools/testing/selftests/bpf/progs/ima.c
@@ -19,6 +19,7 @@ struct {
char _license[] SEC("license") = "GPL";
bool use_ima_file_hash;
+bool enable_bprm_creds_for_exec;
static void ima_test_common(struct file *file)
{
@@ -54,3 +55,13 @@ void BPF_PROG(bprm_committed_creds, struct linux_binprm *bprm)
{
ima_test_common(bprm->file);
}
+
+SEC("lsm.s/bprm_creds_for_exec")
+int BPF_PROG(bprm_creds_for_exec, struct linux_binprm *bprm)
+{
+ if (!enable_bprm_creds_for_exec)
+ return 0;
+
+ ima_test_common(bprm->file);
+ return 0;
+}