tools/testing/selftests/bpf/progs/verifier_ref_tracking.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_ref_tracking.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_ref_tracking.c- Extension
.c- Size
- 38166 bytes
- Lines
- 1496
- 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../../../include/linux/filter.hbpf_misc.h
Detected Declarations
struct bpf_keystruct test_valfunction __kfunc_btf_rootfunction dummy_prog_42_tcfunction dummy_prog_24_tcfunction dummy_prog_loop1_tcfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction acquire_release_user_key_referencefunction acquire_release_system_key_referencefunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __retvalfunction __msgfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __attribute__function __msgfunction __attribute__function __msgfunction __attribute__function __retvalfunction __attribute__function __msgfunction __attribute__function __attribute__function __retvalfunction __attribute__function __attribute__function __retvalfunction __msgfunction __retvalfunction __msgfunction __retval
Annotated Snippet
struct bpf_key {} __attribute__((preserve_access_index));
extern void bpf_key_put(struct bpf_key *key) __ksym;
extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym;
extern struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
/* BTF FUNC records are not generated for kfuncs referenced
* from inline assembly. These records are necessary for
* libbpf to link the program. The function below is a hack
* to ensure that BTF FUNC records are generated.
*/
void __kfunc_btf_root(void)
{
bpf_key_put(0);
bpf_lookup_system_key(0);
bpf_lookup_user_key(0, 0);
}
#define MAX_ENTRIES 11
struct test_val {
unsigned int index;
int foo[MAX_ENTRIES];
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, struct test_val);
} map_array_48b SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 4096);
} map_ringbuf SEC(".maps");
void dummy_prog_42_tc(void);
void dummy_prog_24_tc(void);
void dummy_prog_loop1_tc(void);
struct {
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
__uint(max_entries, 4);
__uint(key_size, sizeof(int));
__array(values, void (void));
} map_prog1_tc SEC(".maps") = {
.values = {
[0] = (void *)&dummy_prog_42_tc,
[1] = (void *)&dummy_prog_loop1_tc,
[2] = (void *)&dummy_prog_24_tc,
},
};
SEC("tc")
__auxiliary
__naked void dummy_prog_42_tc(void)
{
asm volatile ("r0 = 42; exit;");
}
SEC("tc")
__auxiliary
__naked void dummy_prog_24_tc(void)
{
asm volatile ("r0 = 24; exit;");
}
SEC("tc")
__auxiliary
__naked void dummy_prog_loop1_tc(void)
{
asm volatile (" \
r3 = 1; \
r2 = %[map_prog1_tc] ll; \
call %[bpf_tail_call]; \
r0 = 41; \
exit; \
" :
: __imm(bpf_tail_call),
__imm_addr(map_prog1_tc)
: __clobber_all);
}
SEC("tc")
__description("reference tracking: leak potential reference")
__failure __msg("Unreleased reference")
__naked void reference_tracking_leak_potential_reference(void)
{
asm volatile (
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `../../../include/linux/filter.h`, `bpf_misc.h`.
- Detected declarations: `struct bpf_key`, `struct test_val`, `function __kfunc_btf_root`, `function dummy_prog_42_tc`, `function dummy_prog_24_tc`, `function dummy_prog_loop1_tc`, `function __msg`, `function __msg`, `function __msg`, `function __msg`.
- 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.