1 // SPDX-License-Identifier: GPL-2.0
4 #include <bpf/bpf_helpers.h>
7 /* Read an uninitialized value from stack at a fixed offset */
9 __naked int read_uninit_stack_fixed_off(void *ctx)
13 /* force stack depth to be 128 */ \
14 *(u64*)(r10 - 128) = r1; \
15 r1 = *(u8 *)(r10 - 8 ); \
17 r1 = *(u8 *)(r10 - 11); \
18 r1 = *(u8 *)(r10 - 13); \
19 r1 = *(u8 *)(r10 - 15); \
20 r1 = *(u16*)(r10 - 16); \
21 r1 = *(u32*)(r10 - 32); \
22 r1 = *(u64*)(r10 - 64); \
23 /* read from a spill of a wrong size, it is a separate \
24 * branch in check_stack_read_fixed_off() \
26 *(u32*)(r10 - 72) = r1; \
27 r1 = *(u64*)(r10 - 72); \
34 /* Read an uninitialized value from stack at a variable offset */
36 __naked int read_uninit_stack_var_off(void *ctx)
39 call %[bpf_get_prandom_u32]; \
40 /* force stack depth to be 64 */ \
41 *(u64*)(r10 - 64) = r0; \
43 /* give r0 a range [-31, -1] */ \
44 if r0 s<= -32 goto exit_%=; \
45 if r0 s>= 0 goto exit_%=; \
46 /* access stack using r0 */ \
49 r2 = *(u8*)(r1 + 0); \
54 : __imm(bpf_get_prandom_u32)
58 static __noinline void dummy(void) {}
60 /* Pass a pointer to uninitialized stack memory to a helper.
61 * Passed memory block should be marked as STACK_MISC after helper call.
64 __log_level(7) __msg("fp-104=mmmmmmmm")
65 __naked int helper_uninit_to_misc(void *ctx)
68 /* force stack depth to be 128 */ \
69 *(u64*)(r10 - 128) = r1; \
73 call %[bpf_trace_printk]; \
74 /* Call to dummy() forces print_verifier_state(..., true), \
75 * thus showing the stack state, matched by __msg(). \
82 : __imm(bpf_trace_printk),
87 char _license[] SEC("license") = "GPL";