Add verifier coverage for callback subprograms that declare incoming
stack arguments. The test passes a nine-argument callback to bpf_loop()
and expects the verifier to reject it.

Assisted-by: Codex:gpt-5
Signed-off-by: Jérémy Jean <[email protected]>
---
 .../selftests/bpf/progs/verifier_stack_arg.c  | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c 
b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
index 7e0ce5db28a0..50b276fc2c3f 100644
--- a/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
+++ b/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
@@ -27,6 +27,13 @@ static int subprog_7args(int a, int b, int c, int d, int e, 
int f, int g)
        return a + b + c + d + e + f + g;
 }
 
+__noinline __used
+static int callback_9args(__u32 index, void *ctx, long a3, long a4,
+                         long a5, long a6, long a7, long a8, long a9)
+{
+       return a9;
+}
+
 __noinline __used
 static long subprog_deref_arg6(long a, long b, long c, long d, long e, long *f)
 {
@@ -79,6 +86,31 @@ __naked void stack_arg_two_subprogs(void)
        );
 }
 
+SEC("tc")
+__description("stack_arg: callback with incoming stack args")
+__failure
+__naked void stack_arg_callback_many_args(void)
+{
+       asm volatile (
+               "r6 = 0;"
+               "*(u64 *)(r11 - 32) = 0;"
+               "*(u64 *)(r11 - 24) = 0;"
+               "*(u64 *)(r11 - 16) = 0;"
+               "*(u64 *)(r11 - 8) = 0;"
+               "r1 = 1;"
+               "r2 = %[callback_9args];"
+               "r3 = 0;"
+               "r4 = 0;"
+               "call %[bpf_loop];"
+               "r0 = 0;"
+               "exit;"
+               :
+               : __imm_ptr(callback_9args),
+                 __imm(bpf_loop)
+               : __clobber_common, "r6"
+       );
+}
+
 SEC("tc")
 __description("stack_arg: read from uninitialized stack arg slot")
 __failure
-- 
2.47.3


Reply via email to