From: Eduard Zingerman <eddyz87@gmail.com>
To: Nuoqi Gui <gnq25@mails.tsinghua.edu.cn>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: John Fastabend <john.fastabend@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Shuah Khan <shuah@kernel.org>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf 1/2] bpf: Keep fastcall spills for helper stack reads
Date: Thu, 25 Jun 2026 11:32:32 -0700 [thread overview]
Message-ID: <860e915356c571791712be02c636405aadfc6467.camel@gmail.com> (raw)
In-Reply-To: <20260624-f01-12-fastcall-helper-stack-read-v1-1-e0a86085ef77@mails.tsinghua.edu.cn>
On Wed, 2026-06-24 at 16:39 +0800, Nuoqi Gui wrote:
> The fastcall spill/fill rewrite is only sound while the stack slots used by
> the pattern are not accessed outside the pattern. Direct stack loads and
> stores already call check_fastcall_stack_contract() to enforce this.
>
> Helper and kfunc memory-argument checks can validate PTR_TO_STACK reads
> through check_stack_range_initialized() without applying the same contract.
> When such a read overlaps a fastcall spill slot,
> bpf_remove_fastcall_spills_fills() can still remove the spill/fill pair.
> It can then shrink the subprogram stack depth even though a helper or kfunc
> reads that stack address.
>
> Apply check_fastcall_stack_contract() from check_stack_range_initialized()
> after the concrete stack range is known. Zero-sized accesses do not read or
> write memory, so leave the fastcall optimization unchanged for those.
>
> Fixes: 5b5f51bff1b66 ("bpf: no_caller_saved_registers attribute for helper calls")
> Signed-off-by: Nuoqi Gui <gnq25@mails.tsinghua.edu.cn>
> ---
> kernel/bpf/verifier.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index ff9b1f68ceca4..d77332eeab359 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -6873,6 +6873,10 @@ static int check_stack_range_initialized(
> max_off = reg->smax_value + off;
> }
>
> + if (access_size)
> + check_fastcall_stack_contract(env, state, env->insn_idx,
> + min_off);
> +
Thank you for finding this bug.
I think that placing the check_fastcall_stack_contract() call here
makes the same call unnecessary in the check_stack_read_var_off(),
as it calls to check_stack_range_initialized() with zero_size_allowed==false.
> if (meta && meta->raw_mode) {
> /* Ensure we won't be overwriting dynptrs when simulating byte
> * by byte access in check_helper_call using meta.access_size.
next prev parent reply other threads:[~2026-06-25 18:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 8:39 [PATCH bpf 0/2] bpf: Keep fastcall stack slots " Nuoqi Gui
2026-06-24 8:39 ` [PATCH bpf 1/2] bpf: Keep fastcall spills " Nuoqi Gui
2026-06-25 18:32 ` Eduard Zingerman [this message]
2026-06-28 13:46 ` Nuoqi Gui
2026-06-24 8:39 ` [PATCH bpf 2/2] selftests/bpf: Cover fastcall " Nuoqi Gui
2026-06-24 10:01 ` bot+bpf-ci
2026-06-25 18:35 ` Eduard Zingerman
2026-06-28 13:47 ` Nuoqi Gui
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=860e915356c571791712be02c636405aadfc6467.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=gnq25@mails.tsinghua.edu.cn \
--cc=john.fastabend@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®