Skip to content

Fix fastcall rewrite with indirect stack accesses

Kumar Kartikeya Dwivedi bpf 2 versions – Applied

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

  1. v2 Latest2 patches 0 repliesApplied 2/2
  2. v13 patches 1 replySuperseded

Changes in v2 from the cover letter

v1: https://lore.kernel.org/bpf/[email protected]

* Check the contract once in check_stack_access_within_bounds() and drop the calls in the stack read and write paths, which also fixes the frame check_stack_read_fixed_off() checked; fold v1 patch 2 into patch 1. (Alexei)
* Scope the test comment to the output buffer tests and describe the remaining tests individually. (BPF CI)

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: Check fastcall stack contract once for all stack accesseskernel/bpf/verifier.c+9 -40 repliesApplied
2/2selftests/bpf: Test fastcall rewrite with indirect stack accessestools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c+169 -00 repliesApplied

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/2] Fix fastcall rewrite with indirect stack accesses

When a bpf_fastcall call is inlined, the verifier removes the spill/fill pairs around it and shrinks the stack frame to exclude their slots. Two kinds of stack access skip the check that must disable this rewrite, so the program can then access kernel stack outside its frame: stack buffers passed to helpers and kfuncs, which BPF CI reported after commit 5da4a9f26fca ("bpf: Preserve stack initialization for generic output buffers"), and a callee's load from its caller's stack, which checked the callee's frame instead of the caller's.

Patch 1 moves the check into check_stack_access_within_bounds(), which every stack access goes through with the frame that owns the slots, and drops the calls from the stack read and write paths. Patch 2 adds tests.

Changelog:
----------
v1 -> v2
v1: https://lore.kernel.org/bpf/[email protected]

* Check the contract once in check_stack_access_within_bounds() and drop the calls in the stack read and write paths, which also fixes the frame check_stack_read_fixed_off() checked; fold v1 patch 2 into patch 1. (Alexei)
* Scope the test comment to the output buffer tests and describe the remaining tests individually. (BPF CI)

Kumar Kartikeya Dwivedi (2):
bpf: Check fastcall stack contract once for all stack accesses selftests/bpf: Test fastcall rewrite with indirect stack accesses

 kernel/bpf/verifier.c                         |  13 +-
 .../bpf/progs/verifier_bpf_fastcall.c         | 169 ++++++++++++++++++
 2 files changed, 178 insertions(+), 4 deletions(-)

base-commit: 24629aac43d2884109ae47a993fd51b504e2b09b

Signature · 1 line
2.53.0