0001
0002
0003
0004
0005
0006
0007 #include <linux/bpf.h>
0008 #include <errno.h>
0009 #include <bpf/bpf_helpers.h>
0010 #include <bpf/bpf_tracing.h>
0011
0012 char _license[] SEC("license") = "GPL";
0013
0014 struct {
0015 __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
0016 __uint(map_flags, BPF_F_NO_PREALLOC);
0017 __type(key, int);
0018 __type(value, int);
0019 } secure_exec_task_map SEC(".maps");
0020
0021 SEC("lsm/bprm_creds_for_exec")
0022 int BPF_PROG(secure_exec, struct linux_binprm *bprm)
0023 {
0024 int *secureexec;
0025
0026 secureexec = bpf_task_storage_get(&secure_exec_task_map,
0027 bpf_get_current_task_btf(), 0,
0028 BPF_LOCAL_STORAGE_GET_F_CREATE);
0029
0030 if (secureexec && *secureexec)
0031 bpf_bprm_opts_set(bprm, BPF_F_BPRM_SECUREEXEC);
0032
0033 return 0;
0034 }