From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15D05236A73 for ; Wed, 7 Jan 2026 20:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767818440; cv=none; b=mvd/Bwgit0lF+OIPsy+ZaYMIs0CHZ3Ho5krYuXYyXK8s0W+5bIMfEXCmtc7+VwKi7hXhPOyVb+kjfTLdkZmy1yvhyzEaSqSygKg/jKqwsf5HjTPeVT8GLpk5ErxLpRxLj0hjfuup9in6OR5/MaA9EhS6Cn3/9u9qXWxBpuVl3Ek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767818440; c=relaxed/simple; bh=YGms/BPfyqA9p3mN94Fmnsa/PjI6bcYTJ2lyjmNidrs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Iyg0x9m1pIqM4rMgvda47irHAh5tcZud5k/noVn8CvzKYbLAFTR+jb1pgmhpTdo4vjeQzX3CoEQBv+YMbJ9mECC1Bwn181OtFmpgzwbNVCvUiG9FWqLI2mmu5Di/an9HaQD2Bbuuxakv1fAcdqrkfhs/ysvSutdICE/yMjLR4dE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m3wWllin; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m3wWllin" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60623C4CEF1; Wed, 7 Jan 2026 20:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767818439; bh=YGms/BPfyqA9p3mN94Fmnsa/PjI6bcYTJ2lyjmNidrs=; h=From:To:Cc:Subject:Date:From; b=m3wWllin3D/MxysLVhK8rZ0GtZkUIl/joNgi73zN/3yYLguYJeXpUbCeYAX87IfEM ebYJngnsptAvxhxHpbupSxnV32zRxLw15UkmUIT6C0sC00BFaNi9NAnT4/6QA63ENS 10t8eJ0UIqMuhDJGNZDcxvQEp1sTCWhNkCL8i8WjQN02rTT9LoFXbpDVRFgqnpchdh C1LK3wX1BKoMsiaxj4N4mRPITgkf0Ss65DpqQoxPwSCLNa8jRMVwQvQWIx0MBw0791 aGORCanstfgNDVffKkHBJdRvGlCTut+SGSpkXuhczY5VRZ1515eNE54ImbnWgvUNZJ eqXjlmZzuoSvg== From: Puranjay Mohan To: bpf@vger.kernel.org Cc: Puranjay Mohan , Puranjay Mohan , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Mykyta Yatsenko , kernel-team@meta.com Subject: [PATCH bpf-next 0/3] bpf: Improve linked register tracking Date: Wed, 7 Jan 2026 12:39:33 -0800 Message-ID: <20260107203941.1063754-1-puranjay@kernel.org> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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