Commit 2746de3c authored by Roberto Sassu's avatar Roberto Sassu Committed by Alexei Starovoitov
Browse files

selftests/bpf: Move sample generation code to ima_test_common()



Move sample generator code to ima_test_common() so that the new function
can be called by multiple LSM hooks.

Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220302111404.193900-5-roberto.sassu@huawei.com
parent 174b1694
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -18,8 +18,7 @@ struct {

char _license[] SEC("license") = "GPL";

SEC("lsm.s/bprm_committed_creds")
void BPF_PROG(ima, struct linux_binprm *bprm)
static void ima_test_common(struct file *file)
{
	u64 ima_hash = 0;
	u64 *sample;
@@ -28,7 +27,7 @@ void BPF_PROG(ima, struct linux_binprm *bprm)

	pid = bpf_get_current_pid_tgid() >> 32;
	if (pid == monitored_pid) {
		ret = bpf_ima_inode_hash(bprm->file->f_inode, &ima_hash,
		ret = bpf_ima_inode_hash(file->f_inode, &ima_hash,
					 sizeof(ima_hash));
		if (ret < 0 || ima_hash == 0)
			return;
@@ -43,3 +42,9 @@ void BPF_PROG(ima, struct linux_binprm *bprm)

	return;
}

SEC("lsm.s/bprm_committed_creds")
void BPF_PROG(bprm_committed_creds, struct linux_binprm *bprm)
{
	ima_test_common(bprm->file);
}