From: Eduard Zingerman <eddyz87@gmail.com>
To: Tianci Cao <ziye@zju.edu.cn>
Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org,
daniel@iogearbox.net, haoluo@google.com,
john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org,
martin.lau@linux.dev, sdf@fomichev.me, shenghaoyuan0928@163.com,
song@kernel.org, tangyazhou518@outlook.com,
yonghong.song@linux.dev
Subject: Re: [PATCH bpf-next 1/2] bpf: Add bitwise tracking for BPF_END
Date: Tue, 03 Feb 2026 14:36:45 -0800 [thread overview]
Message-ID: <390ea771d41c8cf53de64025036bf1435c5dac5e.camel@gmail.com> (raw)
In-Reply-To: <20260203101736.4975-1-ziye@zju.edu.cn>
On Tue, 2026-02-03 at 18:17 +0800, Tianci Cao wrote:
> Hi Eduard,
>
> Thank you for the review and the ack.
>
> On 2/3/26 4:03 AM, Eduard Zingerman wrote:
> > > - /* ALU32 ops are zero extended into 64bit register */
> > > - if (alu32)
> > > + /*
> > > + * ALU32 ops are zero extended into 64bit register.
> > > + * BPF_END is already handled inside the helper (truncation),
> > > + * so skip zext here.
> > > + */
> > > + if (alu32 && opcode != BPF_END)
> >
> > Nit: zext after scalar_byte_swap() won't change anything, right?
> > If so, I'd just avoid the special case and skip 'opcode != BPF_END'.
>
> Actually, for BPF_END, the alu32 flag may mislead regarding the actual data width being processed.
> The operand size for BPF_END is determined by insn->imm , not by the opcode class.
> So if we simply rely on if (alu32) to perform zext_32_to_64(), we might encounter an unsound state
> in the following cases:
>
> * le64 : opcode=0xd4 (BPF_END | BPF_ALU | BPF_TO_LE)
> * be64 : opcode=0xdc (BPF_END | BPF_ALU | BPF_TO_BE)
>
> These instructions belong to BPF_ALU, so alu32 is true. However, it is a 64-bit operation. If we
> perform zext_32_to_64() after scalar_byte_swap(), the verifier would incorrectly zero-out the
> upper 32 bits of a 64-bit result, which is incorrect and unsound.
>
> Since scalar_byte_swap() already handles truncation and zero-extension internally based on the
> precise ' insn->imm ', it's safer to skip the generic alu32 zext for BPF_END altogether.
>
> If you have any more questions, please feel free to reach out.
Hm, makes sense, thank you for explaining.
next prev parent reply other threads:[~2026-02-03 22:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-02 13:35 [PATCH bpf-next 0/2] bpf: Add bitwise tracking for BPF_END Tianci Cao
2026-02-02 13:35 ` [PATCH bpf-next 1/2] " Tianci Cao
2026-02-02 20:03 ` Eduard Zingerman
2026-02-03 10:17 ` Tianci Cao
2026-02-03 22:36 ` Eduard Zingerman [this message]
2026-02-02 13:35 ` [PATCH bpf-next 2/2] selftests/bpf: Add tests for BPF_END bitwise tracking Tianci Cao
2026-02-02 20:23 ` Eduard Zingerman
2026-02-03 10:20 ` Tianci Cao
2026-02-03 23:16 ` Eduard Zingerman
2026-02-04 6:08 ` Tianci Cao
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=390ea771d41c8cf53de64025036bf1435c5dac5e.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=shenghaoyuan0928@163.com \
--cc=song@kernel.org \
--cc=tangyazhou518@outlook.com \
--cc=yonghong.song@linux.dev \
--cc=ziye@zju.edu.cn \
/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