> selftests/bpf: Cover helper reads of invalid spill siblings
>
> Add a verifier_spill_fill case that passes an untouched byte next to a
> one-byte scalar spill to bpf_map_update_elem(). The full-capability load
> retains the existing uninitialized-stack behavior, while the CAP_BPF-only
> load must reject the STACK_INVALID helper read.
>
> Signed-off-by: Yiyang Chen <[email protected]>
This test covers a verifier bug where a helper read accepted an
uninitialized (STACK_INVALID) sibling byte next to a narrow (<8-byte) scalar
spill. That behavior came in when sub-8-byte scalar spill/refill support was
added, which left sibling bytes STACK_INVALID while the slot still reported a
spilled scalar.
Should this carry the same Fixes: tag as the companion verifier fix so stable
backports pull the test in alongside it?
Fixes: 354e8f1970f8 ("bpf: Support <8-byte scalar spill and refill")
> diff --git a/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
> b/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
> index 8b166c42c4e0e..e686f6d8d5656 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
[ ... ]
> @@ -1307,6 +1314,32 @@ __naked void
> stack_noperfmon_spill_32bit_onto_64bit_slot(void)
> : __clobber_all);
> }
>
> +SEC("socket")
> +__description("helper read must reject an invalid sibling of a narrow spill")
> +__success
> +__caps_unpriv(CAP_BPF)
> +__failure_unpriv __msg_unpriv("invalid read from stack R3 off -7+0 size 1")
> +__naked void helper_read_invalid_partial_spill_sibling(void)
> +{
> + asm volatile ("r5 = 1;\n\t"
> + "*(u8 *)(r10 - 8) = r5;\n\t"
> + "r2 = 0;\n\t"
> + "*(u32 *)(r10 - 16) = r2;\n\t"
this isn't a bug, but could this asm block use the same backslash
line-continuation style as the neighbouring tests in this file? The two
tests just above it, stack_noperfmon_reject_invalid_read() and
stack_noperfmon_spill_32bit_onto_64bit_slot(), write a single string with
trailing tab-backslash, and this is the only "\n\t" per-line block in
verifier_spill_fill.c.
> + "r1 = %[map_partial_spill] ll;\n\t"
> + "r2 = r10;\n\t"
> + "r2 += -16;\n\t"
> + "r3 = r10;\n\t"
> + "r3 += -7;\n\t"
> + "r4 = 0;\n\t"
> + "call %[bpf_map_update_elem];\n\t"
> + "r0 = 0;\n\t"
> + "exit;\n\t"
> + :
> + : __imm(bpf_map_update_elem),
> + __imm_addr(map_partial_spill)
> + : __clobber_all);
> +}
>
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/29229349078