From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Weiming Shi" <bestswngs@gmail.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"John Fastabend" <john.fastabend@gmail.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>, "Shuah Khan" <shuah@kernel.org>
Cc: <bpf@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <co+eada64ce90ecebce@bugs.sh>,
"Xiang Mei" <xmei5@asu.edu>
Subject: Re: [PATCH bpf v2 1/2] bpf: Validate stack arg reads against caller state
Date: Sun, 25 Oct 2026 01:12:09 +0000 [thread overview]
Message-ID: <DMDIPYF3NTY0.3SN2PAZ1PG9J2@gmail.com> (raw)
In-Reply-To: <20261021080100.2663618-1-bestswngs@gmail.com>
On Wed Oct 21, 2026 at 8:00 AM UTC, Weiming Shi wrote:
> check_stack_arg_read() bounds a stack argument index with the callee's
> BTF-derived argument count, then uses the index in the caller's
> stack_arg_regs[] array. The array's actual logical length is recorded in
> caller->out_stack_arg_cnt, so the bound and indexed object can diverge.
>
> A crafted BPF_PROG_LOAD can use an argument mismatch to mark a static
> subprogram's BTF information unreliable. Later calls return from
> btf_check_subprog_call() before check_outgoing_stack_args(), while
> check_func_call() continues the static call on -EINVAL. The callee can
> then read a slot that the caller never allocated or initialized. The
> earlier commit 4286f5deee14 ("bpf: Validate outgoing stack args when
> btf_prepare_func_args fails") closed this hole for the first call, but
> not for later calls after the subprogram has been marked unreliable.
>
> Callbacks have a related problem. The verifier can make incoming stack
> arguments readable from outgoing slots at the helper call site. However,
> helpers and kfuncs invoke callbacks through an ABI that passes at most five
> arguments, so the runtime callback receives no stack arguments. Async
> callback verification can also reach check_stack_arg_read() without a
> caller frame.
>
> On x86-64, KASAN reports the direct-call out-of-bounds copy as:
>
> BUG: KASAN: slab-out-of-bounds in check_load_mem+0xb51/0xc60
> Read of size 80 at addr ffff8881009af550 by task poc/131
> Call Trace:
> check_stack_arg_read at kernel/bpf/verifier.c:4234
> (inlined by) check_load_mem at kernel/bpf/verifier.c:6645
> do_check_common at kernel/bpf/verifier.c:19568
> bpf_check at kernel/bpf/verifier.c:21318
> bpf_prog_load at kernel/bpf/syscall.c:3134
>
> Reject callback subprograms with incoming stack arguments before their
> state is pushed. For direct calls, retrieve the slot with
> bpf_get_spilled_stack_arg(), which validates the index against the caller's
> out_stack_arg_cnt and rejects uninitialized slots before copying the
> register state.
>
> Fixes: 0f6bd5e7a804 ("bpf: Support stack arguments for bpf functions")
> Reported-by: <co+eada64ce90ecebce@bugs.sh>
> Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
> Assisted-by: LLM
> Signed-off-by: Weiming Shi <bestswngs@gmail.com>
looks good, but doesn't apply.
please rebase on top of bpf tree.
pw-bot: cr
prev parent reply other threads:[~2026-10-25 1:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 8:00 [PATCH bpf v2 1/2] bpf: Validate stack arg reads against caller state Weiming Shi
2026-10-21 8:01 ` [PATCH bpf v2 2/2] selftests/bpf: Test missing and callback stack arguments Weiming Shi
2026-10-25 1:12 ` Alexei Starovoitov [this message]
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=DMDIPYF3NTY0.3SN2PAZ1PG9J2@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bestswngs@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=co+eada64ce90ecebce@bugs.sh \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--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 \
--cc=song@kernel.org \
--cc=xmei5@asu.edu \
--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 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.