Skip to content

Compare stack frames in exact register states

Kumar Kartikeya Dwivedi bpf 4 versions – Applied

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

  1. v4 Latest2 patches 0 repliesApplied 2/2
  2. v32 patches 1 replySuperseded
  3. v22 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches2 repliesSuperseded

Changes in v4 from the cover letter

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

* Return NULL from bpf_func() for non-stack registers, since frameno now aliases other pointer metadata and some callers look up the frame before checking the register type. (Sashiko)

Patches in v4 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: Compare stack frames in regs_exact()include/linux/bpf_verifier.h kernel/bpf/states.c+17 -130 repliesApplied
2/2selftests/bpf: Cover frame changes in bounded loopstools/testing/selftests/bpf/progs/verifier_loops1.c+36 -00 repliesApplied

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchEduard Zingerman
1/2A-b
2/2T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH bpf v4 0/2] Compare stack frames in exact register states

regs_exact() compares register values and their ID relationships, but it does not compare frameno. regsafe() checks frameno for ordinary PTR_TO_STACK comparisons, while its EXACT path returns through regs_exact() before reaching that check. Infinite-loop detection can therefore mistake pointers to the same offset in different stack frames for the same pointer and reject a finite loop.

Move frameno into bpf_reg_state's type-specific metadata union so the existing regs_exact() prefix comparison covers it. This avoids a separate PTR_TO_STACK case and keeps the structure at 80 bytes. Adjust the states_maybe_looping() comparison boundary for the new layout. Since frameno now aliases other pointer metadata, bpf_func() returns NULL for registers that are not stack pointers; the callers that look up the frame before checking the register type dereference it only afterwards.

The selftest keeps a stack pointer live in a register across a loop whose only change at the header is the pointer's frame number. On the unfixed tree, the program is rejected with "infinite loop detected". With the fix, it loads and returns the expected value.

Changelog:
----------
v3 -> v4
v3: https://lore.kernel.org/bpf/[email protected]

* Return NULL from bpf_func() for non-stack registers, since frameno now aliases other pointer metadata and some callers look up the frame before checking the register type. (Sashiko)

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

* Rebase on bpf/master.
* Drop the redundant spilled-pointer test, since existing tests already cover the stacksafe() -> regsafe() path. (Eduard)
* Place asm labels on their own line in the selftest. (Eduard)
* Collect Acked-by and Tested-by tags.

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

* Rebase on bpf/master.
* Move frameno into the type-specific metadata union so regs_exact()'s existing prefix comparison covers it without growing bpf_reg_state.

Kumar Kartikeya Dwivedi (2):
bpf: Compare stack frames in regs_exact() selftests/bpf: Cover frame changes in bounded loops

 include/linux/bpf_verifier.h                  | 23 +++++++-----
 kernel/bpf/states.c                           |  7 ++--
 .../selftests/bpf/progs/verifier_loops1.c     | 36 +++++++++++++++++++
 3 files changed, 53 insertions(+), 13 deletions(-)

base-commit: b4e875d397da451fb4e9c573ff4b86db53caba05

Signature · 1 line
2.53.0