bpf: Enhance freplace compatibility
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 11 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | bpf: Disallow freplace on XDP with mismatched xdp_has_frags valueskernel/ | +4 | 7 replies | |
| 2/3 | bpf: Disallow freplace on kprobe with mismatched kprobe_write_ctx valueskernel/ | +8 | 4 replies | |
| 3/3 | selftests/bpf: Add tests to verify freplace compatibilitytools/ tools/ | +164 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH bpf-next 0/3] bpf: Enhance freplace compatibility
The potential issue of kprobe_write_ctx+freplace was mentioned in "bpf: Disallow !kprobe_write_ctx progs tail-calling kprobe_write_ctx progs" [1].
It is true issue, that the test in patch #3 verifies that kprobe_write_ctx=false kprobe progs can be abused to modify struct pt_regs via kprobe_write_ctx=true freplace progs.
When struct pt_regs is modified, bpf_prog_test_run_opts() gets -EFAULT instead of 0.
test_kprobe_write_ctx:FAIL:bpf_prog_test_run_opts unexpected error: -14 (errno 14)
We will disallow freplace on kprobe programs with different kprobe_write_ctx values.
However, xdp_has_frags does not cause such severe issue.
The issue of xdp_has_frags+freplace is that it is able to break the backwards compatibility of XDP.
At the commit f45d5b6ce2e8 ("bpf: generalise tail call map compatibility check"), the backwards compatibility was protected against tail calls, but it missed the freplace case, which is also able to extend XDP progs. If xdp_has_frags=true freplace progs are allowed to attach to xdp_has_frags=false XDP progs, the backwards compatibility is broken.
We will disallow freplace on XDP programs with different xdp_has_frags values, like the way in bpf_prog_map_compatible().
Links:
[1] https://lore.kernel.org/bpf/CAP01T74w4KVMn9bEwpQXrk+bqcUxzb6VW1SQ_QvNy0A4EY-9Jg@mail.gmail.com/
Leon Hwang (3):
bpf: Disallow freplace on XDP with mismatched xdp_has_frags values
bpf: Disallow freplace on kprobe with mismatched kprobe_write_ctx
values
selftests/bpf: Add tests to verify freplace compatibility
kernel/bpf/verifier.c | 12 ++ .../bpf/prog_tests/freplace_compatible.c | 124 ++++++++++++++++++ .../selftests/bpf/progs/freplace_compatible.c | 40 ++++++ 3 files changed, 176 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/freplace_compatible.c create mode 100644 tools/testing/selftests/bpf/progs/freplace_compatible.c
Signature · 1 line
2.53.0