Skip to content

bpf: fork state when comparing sign crossing ranges with zero

Eduard Zingerman bpf sashiko-reviews 1 version In review

Get series with b4
b4 am [email protected] change-id 20260529-cnum-split-at-zero-3c03db9234d3

Versions newest first

  1. v1 Latest2 patches 10 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: fork state when comparing sign crossing ranges with zerokernel/bpf/verifier.c+71 -03 replies
2/2selftests/bpf: test fork on zero comparison with wrapping rangestools/testing/selftests/bpf/progs/verifier_bounds.c+68 -01 reply

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchEmil Tsalapatis
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH bpf 0/2] bpf: fork state when comparing sign crossing ranges with zero

YiFei Zhu reported [1] the verifier regression after switch to cnum based scalars representation. When the following sequence of instructions is processed:

1: ... rX setup with [negative, positive] bounds ... 2: if rX == 0 goto ...
3: if rX > C goto ...
4: ... code relying on rX being in range [1, C] ...

The cnum-based implementation only infers that rX range is [0, C] at instruction (4). The pre-cnum signed/unsigned ranges based representation could always deduct from 'rX != 0' that umin bound is 1.

This patch introduces a workaround forking the verifier state when a register with sign-crossing range is compared to zero.

[1] https://lore.kernel.org/bpf/[email protected]/T/

---
Eduard Zingerman (2):
bpf: fork state when comparing sign crossing ranges with zero selftests/bpf: test fork on zero comparison with wrapping ranges

 kernel/bpf/verifier.c                              | 71 ++++++++++++++++++++++
 .../testing/selftests/bpf/progs/verifier_bounds.c  | 68 +++++++++++++++++++++
 2 files changed, 139 insertions(+)

---
base-commit: e42e53ae23b7d41df22ccd7788192bf578f24da2
change-id: 20260529-cnum-split-at-zero-3c03db9234d3