All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jose Fernandez (Anthropic)" <jose.fernandez@linux.dev>
Cc: bpf@vger.kernel.org, ojeda@kernel.org,
	linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 5/8] arm64: cfi: Use CONFIG_ARM64_FUNCTION_PREFIX_NOPS for the type hash offset
Date: Fri, 04 Sep 2026 01:47:48 +0000	[thread overview]
Message-ID: <20260904014748.C04AA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260904-b4-arm64-callops-kcfi-v1-5-ce6687739b0c@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Medium] bpf_prog_fill_jited_linfo() calculates incorrect line info addresses because ctx.offset includes the CFI prefix size.
--

commit 1909b8cf9ec25c69a7f49627fb1a30b3d8e545d4
Author: Jose Fernandez (Anthropic) <jose.fernandez@linux.dev>
arm64: cfi: Use CONFIG_ARM64_FUNCTION_PREFIX_NOPS for the type hash offset

This patch modifies the CFI prefix to use CONFIG_ARM64_FUNCTION_PREFIX_NOPS
instead of hardcoding four bytes. It adjusts cfi_get_offset(),
SYM_TYPED_FUNC_START, and the BPF JIT to account for the dynamic number of
NOPs required by kCFI kernels with CALL_OPS or ThinLTO and BTI.

> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index c18e005a41dbe..7ad14d9847138 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
[ ... ]
> @@ -185,8 +185,12 @@ static inline void emit_bti(u32 insn, struct jit_ctx *ctx)
>  
>  static inline void emit_kcfi(u32 hash, struct jit_ctx *ctx)
>  {
> -	if (IS_ENABLED(CONFIG_CFI))
> -		emit_u32_data(hash, ctx);
> +	if (!IS_ENABLED(CONFIG_CFI))
> +		return;
> +
> +	emit_u32_data(hash, ctx);
> +	for (int i = 0; i < CONFIG_ARM64_FUNCTION_PREFIX_NOPS; i++)
> +		emit(A64_NOP, ctx);
>  }

[Severity: Medium]
This is a pre-existing issue, but does expanding the CFI prefix length
cause bpf_prog_fill_jited_linfo() to calculate incorrect line info addresses
by adding the CFI prefix twice?

When loading any BPF program with line info on an arm64 kernel built with
kCFI, ctx.offset measures from the start of the JIT buffer, which includes
the CFI prefix emitted here.

However, in bpf_int_jit_compile() in arch/arm64/net/bpf_jit_comp.c, the
offsets are passed to bpf_prog_fill_jited_linfo():

arch/arm64/net/bpf_jit_comp.c:bpf_int_jit_compile() {
    ...
    for (i = 0; i <= prog->len; i++)
        ctx.offset[i] *= AARCH64_INSN_SIZE;
    bpf_prog_fill_jited_linfo(prog, ctx.offset + 1);
    ...
}

Since bpf_prog_fill_jited_linfo() adds these offsets to prog->bpf_func,
which is already shifted past the CFI prefix by cfi_get_offset(), the CFI
prefix length ends up being added twice. The bug existed prior to this patch
(off by 4 bytes) but this patch exacerbates it to 16 or 24 bytes depending
on the number of NOPs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260904-b4-arm64-callops-kcfi-v1-0-ce6687739b0c@linux.dev?part=5

  reply	other threads:[~2026-09-04  1:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  1:18 [PATCH RFC 0/8] arm64: ftrace: support CALL_OPS on kernels built with kCFI Jose Fernandez (Anthropic)
2026-09-04  1:18 ` [PATCH RFC 1/8] ftrace: Let ftrace_call_adjust() reject a patch site Jose Fernandez (Anthropic)
2026-09-04  1:33   ` sashiko-bot
2026-09-04 12:47   ` Steven Rostedt
2026-09-06 20:40     ` Jose Fernandez (Anthropic)
2026-09-08 13:52       ` Steven Rostedt
2026-09-04  1:18 ` [PATCH RFC 2/8] scripts/sorttable: Make the arm64 before_func offset configurable Jose Fernandez (Anthropic)
2026-09-04  2:18   ` bot+bpf-ci
2026-09-04  1:18 ` [PATCH RFC 3/8] compiler_types: Let notrace keep the function prefix NOPs Jose Fernandez (Anthropic)
2026-09-04  1:18 ` [PATCH RFC 4/8] arm64: ftrace: Make the CALL_OPS prefix layout configurable Jose Fernandez (Anthropic)
2026-09-04  1:18 ` [PATCH RFC 5/8] arm64: cfi: Use CONFIG_ARM64_FUNCTION_PREFIX_NOPS for the type hash offset Jose Fernandez (Anthropic)
2026-09-04  1:47   ` sashiko-bot [this message]
2026-09-04  1:18 ` [PATCH RFC 6/8] arm64: ftrace: Support CALL_OPS on kernels built with kCFI Jose Fernandez (Anthropic)
2026-09-04 12:18   ` Miguel Ojeda
2026-09-04  1:18 ` [PATCH RFC 7/8] arm64: ftrace: Use five prefix NOPs on ThinLTO kernels with BTI Jose Fernandez (Anthropic)
2026-09-04  1:18 ` [PATCH RFC 8/8] arm64: ftrace: Allow CALL_OPS on kCFI kernels built with Rust Jose Fernandez (Anthropic)
2026-09-06 16:56   ` Miguel Ojeda
2026-09-06 21:24     ` Jose Fernandez (Anthropic)
2026-09-07 19:33       ` Miguel Ojeda
2026-09-09  2:26         ` Jose Fernandez (Anthropic)

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=20260904014748.C04AA1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jose.fernandez@linux.dev \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=ojeda@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.