aboutsummaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/sendmsg_unix_prog.c
diff options
context:
space:
mode:
authorAndrii Nakryiko <[email protected]>2023-11-30 10:52:28 -0800
committerAlexei Starovoitov <[email protected]>2023-12-06 10:03:00 -0800
commitdc5196fac40c2cb96330bcb98eef868a7fd225b3 (patch)
treeadfd0beabe2cf3afa09142802dab5eea60323f27 /tools/testing/selftests/bpf/progs/sendmsg_unix_prog.c
parent1571740a9ba036f26cc5211a86021199987219e8 (diff)
selftests/bpf: add BPF token-enabled tests
Add a selftest that attempts to conceptually replicate intended BPF token use cases inside user namespaced container. Child process is forked. It is then put into its own userns and mountns. Child creates BPF FS context object. This ensures child userns is captured as the owning userns for this instance of BPF FS. Given setting delegation mount options is privileged operation, we ensure that child cannot set them. This context is passed back to privileged parent process through Unix socket, where parent sets up delegation options, creates, and mounts it as a detached mount. This mount FD is passed back to the child to be used for BPF token creation, which allows otherwise privileged BPF operations to succeed inside userns. We validate that all of token-enabled privileged commands (BPF_BTF_LOAD, BPF_MAP_CREATE, and BPF_PROG_LOAD) work as intended. They should only succeed inside the userns if a) BPF token is provided with proper allowed sets of commands and types; and b) namespaces CAP_BPF and other privileges are set. Lacking a) or b) should lead to -EPERM failures. Based on suggested workflow by Christian Brauner ([0]). [0] https://lore.kernel.org/bpf/20230704-hochverdient-lehne-eeb9eeef785e@brauner/ Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/sendmsg_unix_prog.c')
0 files changed, 0 insertions, 0 deletions