BPF List
 help / color / mirror / Atom feed
From: Puranjay Mohan <puranjay@kernel.org>
To: bpf@vger.kernel.org
Cc: Puranjay Mohan <puranjay@kernel.org>,
	Puranjay Mohan <puranjay12@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
	kernel-team@meta.com
Subject: [PATCH bpf-next 0/3] bpf: Improve linked register tracking
Date: Wed,  7 Jan 2026 12:39:33 -0800	[thread overview]
Message-ID: <20260107203941.1063754-1-puranjay@kernel.org> (raw)

This series extends the BPF verifier's linked register tracking to handle
negative offsets and BPF_SUB operations, enabling better bounds propagation for
common arithmetic patterns.

The verifier previously only tracked positive constant deltas between linked
registers using BPF_ADD. This meant patterns using negative offsets or
subtraction couldn't benefit from bounds propagation:

  r1 = r0
  r1 += -4
  if r1 s>= 0 goto ...   // r1 >= 0 implies r0 >= 4
  // verifier couldn't propagate bounds back to r0

Patch 1 extends scalar_min_max_add() to:
  - Accept BPF_SUB in addition to BPF_ADD (treating r1 -= 4 as r1 += -4)
  - Change the overflow check to properly validate s32 range
  - Add a guard against S32_MIN negation overflow
  - Retain the !alu32 restriction due to known issues with 32-bit ALU upper bits

Patches 2-3 update the selftests:
  - Patch 2 adds comprehensive tests covering success cases (negative offsets,
    BPF_SUB), failure cases (32-bit ALU, double ADD), and large delta edge cases
    (S32_MIN/S32_MAX offsets)
  - Patch 3 updates an existing test's expected output to reflect the new
    tracking behavior

Puranjay Mohan (3):
  bpf: Support negative offsets and BPF_SUB for linked register tracking
  selftests/bpf: Add tests for linked register tracking with negative
    offsets
  selftests/bpf: Update expected output for sub64_partial_overflow test

 kernel/bpf/verifier.c                         |  26 ++-
 .../selftests/bpf/progs/verifier_bounds.c     |   2 +-
 .../bpf/progs/verifier_linked_scalars.c       | 213 ++++++++++++++++++
 3 files changed, 233 insertions(+), 8 deletions(-)


base-commit: 2175ccfb93fd91d0ece74684eb7ab9443de806ec
-- 
2.47.3


             reply	other threads:[~2026-01-07 20:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-07 20:39 Puranjay Mohan [this message]
2026-01-07 20:39 ` [PATCH bpf-next 1/3] bpf: Support negative offsets and BPF_SUB for linked register tracking Puranjay Mohan
2026-01-08  1:40   ` Eduard Zingerman
2026-01-08  1:47     ` Eduard Zingerman
2026-01-08  2:53       ` Alexei Starovoitov
2026-01-07 20:39 ` [PATCH bpf-next 2/3] selftests/bpf: Add tests for linked register tracking with negative offsets Puranjay Mohan
2026-01-08  2:11   ` Eduard Zingerman
2026-01-21  0:46     ` __description(). Was: " Alexei Starovoitov
2026-01-08  6:55   ` Eduard Zingerman
2026-01-08 11:33     ` Puranjay Mohan
2026-01-07 20:39 ` [PATCH bpf-next 3/3] selftests/bpf: Update expected output for sub64_partial_overflow test Puranjay Mohan
2026-01-08  6:59   ` Eduard Zingerman
2026-01-08 10:39     ` Puranjay Mohan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260107203941.1063754-1-puranjay@kernel.org \
    --to=puranjay@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=puranjay12@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox