tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c- Extension
.c- Size
- 12690 bytes
- Lines
- 399
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/types.hsys/socket.hsys/xattr.htest_progs.hbpf/btf.hlsm_cgroup.skel.hlsm_cgroup_nonvoid.skel.hcgroup_helpers.hnetwork_helpers.h
Detected Declarations
function query_prog_cntfunction test_lsm_cgroup_functionalfunction test_lsm_cgroup_nonvoidfunction test_lsm_cgroup_retvalfunction test_lsm_cgroup
Annotated Snippet
if (!ASSERT_OK(err, "attach first sock_create prog"))
goto cleanup_skipcap2;
err = bpf_prog_attach(socket_prog_fd2, cgroup_fd, BPF_LSM_CGROUP, BPF_F_ALLOW_MULTI);
if (!ASSERT_OK(err, "attach second sock_create prog"))
goto cleanup_sock_create1;
/* trigger the bool hook by setxattr */
err = setxattr(tmpfile, "user.test", "value", 5, 0);
if (!ASSERT_OK(err, "setxattr"))
goto cleanup_sock_create2;
/* trigger the errno hook by creating a socket */
fd = socket(AF_INET, SOCK_STREAM, 0);
if (!ASSERT_OK_FD(fd, "socket"))
goto cleanup_sock_create2;
close(fd);
ASSERT_EQ(skel->data->skipcap_retval, 0, "bool_hook_retval_should_be_0");
ASSERT_EQ(skel->data->socket_retval, -EPERM, "errno_hook_retval_should_be_EPERM");
cleanup_sock_create2:
bpf_prog_detach2(socket_prog_fd2, cgroup_fd, BPF_LSM_CGROUP);
cleanup_sock_create1:
bpf_prog_detach2(socket_prog_fd1, cgroup_fd, BPF_LSM_CGROUP);
cleanup_skipcap2:
bpf_prog_detach2(skipcap_prog_fd2, cgroup_fd, BPF_LSM_CGROUP);
cleanup_skipcap1:
bpf_prog_detach2(skipcap_prog_fd1, cgroup_fd, BPF_LSM_CGROUP);
cleanup_skeleton:
lsm_cgroup__destroy(skel);
cleanup_cgroup:
close(cgroup_fd);
cleanup_tmpfile:
unlink(tmpfile);
}
void test_lsm_cgroup(void)
{
if (test__start_subtest("functional"))
test_lsm_cgroup_functional();
if (test__start_subtest("nonvoid"))
test_lsm_cgroup_nonvoid();
if (test__start_subtest("retval"))
test_lsm_cgroup_retval();
btf__free(btf);
}
Annotation
- Immediate include surface: `sys/types.h`, `sys/socket.h`, `sys/xattr.h`, `test_progs.h`, `bpf/btf.h`, `lsm_cgroup.skel.h`, `lsm_cgroup_nonvoid.skel.h`, `cgroup_helpers.h`.
- Detected declarations: `function query_prog_cnt`, `function test_lsm_cgroup_functional`, `function test_lsm_cgroup_nonvoid`, `function test_lsm_cgroup_retval`, `function test_lsm_cgroup`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.