Skip to content

RFC Improve signed ranges reasoning for BPF_AND

Shung-Hsi Yu bpf 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest3 patches 3 repliesIn review
  2. v1 RFC1 patch 1 replySuperseded

Changes in v2 from the cover letter

- address comments
- add code comment in scalar*_min_max_and() to better explaining the reasoning (Eduard, Alexei)
- point out unsigned range are still propagated to signed range later in __reg_deduce_bounds() (Edward)
- point out the fls(~v) special case in negative_bit_floor() (Edward)
- revert workaround added in 229d6db14942
- add additional tests
- v1 can be found at both
- https://lore.kernel.org/bpf/[email protected]/
- https://lore.kernel.org/bpf/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3bpf, verifier: improve signed ranges reasoning for BPF_ANDkernel/bpf/verifier.c tools/testing/selftests/bpf/progs/test_libbpf_get_fd_by_id_opts.c+85 -210 replies
2/3selftests/bpf: bring back verifier tests for bpf lsmtools/testing/selftests/bpf/progs/verifier_lsm.c+16 -00 replies
3/3selftests/bpf: add more verifier tests for signed range deduction of BPF_ANDtools/testing/selftests/bpf/progs/verifier_and.c+56 -03 replies

Reviews trailers per patch

1 of 3 patches has a Reviewed-by or Acked-by.

PatchEduard ZingermanEdward CreeHarishankar Vishwanathan
1/3A-b R-b T-b
2/3
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [RFC bpf-next v2 0/3] Improve signed ranges reasoning for BPF_AND

RFC because the selftests in the 3rd patch is failing and I couldn't figure out what's going on, sending out for suggestion.

This is a follow up of Xu Kuohai's "Add BPF LSM return value range check, BPF part" series[1], where the 5th patch "improve signed ranges inference for BPF_AND" was omitting because further changes were required. This series brough back that patch (with modifications as requested), removed workaround, and bring back 'test 3'[2] from Xu Kuohai that was also dropped.

Patch 1 add reasoning of signed ranges directly from previous signed ranges during BPF_AND to the BPF verfier, which allowed better tracking of signed range for situation like [-1, 0] & -13. See the patch for complete detail.

Patch 2 and 3 are corresponding tests. Patch 2 brings back an omitted test[2] from Xu Kuohai. Patch 3 add more specific test in verifier_and.c.

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

Changes since v1:
- address comments
- add code comment in scalar*_min_max_and() to better explaining the reasoning (Eduard, Alexei)
- point out unsigned range are still propagated to signed range later in __reg_deduce_bounds() (Edward)
- point out the fls(~v) special case in negative_bit_floor() (Edward)
- revert workaround added in 229d6db14942
- add additional tests
- v1 can be found at both
- https://lore.kernel.org/bpf/[email protected]/
- https://lore.kernel.org/bpf/[email protected]/

Shung-Hsi Yu (3):
bpf, verifier: improve signed ranges inference for BPF_AND selftests/bpf: bring back verifier tests for bpf lsm selftests/bpf: add more verifier tests for signed range deduction of
BPF_AND

 kernel/bpf/verifier.c                         | 105 ++++++++++++++----
 .../bpf/progs/test_libbpf_get_fd_by_id_opts.c |   1 -
 .../selftests/bpf/progs/verifier_and.c        |  56 ++++++++++
 .../selftests/bpf/progs/verifier_lsm.c        |  16 +++
 4 files changed, 157 insertions(+), 21 deletions(-)
Signature · 1 line
2.47.0