[PATCH v3 0/2] bpf, verifier: Improve precision of BPF_ADD and BPF_SUB

From: Harishankar Vishwanathan
Date: Mon Jun 23 2025 - 00:04:46 EST


This patchset improves the precision of BPF_ADD and BPF_SUB range
tracking. It also adds selftests that exercise the cases where precision
improvement occurs, and selftests for the cases where precise bounds
cannot be computed and the output register state values are set to
unbounded.

Changelog:

v3:
* Improve readability in selftests and commit message by using
more readable constants (suggested by Eduard Zingerman).
* Add four new selftests for the cases where precise output register
state bounds cannot be computed in scalar(32)_min_max_add/sub, so the
output register state must be set to unbounded, i.e., [0, U64_MAX]
or [0, U32_MAX].
* Add suggested-by Eduard tag to commit message for changes to
verifier_bounds.c

v2:
* Add clearer example of precision improvement in the commit message for
verifier.c changes.
* Add selftests that exercise the precision improvement to
verifier_bounds.c (suggested by Eduard Zingerman).

v1:
https://lore.kernel.org/bpf/20250610221356.2663491-1-harishankar.vishwanathan@xxxxxxxxx/

Harishankar Vishwanathan (2):
bpf, verifier: Improve precision for BPF_ADD and BPF_SUB
selftests/bpf: Add testcases for BPF_ADD and BPF_SUB

kernel/bpf/verifier.c | 76 ++++++---
.../selftests/bpf/progs/verifier_bounds.c | 161 ++++++++++++++++++
2 files changed, 217 insertions(+), 20 deletions(-)

--
2.45.2