mbox series

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

Message ID 20241119114023.397450-1-shung-hsi.yu@suse.com (mailing list archive)
Headers show
Series Improve signed ranges reasoning for BPF_AND | expand

Message

Shung-Hsi Yu Nov. 19, 2024, 11:40 a.m. UTC
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/20240719110059.797546-1-xukuohai@huaweicloud.com/
2: https://lore.kernel.org/bpf/20240719110059.797546-10-xukuohai@huaweicloud.com/

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/20240719110059.797546-6-xukuohai@huaweicloud.com/
  - https://lore.kernel.org/bpf/9505522b-de45-cf52-162b-76a3a52a6efe@gmail.com/

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(-)