Skip to content

bpf: allow s32/u32 return types in verifier for bpf helpers

Yonghong Song bpf 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 3 repliesIn review
  2. v12 patches 1 replySuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3bpf: add a helper to set preciseness of an unknown registerkernel/bpf/verifier.c+9 -30 replies
2/3bpf: allow s32/u32 return types in verifier for bpf helpersinclude/linux/bpf.h include/linux/tnum.h kernel/bpf/helpers.c +4 more+54 -223 replies
3/3tools/bpf: add verifier test for s32/u32 helper return valuestools/testing/selftests/bpf/verifier/helper_ret.c+50 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH bpf-next v2 0/3] bpf: allow s32/u32 return types in verifier for bpf helpers

Currently, for all helpers with integer return type, the verifier permits a single return type, RET_INTEGER, which represents 64-bit return value from the helper, and the verifier will assign 64-bit value ranges for these return values. Such an assumption is different from what compiler sees and the generated code with llvm alu32 mode, and may lead verification failure.

This patch set enhanced verifier to handle s32/u32 helper return values properly to avoid verification failure due to conservative return value range marking.
Patch #1 refactored the verifier code to have an internal helper
which will be used in Patch #2.
Patch #2 added 32-bit helper return type support.
The commit message has details of explanation.
Patch #3 added two test cases to selftests test_verifier.

Yonghong Song (3):
bpf: add a helper to set preciseness of an unknown register
bpf: allow s32/u32 return types in verifier for bpf helpers tools/bpf: add verifier test for s32/u32 helper return values

 include/linux/bpf.h                           |  4 +-
 include/linux/tnum.h                          |  3 +-
 kernel/bpf/helpers.c                          |  8 +--
 kernel/bpf/tnum.c                             |  3 +-
 kernel/bpf/verifier.c                         | 50 ++++++++++++++++---
 kernel/trace/bpf_trace.c                      |  4 +-
 net/core/filter.c                             | 16 +++---
 .../selftests/bpf/verifier/helper_ret.c       | 50 +++++++++++++++++++
 8 files changed, 113 insertions(+), 25 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/verifier/helper_ret.c
Signature · 1 line
2.17.1