bpf: Fix abs(INT_MIN) undefined behavior in interpreter sdiv/smod
Status from this message: This series was applied to bpf/bpf.git (master)
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest2 patches 0 repliesApplied 2/2
- v42 patches 4 repliesSuperseded
- v32 patches 2 repliesSuperseded
Earlier versions · 2
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v2 | 2 patches | 2 replies | Superseded | |
| v1 | 2 patches | 0 replies | Superseded |
Changes in v5 from the cover letter
- Renamed __safe_abs32() to abs_s32() and dropped inline keyword per Alexei Starovoitov's feedback
Patches in v5 All 2 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | bpf: Fix undefined behavior in interpreter sdiv/smod for INT_MINkernel/ | +14 | 0 replies | Applied |
| 2/2 | selftests/bpf: Add tests for sdiv32/smod32 with INT_MIN dividendtools/ | +58 | 0 replies | Applied |
Reviews trailers per patch
All 2 patches have a Reviewed-by or Acked-by.
| Patch | Yonghong Song | Mykyta Yatsenko | Jiayuan Chen |
|---|---|---|---|
| 1/2 | A-b | A-b | |
| 2/2 | A-b | R-b |
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.
Cover letter [PATCH v5 0/2] bpf: Fix abs(INT_MIN) undefined behavior in interpreter sdiv/smod
The BPF interpreter's signed 32-bit division and modulo handlers use abs() on s32 operands, which is undefined for S32_MIN. This causes the interpreter to compute wrong results, creating a mismatch with the verifier's range tracking.
For example, INT_MIN / 2 returns 0x40000000 instead of the correct 0xC0000000. The verifier tracks the correct range, so a crafted BPF program can exploit the mismatch for out-of-bounds map value access (confirmed by KASAN).
Patch 1 introduces abs_s32() which handles S32_MIN correctly and replaces all 8 abs((s32)...) call sites. s32 is the only affected case -- the s64 handlers do not use abs().
Patch 2 adds selftests covering sdiv32 and smod32 with INT_MIN dividend to prevent regression.
Changes since v4:
- Renamed __safe_abs32() to abs_s32() and dropped inline keyword per Alexei Starovoitov's feedback
Changes since v3:
- Fixed stray blank line deletion in the file header
- Improved comment per Yonghong Song's suggestion
- Added JIT vs interpreter context to selftest commit message
Changes since v2:
- Simplified to use -(u32)x per Mykyta Yatsenko's suggestion
Changes since v1:
- Moved helper above kerneldoc comment block to fix build warnings
Jenny Guanni Qu (2):
bpf: Fix undefined behavior in interpreter sdiv/smod for INT_MIN selftests/bpf: Add tests for sdiv32/smod32 with INT_MIN dividend
kernel/bpf/core.c | 22 ++++--- .../selftests/bpf/progs/verifier_sdiv.c | 58 +++++++++++++++++++ 2 files changed, 72 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1