tools/testing/selftests/bpf/progs/uninit_stack.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/uninit_stack.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/uninit_stack.c
Extension
.c
Size
2220 bytes
Lines
90
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

static __noinline void dummy(void) {}

/* Pass a pointer to uninitialized stack memory to a helper.
 * Passed memory block should be marked as STACK_MISC after helper call.
 */
SEC("socket")
__log_level(7) __msg("fp-104=mmmmmmmm")
__naked int helper_uninit_to_misc(void *ctx)
{
	asm volatile ("					\
		/* force stack depth to be 128 */	\
		*(u64*)(r10 - 128) = r1;		\
		r1 = r10;				\
		r1 += -128;				\
		r2 = 32;				\
		r3 = 0;					\
		call %[bpf_probe_read_user];		\
		/* Call to dummy() forces print_verifier_state(..., true),	\
		 * thus showing the stack state, matched by __msg().		\
		 */					\
		call %[dummy];				\
		r1 = *(u64*)(r10 - 104);		\
		r0 = 0;					\
		exit;					\
"
		      :
		      : __imm(bpf_probe_read_user),
			__imm(dummy)
		      : __clobber_all);
}

char _license[] SEC("license") = "GPL";

Annotation

Implementation Notes