BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tiezhu Yang" <yangtiezhu@loongson.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v1 1/4] LoongArch: BPF: Optimize BPF_CALL control flow
Date: Mon, 23 Nov 2026 04:42:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-228668@kernel.org> (raw)
In-Reply-To: <20261123043907.20225-2-yangtiezhu@loongson.cn>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] LoongArch: BPF: unshifted and unaligned offset for
  stptrw/stptrd in build_insn() [1]
--

commit 0dc0cb0459b2a4e50da067a04e5643e5c6bf634c
Author: Tiezhu Yang <yangtiezhu@loongson.cn>

LoongArch: BPF: Optimize BPF_CALL control flow

This commit separates BPF_PSEUDO_CALL handling in build_insn() so that it
emits the jump and breaks early, avoiding a redundant check at the end of
the BPF_CALL case.

> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> index 15af1abb5cb69..b26b75f62fb31 100644
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c
> @@ -1219,6 +1219,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
>  		if (insn->src_reg == BPF_PSEUDO_CALL) {
>  			tcc_ptr_off = BPF_TAIL_CALL_CNT_PTR_STACK_OFF(ctx->stack_size);
>  			emit_insn(ctx, ldd, REG_TCC, LOONGARCH_GPR_SP, tcc_ptr_off);
> +			move_addr(ctx, t1, func_addr);
> +			emit_insn(ctx, jirl, LOONGARCH_GPR_RA, t1, 0);
> +			break;
>  		}
>  
>  		if (insn->src_reg == BPF_PSEUDO_KFUNC_CALL) {
> @@ -1245,8 +1248,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
>  		 * convention with the argument and return value in BPF_REG_AX,
>  		 * so skip moving the C return value into BPF_REG_0.
>  		 */
> -		if (insn->src_reg != BPF_PSEUDO_CALL &&
> -		    func_addr != (u64)arch_bpf_timed_may_goto)
> +		if (func_addr != (u64)arch_bpf_timed_may_goto)
>  			move_reg(ctx, regmap[BPF_REG_0], LOONGARCH_GPR_A0);
>  
>  		break;

[Severity: High]
This problem wasn't introduced by this patch, but can emit_insn() for
stptrw and stptrd in build_insn() corrupt memory outside the target buffer
[1]?

Later in build_insn(), the BPF_ST and BPF_STX cases emit stptrw and stptrd
when off is outside the 12-bit signed immediate range [-2048, 2047] but
within the 14-bit signed range [-8192, 8191]:

arch/loongarch/net/bpf_jit.c:build_insn() {
    ...
		case BPF_W:
			if (is_signed_imm12(off)) {
				emit_insn(ctx, stw, src, dst, off);
			} else if (is_signed_imm14(off)) {
				emit_insn(ctx, stptrw, src, dst, off);
			} else {
    ...
}

In LoongArch, stptr.w and stptr.d require a 4-byte-aligned offset encoded
as a word-scaled 14-bit signed immediate (si14 << 2), whereas
emit_stptrw() and emit_stptrd() write their immediate argument directly
into insn->reg2i14_format.immediate without shifting.  Passing the byte
offset off directly causes the store to write to dst + (off << 2) instead
of dst + off, corrupting kernel memory up to 24 KB beyond a verifier-
checked map value or arena buffer.

[1] https://sashiko.dev/#/bug/linux-9c06f20c-c232-47f5-ae96-11fb3889acdc

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123043907.20225-1-yangtiezhu@loongson.cn?part=1

  reply	other threads:[~2026-11-23  4:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  4:39 [PATCH v1 0/4] LoongArch: BPF: Support instructions array, indirect jumps and calls Tiezhu Yang
2026-11-23  4:39 ` [PATCH v1 1/4] LoongArch: BPF: Optimize BPF_CALL control flow Tiezhu Yang
2026-11-23  4:42   ` sashiko-bot [this message]
2026-11-23  4:39 ` [PATCH v1 2/4] LoongArch: BPF: Add support for instructions array Tiezhu Yang
2026-11-23  4:39 ` [PATCH v1 3/4] LoongArch: BPF: Add support for indirect jumps Tiezhu Yang
2026-11-23  4:39 ` [PATCH v1 4/4] LoongArch: BPF: Add support for indirect calls Tiezhu Yang

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=sashiko-outbox-228668@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yangtiezhu@loongson.cn \
    /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