tools/testing/selftests/bpf/progs/verifier_helper_access_var_len.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_helper_access_var_len.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_helper_access_var_len.c- Extension
.c- Size
- 20811 bytes
- Lines
- 826
- 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.hbpf_misc.h
Detected Declarations
struct test_valfunction bitwise_and_jmp_correct_boundsfunction __msg_unprivfunction __msgfunction memory_stack_jmp_correct_boundsfunction stack_jmp_signed_correct_boundsfunction __msgfunction __msgfunction stack_jmp_no_max_checkfunction __msg_unprivfunction __msgfunction memory_map_jmp_correct_boundsfunction __msgfunction map_adjusted_jmp_correct_boundsfunction __msgfunction __retvalfunction __msgfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __msgfunction __msgfunction ptr_to_mem_or_null_10function ptr_to_mem_or_null_11function ptr_to_mem_or_null_12function ptr_to_mem_or_null_13function __msg_unprivfunction bytes_no_leak_init_memory
Annotated Snippet
struct test_val {
unsigned int index;
int foo[MAX_ENTRIES];
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1);
__type(key, long long);
__type(value, struct test_val);
} map_hash_48b SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1);
__type(key, long long);
__type(value, long long);
} map_hash_8b SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 4096);
} map_ringbuf SEC(".maps");
SEC("tracepoint")
__description("helper access to variable memory: stack, bitwise AND + JMP, correct bounds")
__success
__naked void bitwise_and_jmp_correct_bounds(void)
{
asm volatile (" \
r1 = r10; \
r1 += -64; \
r0 = 0; \
*(u64*)(r10 - 64) = r0; \
*(u64*)(r10 - 56) = r0; \
*(u64*)(r10 - 48) = r0; \
*(u64*)(r10 - 40) = r0; \
*(u64*)(r10 - 32) = r0; \
*(u64*)(r10 - 24) = r0; \
*(u64*)(r10 - 16) = r0; \
*(u64*)(r10 - 8) = r0; \
r2 = 16; \
*(u64*)(r1 - 128) = r2; \
r2 = *(u64*)(r1 - 128); \
r2 &= 64; \
r4 = 0; \
if r4 >= r2 goto l0_%=; \
r3 = 0; \
call %[bpf_probe_read_kernel]; \
l0_%=: r0 = 0; \
exit; \
" :
: __imm(bpf_probe_read_kernel)
: __clobber_all);
}
SEC("socket")
__description("helper access to variable memory: stack, bitwise AND, zero included")
/* in privileged mode reads from uninitialized stack locations are permitted */
__success __failure_unpriv
__msg_unpriv("invalid read from stack R2 off -64+0 size 64")
__retval(0)
__naked void stack_bitwise_and_zero_included(void)
{
asm volatile (" \
/* set max stack size */ \
r6 = 0; \
*(u64*)(r10 - 128) = r6; \
/* set r3 to a random value */ \
call %[bpf_get_prandom_u32]; \
r3 = r0; \
/* use bitwise AND to limit r3 range to [0, 64] */\
r3 &= 64; \
r1 = %[map_ringbuf] ll; \
r2 = r10; \
r2 += -64; \
r4 = 0; \
/* Call bpf_ringbuf_output(), it is one of a few helper functions with\
* ARG_CONST_SIZE_OR_ZERO parameter allowed in unpriv mode.\
* For unpriv this should signal an error, because memory at &fp[-64] is\
* not initialized. \
*/ \
call %[bpf_ringbuf_output]; \
exit; \
" :
: __imm(bpf_get_prandom_u32),
__imm(bpf_ringbuf_output),
__imm_addr(map_ringbuf)
: __clobber_all);
}
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `struct test_val`, `function bitwise_and_jmp_correct_bounds`, `function __msg_unpriv`, `function __msg`, `function memory_stack_jmp_correct_bounds`, `function stack_jmp_signed_correct_bounds`, `function __msg`, `function __msg`, `function stack_jmp_no_max_check`, `function __msg_unpriv`.
- 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.