Fix generic __uninit kfunc output buffers
Status from this message: This series was applied to bpf/bpf-next.git (master)
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest11 patches 0 repliesApplied 11/11
- v48 patches 4 repliesSuperseded
- v35 patches 4 repliesSuperseded
Earlier versions · 2
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v2 | 5 patches | 1 reply | Superseded | |
| v1 | 3 patches | 5 replies | Superseded |
Changes in v5 from the cover letter
v4: https://lore.kernel.org/bpf/[email protected]
* Check __uninit kfunc outputs as write-only and mark generated kfunc buffers MEM_WRITE, replacing the kfunc-specific access override. (Amery)
* Derive memory access from MEM_WRITE and MEM_UNINIT after relaxing the MEM_UNINIT contract, so partial-output helpers keep write-only map destinations while input/output helpers gain read checks. (Eduard, Amery, Sashiko)
* Move the helper read-access fix and its permission tests after the MEM_UNINIT relaxation, and drop its Fixes tag: it only closes a write-only map permission gap for input/output helpers.
* Reuse the raw-memory predicate after type resolution and clarify how argument ordering affects output tracking. (Eduard, BPF CI)
* Keep prospective struct-output counting separate from raw-memory checks.
* Clarify the __uninit buffer contract and privilege rules. (BPF CI, Eduard)
* Add read-only FIB rejection and partial-output write-only map coverage. (BPF CI)
* Carry Eduard's Acked-by on the generic __uninit fix.
* Allow partial initialization for all generic MEM_UNINIT buffers and annotate partial-output helpers with MEM_UNINIT. (Eduard)
* Preserve per-byte initialization and prior stack liveness for generic outputs when uninitialized stack reads are not allowed. (Eduard)
* Retain output classification when variable sizes disable raw mode.
* Cover stricter readback rules for full-writing helpers and kfuncs.
* Retain helper-argument fallback coverage using map_update_elem inputs.
Patches in v5 All 11 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/11 | selftests/bpf: Allow privileged preparation for capability teststools/ tools/ tools/ +1 more | +55 | 0 replies | Applied |
| 2/11 | bpf: Record raw memory arguments during argument checkingkernel/ | +14 | 0 replies | Applied |
| 3/11 | bpf: Check __uninit kfunc output buffers as write-onlykernel/ | +7 | 0 replies | Applied |
| 4/11 | bpf: Fix generic __uninit kfunc output buffersDocumentation/ include/ kernel/ | +81 | 0 replies | Applied |
| 5/11 | selftests/bpf: Cover generic __uninit output initializationtools/ tools/ tools/ +1 more | +130 | 0 replies | Applied |
| 6/11 | bpf: Support multiple __uninit kfunc output argumentsinclude/ kernel/ | +28 | 0 replies | Applied |
| 7/11 | selftests/bpf: Cover __uninit kfunc output argument slotstools/ tools/ tools/ +1 more | +139 | 0 replies | Applied |
| 8/11 | bpf: Preserve stack initialization for generic output buffersDocumentation/ include/ include/ +4 more | +54 | 0 replies | Applied |
| 9/11 | selftests/bpf: Cover generic output stack initializationtools/ tools/ tools/ +4 more | +356 | 0 replies | Applied |
| 10/11 | bpf: Check read access for helper input/output bufferskernel/ | +15 | 0 replies | Applied |
| 11/11 | selftests/bpf: Cover helper memory access permissionstools/ tools/ | +231 | 0 replies | Applied |
Reviews trailers per patch
2 of 11 patches have a Reviewed-by or Acked-by.
| Patch | Eduard Zingerman | Amery Hung |
|---|---|---|
| 1/11 | ||
| 2/11 | ||
| 3/11 | ||
| 4/11 | A-b | |
| 5/11 | R-b | |
| 6/11 | ||
| 7/11 | ||
| 8/11 | ||
| 9/11 | ||
| 10/11 | ||
| 11/11 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH bpf-next v5 00/11] Fix generic __uninit kfunc output buffers
Generic __uninit kfunc arguments are output buffers. Stack liveness treats them as writes, but argument checking still requires readable contents and does not record definite initialization after the call. Check these arguments as write-only and record privileged output initialization after validating all inputs, including inputs that alias an output.
Following Eduard's rework, helpers and kfuncs record generic outputs in the same argument-checking path after type resolution. Generated kfunc prototypes now mark generic buffers with MEM_WRITE, so __uninit buffers are checked as write-only ahead of the fix while ordinary buffers stay read/write.
The final two patches derive memory access from MEM_WRITE and MEM_UNINIT alone, so input/output helpers such as bpf_check_mtu() require read as well as write permission without a new prototype field, and add the permission tests.
Changelog:
----------
v4 -> v5
v4: https://lore.kernel.org/bpf/[email protected]
* Check __uninit kfunc outputs as write-only and mark generated kfunc buffers MEM_WRITE, replacing the kfunc-specific access override. (Amery)
* Derive memory access from MEM_WRITE and MEM_UNINIT after relaxing the MEM_UNINIT contract, so partial-output helpers keep write-only map destinations while input/output helpers gain read checks. (Eduard, Amery, Sashiko)
* Move the helper read-access fix and its permission tests after the MEM_UNINIT relaxation, and drop its Fixes tag: it only closes a write-only map permission gap for input/output helpers.
* Reuse the raw-memory predicate after type resolution and clarify how argument ordering affects output tracking. (Eduard, BPF CI)
* Keep prospective struct-output counting separate from raw-memory checks.
* Clarify the __uninit buffer contract and privilege rules. (BPF CI, Eduard)
* Add read-only FIB rejection and partial-output write-only map coverage. (BPF CI)
* Carry Eduard's Acked-by on the generic __uninit fix.
* Allow partial initialization for all generic MEM_UNINIT buffers and annotate partial-output helpers with MEM_UNINIT. (Eduard)
* Preserve per-byte initialization and prior stack liveness for generic outputs when uninitialized stack reads are not allowed. (Eduard)
* Retain output classification when variable sizes disable raw mode.
* Cover stricter readback rules for full-writing helpers and kfuncs.
* Retain helper-argument fallback coverage using map_update_elem inputs.
v3 -> v4
v3: https://lore.kernel.org/bpf/[email protected]
* Record helper and kfunc outputs after type resolution. (Eduard, Amery)
* Derive generic memory access from flags for helpers and kfuncs. (Eduard)
* Fix MEM_WRITE read checks separately and add permission tests. (Eduard)
* Remove the output-count validator in the multiple-output extension. (Amery)
* Clarify argument-slot naming and move its accessor into the fix. (BPF CI)
* Add the unaligned header and order the new test registrations. (BPF CI)
* Shorten the kfunc fix description while retaining its rationale. (BPF CI)
v2 -> v3
v2: https://lore.kernel.org/bpf/[email protected]
* Reuse check_raw_mode_ok() after kfunc prototype generation, including struct outputs resolved to generic memory later. (Amery)
* Remove the now-redundant kfunc output-count check in the multiple-output extension and simplify the helper validator.
* Leave the stack-passed output uninitialized so the reduced-capability test detects missing __uninit handling. (Sashiko)
v1 -> v2
v1: https://lore.kernel.org/bpf/[email protected]
* Separate the single-output fix and tests from multiple-output support and its tests; reduce coverage to focused cases. (Eduard)
* Skip inactive output slots before looking up argument register state. (Sashiko, Amery)
* Separate sysctl restrictions from mitigation-related test skips. (BPF CI)
* Use an int-width initialization store in the alias test for big-endian targets. (BPF CI)
* Centralize conversion from argument numbers to slots. (Eduard)
* Share clear access-mode selection between fixed-size and sized arguments. (Amery)
* Clarify the opt-in prepare/load capability boundary and retain the reduced-capability alias rejection test. (Eduard)
Eduard Zingerman (3):
bpf: Record raw memory arguments during argument checking
bpf: Check read access for helper input/output buffers selftests/bpf: Cover helper memory access permissions
Kumar Kartikeya Dwivedi (8):
selftests/bpf: Allow privileged preparation for capability tests
bpf: Check __uninit kfunc output buffers as write-only
bpf: Fix generic __uninit kfunc output buffers selftests/bpf: Cover generic __uninit output initialization
bpf: Support multiple __uninit kfunc output arguments selftests/bpf: Cover __uninit kfunc output argument slots
bpf: Preserve stack initialization for generic output buffers selftests/bpf: Cover generic output stack initialization
Documentation/bpf/kfuncs.rst | 27 +- include/linux/bpf.h | 5 +- include/linux/bpf_verifier.h | 13 +- kernel/bpf/cgroup.c | 2 +- kernel/bpf/helpers.c | 2 +- kernel/bpf/verifier.c | 167 +++++---- kernel/trace/bpf_trace.c | 6 +- .../selftests/bpf/prog_tests/verifier.c | 4 + tools/testing/selftests/bpf/progs/bpf_misc.h | 9 +- .../progs/verifier_helper_access_var_len.c | 332 ++++++++++++++++++ .../bpf/progs/verifier_kfunc_uninit.c | 236 +++++++++++++ .../bpf/progs/verifier_kfunc_uninit_multi.c | 113 ++++++ .../selftests/bpf/progs/verifier_live_stack.c | 33 +- .../selftests/bpf/progs/verifier_mtu.c | 88 +++++ .../selftests/bpf/progs/verifier_raw_stack.c | 4 + .../selftests/bpf/test_kmods/bpf_testmod.c | 52 +++ .../bpf/test_kmods/bpf_testmod_kfunc.h | 8 + tools/testing/selftests/bpf/test_loader.c | 48 ++- tools/testing/selftests/bpf/unpriv_helpers.c | 16 +- tools/testing/selftests/bpf/unpriv_helpers.h | 2 + 20 files changed, 1046 insertions(+), 121 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/verifier_kfunc_uninit.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_kfunc_uninit_multi.c
base-commit: b99f71407ce529ba01a9392f477522d2e76c6613
Signature · 1 line
2.53.0