public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 1/4] bpf: Fix linked reg delta tracking when src_reg == dst_reg
@ 2026-04-07 19:24 Daniel Borkmann
  2026-04-07 19:24 ` [PATCH bpf-next 2/4] bpf: Clear delta when clearing reg id for non-{add,sub} ops Daniel Borkmann
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Daniel Borkmann @ 2026-04-07 19:24 UTC (permalink / raw)
  To: bpf; +Cc: ast, puranjay, info

Consider the case of rX += rX where src_reg and dst_reg are pointers to
the same bpf_reg_state in adjust_reg_min_max_vals(). The latter first
modifies the dst_reg in-place, and later in the delta tracking, the
subsequent is_reg_const(src_reg)/reg_const_value(src_reg) reads the
post-{add,sub} value instead of the original source.

This is problematic since it sets an incorrect delta, which sync_linked_regs()
then propagates to linked registers, thus creating a verifier-vs-runtime
mismatch. Fix it by just skipping this corner case.

Fixes: 98d7ca374ba4 ("bpf: Track delta between "linked" registers.")
Reported-by: STAR Labs SG <info@starlabs.sg>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
 kernel/bpf/verifier.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1bebbdb3b693..d83e17cccd38 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -16722,7 +16722,8 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
 	 */
 	if (env->bpf_capable &&
 	    (BPF_OP(insn->code) == BPF_ADD || BPF_OP(insn->code) == BPF_SUB) &&
-	    dst_reg->id && is_reg_const(src_reg, alu32)) {
+	    dst_reg->id && is_reg_const(src_reg, alu32) &&
+	    !(BPF_SRC(insn->code) == BPF_X && insn->src_reg == insn->dst_reg)) {
 		u64 val = reg_const_value(src_reg, alu32);
 		s32 off;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-04-08  1:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 19:24 [PATCH bpf-next 1/4] bpf: Fix linked reg delta tracking when src_reg == dst_reg Daniel Borkmann
2026-04-07 19:24 ` [PATCH bpf-next 2/4] bpf: Clear delta when clearing reg id for non-{add,sub} ops Daniel Borkmann
2026-04-07 19:24 ` [PATCH bpf-next 3/4] selftests/bpf: Add tests for delta tracking when src_reg == dst_reg Daniel Borkmann
2026-04-07 19:24 ` [PATCH bpf-next 4/4] selftests/bpf: Add tests for stale delta leaking through id reassignment Daniel Borkmann
2026-04-08  1:20 ` [PATCH bpf-next 1/4] bpf: Fix linked reg delta tracking when src_reg == dst_reg patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox