From: Yonghong Song <yonghong.song@linux.dev>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v3 1/2] bpf: Do not include stack ptr register in precision backtracking bookkeeping
Date: Wed, 21 May 2025 14:35:48 -0700 [thread overview]
Message-ID: <6885590a-266e-4230-9eeb-4fbfd7e2f3f4@linux.dev> (raw)
In-Reply-To: <m2ikltd6kz.fsf@gmail.com>
On 5/21/25 1:58 PM, Eduard Zingerman wrote:
> Yonghong Song <yonghong.song@linux.dev> writes:
>
> [...]
>
>>>> @@ -16397,6 +16423,29 @@ static void sync_linked_regs(struct
>>>> bpf_verifier_state *vstate, struct bpf_reg_s
>>>> }
>>>> }
>>>> +static int push_cond_jmp_history(struct bpf_verifier_env *env,
>>>> struct bpf_verifier_state *state,
>>>> + struct bpf_reg_state *dst_reg, struct
>>>> bpf_reg_state *src_reg,
>>>> + u64 linked_regs)
>>>> +{
>>>> + bool dreg_stack_ptr, sreg_stack_ptr;
>>>> + int insn_flags;
>>>> +
>>>> + if (!src_reg) {
>>>> + if (linked_regs)
>>>> + return push_insn_history(env, state, 0, linked_regs);
>>>> + return 0;
>>>> + }
>>> Nit: this 'if' is not needed, src_reg is always set (it might point
>>> to a fake register,
>>> but in that case it is a scalar without id).
>>>
>> Here, there is a bug here. Thanks for pointing this out. I need to check
>> BPF_SRC(insn->code) != BPF_X instead of "!src_reg". Basically passing one
>> more parameter (e.g., faked_sreg) to decide whether src_reg is faked or not.
> I don't think any checks are needed.
> Fake register is always scalar and it cannot be collected as a linked register.
> So it won't end up in the instruction history flags.
Let us say that we remove the code
+ if (!src_reg) {
+ if (linked_regs)
+ return push_insn_history(env, state, 0, linked_regs);
+ return 0;
+ }
The code should still work. But we might end up with more unnecessary
jump history entries. For example,
dreg->type == PTR_TO_STACK, sreg is faked (i.e., BPF_SRC(insn->code) == BPF_K)
and linked_regs = 0
In this particular, we will still generate a jump table entry which
is not used in backtrack_insn().
>
> [...]
next prev parent reply other threads:[~2025-05-21 21:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-21 17:04 [PATCH bpf-next v3 1/2] bpf: Do not include stack ptr register in precision backtracking bookkeeping Yonghong Song
2025-05-21 17:04 ` [PATCH bpf-next v3 2/2] selftests/bpf: Add tests with stack ptr register in conditional jmp Yonghong Song
2025-05-21 19:02 ` Eduard Zingerman
2025-05-21 20:57 ` Yonghong Song
2025-05-21 21:03 ` Eduard Zingerman
2025-05-21 18:55 ` [PATCH bpf-next v3 1/2] bpf: Do not include stack ptr register in precision backtracking bookkeeping Eduard Zingerman
2025-05-21 20:34 ` Yonghong Song
2025-05-21 20:58 ` Eduard Zingerman
2025-05-21 21:35 ` Yonghong Song [this message]
2025-05-21 21:59 ` Eduard Zingerman
2025-05-21 22:04 ` Eduard Zingerman
2025-05-21 22:38 ` Andrii Nakryiko
2025-05-21 22:49 ` Eduard Zingerman
2025-05-22 2:53 ` Yonghong Song
2025-05-22 20:05 ` Andrii Nakryiko
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=6885590a-266e-4230-9eeb-4fbfd7e2f3f4@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.