BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yonghong Song" <yonghong.song@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 03/13] bpf: Wire up JIT support for 16-byte kfunc returns
Date: Sat, 08 Aug 2026 19:39:53 +0000	[thread overview]
Message-ID: <20260808193954.645B91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260808190337.1898362-1-yonghong.song@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Uninitialized kernel register state can be leaked to BPF programs when a kfunc returns an aggregate (struct/union) between 9 and 15 bytes in size.
--

--- Patch [3]: [PATCH bpf-next v3 03/13] bpf: Wire up JIT support for 16-byte kfunc returns ---
commit f2df1b40e2f3eb74688d20cd37742fe85c667da9
Author: Yonghong Song <yonghong.song@linux.dev>
Subject: bpf: Wire up JIT support for 16-byte kfunc returns

This patch adds JIT support for returning structures up to 16 bytes from
kfuncs in the BPF R0:R2 register pair. It implements the necessary RDX to RSI
move for x86-64 and adds opt-in capabilities for the x86, arm64, and riscv
architectures.

> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index 8dddb5d7af21b..01c34114c8502 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
[ ... ]
> @@ -2647,6 +2647,22 @@ st:			insn_off = insn->off;
>  				return -EINVAL;
>  			if (priv_frame_ptr)
>  				pop_r9(&prog);
> +			if (src_reg == BPF_PSEUDO_KFUNC_CALL) {
> +				const struct btf_func_model *fm;
> +
> +				/*
> +				 * A kfunc returning a >8 byte aggregate hands the
> +				 * second half back in RDX (the native ABI's second
> +				 * return reg), but BPF expects it in R0:R2. BPF R0
> +				 * is RAX (no move needed), while BPF R2 is RSI, so
> +				 * copy RDX into RSI.
> +				 */
> +				fm = bpf_jit_find_kfunc_model(bpf_prog, insn);
> +				if (!fm)
> +					return -EFAULT;
> +				if (fm->ret_size > 8)
> +					emit_mov_reg(&prog, true, BPF_REG_2, BPF_REG_3);

[Severity: High]
In do_jit(), when a kfunc returns an aggregate between 9 and 15 bytes in size,
could this 64-bit move leak uninitialized kernel register state?

According to the native ABI, the upper bytes of the second return register
(RDX/BPF_REG_3) might contain padding and be uninitialized.

Since the move is a full 64-bit copy to BPF_REG_2, and the BPF verifier allows
64-bit reads of BPF_REG_2 without zero-extending the padded bits, a BPF
program might save the full register to a map and leak the uninitialized bytes
to userspace.

Should the JIT mask out the uninitialized upper bytes of BPF_REG_2 when the
return size is between 9 and 15 bytes?

This same question applies to the arm64 and riscv capabilities enabled in this
patch, where the native registers (x1 and a1) map directly to BPF_REG_2 and
could similarly leave the upper bits unmasked.

> +			}
>  			break;
>  		}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260808190322.1896580-1-yonghong.song@linux.dev?part=3

  reply	other threads:[~2026-08-08 19:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-08 19:03 [PATCH bpf-next v3 00/13] bpf: Support aggregate return values up to 16 bytes Yonghong Song
2026-08-08 19:03 ` [PATCH bpf-next v3 01/13] bpf: Factor check_global_ret_scalar_reg() out of the global return check Yonghong Song
2026-08-08 19:03 ` [PATCH bpf-next v3 02/13] bpf: Add helpers to describe the R0:R2 return register pair Yonghong Song
2026-08-08 19:03 ` [PATCH bpf-next v3 03/13] bpf: Wire up JIT support for 16-byte kfunc returns Yonghong Song
2026-08-08 19:39   ` sashiko-bot [this message]
2026-08-10 16:29     ` Yonghong Song
2026-08-08 19:03 ` [PATCH bpf-next v3 04/13] bpf: Track R2 of register-pair returns in precision backtracking Yonghong Song
2026-08-08 19:29   ` sashiko-bot
2026-08-10 16:30     ` Yonghong Song
2026-08-08 19:03 ` [PATCH bpf-next v3 05/13] bpf: Account R2 of register-pair returns in live register analysis Yonghong Song
2026-08-08 19:03 ` [PATCH bpf-next v3 06/13] bpf: Reject callbacks returning more than 8 bytes Yonghong Song
2026-08-08 19:45   ` sashiko-bot
2026-08-10 16:36     ` Yonghong Song
2026-08-08 19:03 ` [PATCH bpf-next v3 07/13] bpf: Add verifier support for 16-byte returns in R0:R2 Yonghong Song
2026-08-08 19:41   ` sashiko-bot
2026-08-10 16:44     ` Yonghong Song
2026-08-08 19:04 ` [PATCH bpf-next v3 08/13] bpf: Reject register-pair returns when the subprog BTF is unreliable Yonghong Song
2026-08-08 19:04 ` [PATCH bpf-next v3 09/13] bpf: Enable aggregate return types up to 16 bytes Yonghong Song
2026-08-08 19:04 ` [PATCH bpf-next v3 10/13] selftests/bpf: Add C tests for 16-byte returns in R0:R2 Yonghong Song
2026-08-08 19:27   ` sashiko-bot
2026-08-10 16:51     ` Yonghong Song
2026-08-08 19:04 ` [PATCH bpf-next v3 11/13] selftests/bpf: Add inline-asm and subprog tests for R0:R2 returns Yonghong Song
2026-08-08 19:04 ` [PATCH bpf-next v3 12/13] selftests/bpf: Add tests for callbacks returning more than 8 bytes Yonghong Song
2026-08-08 19:04 ` [PATCH bpf-next v3 13/13] Documentation/bpf: Document up to 16-byte kfunc return values in R0:R2 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=20260808193954.645B91F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox