tools/testing/selftests/bpf/progs/cgroup_storage.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/cgroup_storage.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/cgroup_storage.c- Extension
.c- Size
- 1674 bytes
- Lines
- 68
- 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
linux/bpf.hbpf/bpf_helpers.h
Detected Declarations
function bpf_progfunction trigger_oob
Annotated Snippet
SEC("cgroup/sock_create")
int trigger_oob(struct bpf_sock *sk)
{
__u32 key = 0;
__u32 *cgroup_val;
__u32 value = 0x12345678;
/* Get cgroup storage value */
cgroup_val = bpf_get_local_storage(&cgroup_storage_oob, 0);
if (!cgroup_val)
return 0;
/* Initialize cgroup storage */
*cgroup_val = value;
/* This triggers the OOB read:
* bpf_map_update_elem() -> htab_map_update_elem() ->
* pcpu_init_value() -> copy_map_value_long() ->
* bpf_obj_memcpy(..., long_memcpy=true) ->
* bpf_long_memcpy(dst, src, round_up(4, 8))
*
* The copy size is rounded up to 8 bytes, but cgroup_val
* points to a 4-byte buffer, causing a 4-byte OOB read.
*/
bpf_map_update_elem(&lru_map, &key, cgroup_val, BPF_ANY);
return 1;
}
char _license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`.
- Detected declarations: `function bpf_prog`, `function trigger_oob`.
- 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.