]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Add test for narrow spill into 64-bit spilled scalar
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Wed, 4 Dec 2024 04:47:57 +0000 (20:47 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 4 Dec 2024 17:19:50 +0000 (09:19 -0800)
Add a test case to verify that without CAP_PERFMON, the test now
succeeds instead of failing due to a verification error.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20241204044757.1483141-6-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/verifier_spill_fill.c

index bab6d789ba007b0655e1d84fcac56bfb0448775f..1e5a511e8494afa75883f02a5ac1bfdf734e6988 100644 (file)
@@ -1262,4 +1262,21 @@ __naked void stack_noperfmon_reject_invalid_read(void)
 "      ::: __clobber_all);
 }
 
+SEC("socket")
+__description("stack_noperfmon: narrow spill onto 64-bit scalar spilled slots")
+__success
+__caps_unpriv(CAP_BPF)
+__success_unpriv
+__naked void stack_noperfmon_spill_32bit_onto_64bit_slot(void)
+{
+       asm volatile("                                  \
+       r0 = 0;                                         \
+       *(u64 *)(r10 - 8) = r0;                         \
+       *(u32 *)(r10 - 8) = r0;                         \
+       exit;                                           \
+"      :
+       :
+       : __clobber_all);
+}
+
 char _license[] SEC("license") = "GPL";