tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c- Extension
.c- Size
- 5288 bytes
- Lines
- 259
- 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
libarena/common.hlibarena/asan.hlibarena/buddy.htest_progs_compat.hst_asan_common.h
Detected Declarations
struct buddy_blobfunction asan_test_buddy_oob_singlefunction asan_test_buddy_bytefunction asan_test_buddy_uaf_singlefunction asan_test_buddy_blob_singlefunction asan_test_buddy_oobfunction asan_test_buddy_uaffunction asan_test_buddy_blob
Annotated Snippet
struct buddy_blob {
volatile u8 mem[48];
u8 oob;
};
static __always_inline int asan_test_buddy_blob_single(void)
{
volatile struct buddy_blob __arena *blob;
const size_t alloc_size = sizeof(struct buddy_blob) - 1;
int ret;
blob = buddy_alloc(&buddy, alloc_size);
if (!blob)
return -ENOMEM;
blob->mem[0] = 0xba;
ret = asan_validate_addr(false, &blob->mem[0]);
if (ret < 0)
return ret;
blob->mem[47] = 0xba;
ret = asan_validate_addr(false, &blob->mem[47]);
if (ret < 0)
return ret;
blob->oob = 0;
ret = asan_validate_addr(true, &blob->oob);
if (ret < 0)
return ret;
buddy_free(&buddy, (void __arena *)blob);
return 0;
}
SEC("syscall")
__stderr("Memory violation for address {{.*}} for write of size 1")
__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
__stderr("Call trace:\n"
"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
"|[ \t]+[^\n]+\n)*}}")
__weak int asan_test_buddy_oob(void)
{
size_t sizes[] = {
7, 8, 17, 18, 64, 256, 317, 512, 1024,
};
int ret, i;
ret = buddy_init(&buddy);
if (ret) {
arena_stdout("buddy_init failed with %d", ret);
return ret;
}
for (i = zero; i < sizeof(sizes) / sizeof(sizes[0]) && can_loop; i++) {
ret = asan_test_buddy_oob_single(sizes[i]);
if (ret) {
arena_stdout("%s:%d Failed for size %lu", __func__,
__LINE__, sizes[i]);
buddy_destroy(&buddy);
return ret;
}
}
buddy_destroy(&buddy);
ret = asan_validate();
if (ret < 0)
return ret;
return 0;
}
SEC("syscall")
__stderr("Memory violation for address {{.*}} for write of size 1")
__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
__stderr("Call trace:\n"
"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
"|[ \t]+[^\n]+\n)*}}")
__weak int asan_test_buddy_uaf(void)
{
size_t sizes[] = { 16, 32, 64, 128, 256, 512, 1024, 16384 };
int ret, i;
ret = buddy_init(&buddy);
if (ret) {
arena_stdout("buddy_init failed with %d", ret);
return ret;
}
Annotation
- Immediate include surface: `libarena/common.h`, `libarena/asan.h`, `libarena/buddy.h`, `test_progs_compat.h`, `st_asan_common.h`.
- Detected declarations: `struct buddy_blob`, `function asan_test_buddy_oob_single`, `function asan_test_buddy_byte`, `function asan_test_buddy_uaf_single`, `function asan_test_buddy_blob_single`, `function asan_test_buddy_oob`, `function asan_test_buddy_uaf`, `function asan_test_buddy_blob`.
- 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.