xref: /linux/tools/testing/selftests/bpf/progs/test_signed_loader_lsm.c (revision b2128290c29902315e632ea59e0504d6bc9e9b42)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include "vmlinux.h"
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 
7 char _license[] SEC("license") = "GPL";
8 
9 __u32 monitored_tid;
10 
11 int sig_keyring_serial;
12 int sig_keyring_type;
13 int sig_verdict;
14 int seen;
15 
16 SEC("lsm/bpf_prog_load")
17 int BPF_PROG(inspect_prog_load, struct bpf_prog *prog, union bpf_attr *attr,
18 	     struct bpf_token *token, bool kernel)
19 {
20 	__u32 tid = bpf_get_current_pid_tgid() & 0xffffffff;
21 
22 	if (!monitored_tid || tid != monitored_tid)
23 		return 0;
24 
25 	seen++;
26 	sig_keyring_serial = prog->aux->sig.keyring_serial;
27 	sig_keyring_type = prog->aux->sig.keyring_type;
28 	sig_verdict = prog->aux->sig.verdict;
29 	return 0;
30 }
31