From: Eduard Zingerman <eddyz87@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org
Cc: daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com,
yonghong.song@linux.dev, eddyz87@gmail.com, memxor@gmail.com,
iii@linux.ibm.com, gimm78064@gmail.com, info@starlabs.sg
Subject: [PATCH bpf-next v4 0/7] bpf: infer zext_dst based on static register liveness analysis
Date: Fri, 7 Aug 2026 13:59:29 -0700 [thread overview]
Message-ID: <20260807-static-zext-v4-0-b6c270013c77@gmail.com> (raw)
Min-gyu Kim reported a bug in 32-bit operations zero extension
handling [1]. The same issue was independently identified by
STAR Labs SG. The bug was introduced by the commit [2].
The tl;dr of the bug is that the verifier does not carry zero
extension marks across pruning points. The detailed mechanism is
described in patch #3.
Fix this by reworking zero extension logic to avoid main-path based
subreg_def tracking, and instead extend the live registers analysis to
track upper register halves' liveness.
As noted in the commit message for patch #3:
There is one notable drop in precision: whenever a BPF subprogram is
called, all 64 bits of parameter registers are presumed to be used.
The assumption is that such a drop in precision would not inflict
noticeable performance penalty.
Ilya, could you please help with testing this conjecture?
Min-gyu, could you please test the proposed fix against your
reproducer?
Side note:
Patch #1 is a small refactoring for disasm.c, as patch #3 adds a new
location where bpf_verbose_insn() is called and there as well I have
to wrangle with the newline added by the disasm code.
[1] https://lore.kernel.org/bpf/CAGKGUv=sOuqQtA1Ub-5JXfA4FPosJFYKAQE4B79cK+P1erxqtg@mail.gmail.com/
[2] commit 107e16979905 ("bpf: disable and remove registers chain based liveness")
Changelog:
v1 -> v2:
- fixed BPF_JMP32 handling, these no longer for zero extension (sashiko)
- removed dead code in print_insn_for_graph() (bot+bpf-ci)
- reworked bpf_is_reg64() to drop dead code (sashiko, bot+bpf-ci)
v2 -> v3:
- fix for proper s390x calling convention all call parameters are now
zero extended if necessary (sashiko)
- fix for PTR_TO_ARENA alu operations to set zext_dst when needs_zext
is set, in order for such operations to be zero extended (sashiko)
- updated bpf_is_reg64() to handle BPR_PROBE_MEM{,32} loads in order
to avoid a false positive from sashiko.
v3 -> v4:
- fix to properly handle address space cast instructions for
arena maps with BPF_F_NO_USER_CONV (sashiko):
- extracted is_addr_space_cast32() utility function,
for use in bpf_do_misc_fixups() and bpf_is_reg64();
- made bpf_is_reg64() aware of such address space casts.
- added a note about report from STAR Labs SG.
v1: https://lore.kernel.org/bpf/20260731-static-zext-v1-0-98a4dc73e94b@gmail.com/T/
v2: https://lore.kernel.org/bpf/20260731-static-zext-v2-0-da4aa161e8c5@gmail.com/T/
v3: https://lore.kernel.org/bpf/20260802-static-zext-v3-0-3456b2604574@gmail.com/T/
---
Eduard Zingerman (7):
bpf: do not print a newline after disassembly in bpf_verbose_insn()
bpf: extract is_addr_space_cast32() utility function
bpf: move bpf_is_reg64() to fixups.c
bpf: track upper 32-bit register halves' liveness in compute_live_registers()
bpf: infer zext_dst based on static register liveness analysis
bpf: simplify the bpf_is_reg64()
selftests/bpf: verify zext_dst annotations for various instructions
include/linux/bpf_verifier.h | 7 +-
kernel/bpf/backtrack.c | 1 +
kernel/bpf/disasm.c | 68 ++--
kernel/bpf/fixups.c | 100 ++++--
kernel/bpf/liveness.c | 109 ++++--
kernel/bpf/verifier.c | 204 +----------
tools/bpf/bpftool/xlated_dumper.c | 19 +-
tools/testing/selftests/bpf/disasm_helpers.c | 3 +-
tools/testing/selftests/bpf/prog_tests/verifier.c | 2 +
tools/testing/selftests/bpf/progs/verifier_zext.c | 392 ++++++++++++++++++++++
10 files changed, 596 insertions(+), 309 deletions(-)
---
base-commit: 41c129fdc28b6414d259da72679567c5e72a55dd
change-id: 20260731-static-zext-938cd128273c
next reply other threads:[~2026-08-07 20:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 20:59 Eduard Zingerman [this message]
2026-08-07 20:59 ` [PATCH bpf-next v4 1/7] bpf: do not print a newline after disassembly in bpf_verbose_insn() Eduard Zingerman
2026-08-07 20:59 ` [PATCH bpf-next v4 2/7] bpf: extract is_addr_space_cast32() utility function Eduard Zingerman
2026-08-07 20:59 ` [PATCH bpf-next v4 3/7] bpf: move bpf_is_reg64() to fixups.c Eduard Zingerman
2026-08-07 21:52 ` bot+bpf-ci
2026-08-07 20:59 ` [PATCH bpf-next v4 4/7] bpf: track upper 32-bit register halves' liveness in compute_live_registers() Eduard Zingerman
2026-08-07 20:59 ` [PATCH bpf-next v4 5/7] bpf: infer zext_dst based on static register liveness analysis Eduard Zingerman
2026-08-07 20:59 ` [PATCH bpf-next v4 6/7] bpf: simplify the bpf_is_reg64() Eduard Zingerman
2026-08-07 20:59 ` [PATCH bpf-next v4 7/7] selftests/bpf: verify zext_dst annotations for various instructions Eduard Zingerman
2026-08-08 10:00 ` [PATCH bpf-next v4 0/7] bpf: infer zext_dst based on static register liveness analysis 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=20260807-static-zext-v4-0-b6c270013c77@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gimm78064@gmail.com \
--cc=iii@linux.ibm.com \
--cc=info@starlabs.sg \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=yonghong.song@linux.dev \
/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