From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
Nicholas Carlini <npc@anthropic.com>,
kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf v4 0/2] Compare stack frames in exact register states
Date: Sat, 19 Sep 2026 03:42:09 +0200 [thread overview]
Message-ID: <20260919014213.1840880-1-memxor@gmail.com> (raw)
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/20260919004327.1403382-1-memxor@gmail.com
* 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/20260918011313.3053497-1-memxor@gmail.com
* 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/20260914161340.3419141-1-memxor@gmail.com
* 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
--
2.53.0
next reply other threads:[~2026-09-19 1:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 1:42 Kumar Kartikeya Dwivedi [this message]
2026-09-19 1:42 ` [PATCH bpf v4 1/2] bpf: Compare stack frames in regs_exact() Kumar Kartikeya Dwivedi
2026-09-19 2:55 ` bot+bpf-ci
2026-09-19 1:42 ` [PATCH bpf v4 2/2] selftests/bpf: Cover frame changes in bounded loops Kumar Kartikeya Dwivedi
2026-09-19 5:30 ` [PATCH bpf v4 0/2] Compare stack frames in exact register states patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260919014213.1840880-1-memxor@gmail.com \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=npc@anthropic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox