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.

Dependency Surface

Detected Declarations

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

Implementation Notes