bpf: Clear scalar delta on narrowing stack spill
Daniel Borkmann
maintainerPATCH 1/1 bpf: Clear scalar delta on narrowing stack spill
check_stack_write_fixed_off() breaks the scalar link on a narrowing spill by zeroing the id of the destination stack slot, but leaves the delta in place. save_register_state() has just copied the source register verbatim, so the slot keeps the BPF_ADD_CONST delta of a register it is no longer linked to. This is the same shape as the case addressed in 1b327732c846 ("bpf: Clear delta when clearing reg id for non-{add,sub} ops"). Unlike the latter, no miscomputation seems reachable, so mainly consistency.
---
[ noticed while reviewing clear_scalar_id locations ]
kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/verifier.c +1 -1
@@ -3582,7 +3582,7 @@ static int check_stack_write_fixed_off(struct bpf_verifier_env *env,save_register_state (env, state, spi, reg, size);/* Break the relation on a narrowing spill. */ if (!reg_value_fits) - state->stack[spi].spilled_ptr.id =0 ; +clear_scalar_id (&state->stack[spi].spilled_ptr); }else if (!reg && !(off %BPF_REG_SIZE ) &&is_bpf_st_mem (insn) && env->bpf_capable) {struct bpf_reg_state *tmp_reg = &env->fake_reg[0 ];
Signature · 1 line
2.43.0
Quoted 10 lines · Daniel Borkmann
check_stack_write_fixed_off()breaks the scalar link on a narrowing spill by zeroing the id of the destination stack slot, but leaves the delta in place.save_register_state()has just copied the source register verbatim, so the slot keeps theBPF_ADD_CONSTdelta of a register it is no longer linked to. This is the same shape as the case addressed in1b327732c846("bpf: Clear delta when clearing reg id for non-{add,sub} ops"). Unlike the latter, no miscomputation seems reachable, so mainly consistency.Signed-off-by Daniel Borkmann <[email protected]>---
It appears there are no other instances.
Remaining .id = 0 are for non-scalar types.
...
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Thu, 10 Sep 2026 20:56:04 +0200 you wrote:
check_stack_write_fixed_off()breaks the scalar link on a narrowing spill by zeroing the id of the destination stack slot, but leaves the delta in place.save_register_state()has just copied the source register verbatim, so the slot keeps theBPF_ADD_CONSTdelta of a register it is no longer linked to. This is the same shape as the case addressed in1b327732c846("bpf: Clear delta when clearing reg id for non-{add,sub} ops"). Unlike the latter, no miscomputation seems reachable, so mainly consistency.[...]
Here is the summary with links:
- [bpf] bpf: Clear scalar delta on narrowing stack spill
https://git.kernel.org/bpf/bpf/c/2936aed9b021
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html