All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 07/11] bpf: Allow arena pointers in a by-value kfunc return
Date: Fri, 28 Aug 2026 11:10:10 -0700	[thread overview]
Message-ID: <47573fc4-be5c-44bf-b307-b1528eae196c@linux.dev> (raw)
In-Reply-To: <20260827065558.C91891F000E9@smtp.kernel.org>



On 8/26/26 11:55 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Kfuncs returning structs by value can leak uninitialized kernel stack memory via struct padding.
> --
>
> commit a43266e4517bac02a4bb85149655178eefda72ad
> Author: Yonghong Song <yonghong.song@linux.dev>
>
> bpf: Allow arena pointers in a by-value kfunc return
>
> This commit allows by-value struct returns from kfuncs to contain arena
> pointers, in addition to scalars. An arena pointer has no provenance to lose
> and can be cast by the program, so returning it as a scalar is safe.
>
>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>> index 967ad010b3222..9a36808136c9a 100644
>> --- a/kernel/bpf/verifier.c
>> +++ b/kernel/bpf/verifier.c
>> @@ -14119,13 +14119,17 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
>>   
>>   		/*
>>   		 * The returned struct comes back as raw register bits modeled
>> -		 * as an unknown scalar, so it must contain only scalars:
>> -		 * otherwise a pointer field would be laundered into a scalar
>> -		 * and escape provenance and reference tracking.
>> +		 * as an unknown scalar, so a pointer member would be laundered
>> +		 * into a scalar and escape provenance and reference tracking.
>> +		 * Only scalars and arena pointers are allowed: an arena pointer
>> +		 * has no provenance to lose, since a program may already derive
>> +		 * one from any scalar with addr_space_cast(), which confines the
>> +		 * result to the arena.
>>   		 */
>> -		if (!btf_struct_member_walk(env, desc_btf, t, BTF_MEMBER_SCALAR, 0, &path)) {
>> +		if (!btf_struct_member_walk(env, desc_btf, t,
>> +					    BTF_MEMBER_SCALAR | BTF_MEMBER_ARENA_PTR, 0, &path)) {
> [Severity: High]
> This is a pre-existing issue, but does returning structs by value from kfuncs
> leak uninitialized kernel stack memory via struct padding?
>
> When a BPF program calls a kfunc that returns a struct by value (up to 16
> bytes) containing padding bytes, the C compiler leaves the padding bytes
> uninitialized in the return registers (e.g., RAX/RDX on x86-64).
>
> The verifier's check_kfunc_call() processes this using btf_struct_member_walk()
> which ignores padding. The code then calls mark_kfunc_ret_regs() which
> unconditionally marks the entire return registers as fully initialized
> scalar values:
>
> kernel/bpf/verifier.c:mark_kfunc_ret_regs() {
>      ...
>      mark_reg_unknown(env, regs, ret_regs[0]);
>      if (nregs == 1)
>          return nregs;
>
>      for (i = 1; i < nregs; i++) {
>          mark_reg_unknown(env, regs, ret_regs[i]);
>      }
>      ...
> }
>
> Can a BPF program then read these registers and exfiltrate the uninitialized
> padding bytes (e.g., via BPF maps)?

We should be okay. Based on type, the return register will do proper narrowing
e.g., zeroing out the upper 32bit value, etc.

>


  reply	other threads:[~2026-08-28 18:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27  6:11 [PATCH bpf-next v3 00/11] bpf: Allow arena pointers in by-value returns Yonghong Song
2026-08-27  6:11 ` [PATCH bpf-next v3 01/11] bpf: Record each half of a paired return value in verifier diagnostics Yonghong Song
2026-08-27  6:11 ` [PATCH bpf-next v3 02/11] bpf: Drop the recursion depth argument of btf_type_is_scalar_struct() Yonghong Song
2026-08-27  7:04   ` bot+bpf-ci
2026-08-28 17:39     ` Yonghong Song
2026-08-27  6:11 ` [PATCH bpf-next v3 03/11] bpf: Add btf_type_is_arena_ptr() Yonghong Song
2026-08-27  6:11 ` [PATCH bpf-next v3 04/11] bpf: Let the by-value struct walk take the kinds of member it accepts Yonghong Song
2026-08-27  6:11 ` [PATCH bpf-next v3 05/11] bpf: Report which member makes a kfunc return type unsupported Yonghong Song
2026-08-27  7:04   ` bot+bpf-ci
2026-08-28 17:45     ` Yonghong Song
2026-08-27  6:11 ` [PATCH bpf-next v3 06/11] bpf: Allow a global function to return arena pointers by value Yonghong Song
2026-08-27  6:33   ` sashiko-bot
2026-08-28 18:00     ` Yonghong Song
2026-08-27  6:11 ` [PATCH bpf-next v3 07/11] bpf: Allow arena pointers in a by-value kfunc return Yonghong Song
2026-08-27  6:55   ` sashiko-bot
2026-08-28 18:10     ` Yonghong Song [this message]
2026-08-27  6:11 ` [PATCH bpf-next v3 08/11] selftests/bpf: Check the member named for an unsupported kfunc return type Yonghong Song
2026-08-27  7:04   ` bot+bpf-ci
2026-08-28 18:20     ` Yonghong Song
2026-08-27  6:12 ` [PATCH bpf-next v3 09/11] selftests/bpf: Test global functions returning arena pointers by value Yonghong Song
2026-08-27  7:04   ` bot+bpf-ci
2026-08-28 18:26     ` Yonghong Song
2026-08-27  6:12 ` [PATCH bpf-next v3 10/11] selftests/bpf: Test kfuncs " Yonghong Song
2026-08-27  7:17   ` bot+bpf-ci
2026-08-28 18:28     ` Yonghong Song
2026-08-27  6:12 ` [PATCH bpf-next v3 11/11] docs/bpf: Document arena pointers in a by-value return Yonghong Song

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=47573fc4-be5c-44bf-b307-b1528eae196c@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.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.