1 // SPDX-License-Identifier: GPL-2.0
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_tracing.h>
6 #include <linux/capability.h>
8 struct kernel_cap_struct {
10 } __attribute__((preserve_access_index));
13 struct kernel_cap_struct cap_effective;
14 } __attribute__((preserve_access_index));
16 char _license[] SEC("license") = "GPL";
18 SEC("lsm.s/userns_create")
19 int BPF_PROG(test_userns_create, const struct cred *cred, int ret)
21 struct kernel_cap_struct caps = cred->cap_effective;
22 __u64 cap_mask = BIT_LL(CAP_SYS_ADMIN);
28 if (caps.val & cap_mask)