All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 07/17] bpf, x86: Add JIT support for callx
Date: Tue, 22 Sep 2026 01:27:12 +0000	[thread overview]
Message-ID: <20260922012712.6B21C1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260922011323.1298619-8-alexei.starovoitov@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: callx bypasses KCFI due to missing caller-side hash check
--

commit d4dfd1b46a3e02ea97924c833ac04239e01627f1
Author: Alexei Starovoitov <ast@kernel.org>
Subject: bpf, x86: Add JIT support for callx

This commit adds JIT support for BPF indirect calls via the register that
holds the address of the BPF subprog. It introduces the emit_indirect_call
helper to handle the translation using ITS or retpoline thunks.

> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
[ ... ]
> @@ -749,6 +749,46 @@ static void emit_indirect_jump(u8 **pprog, int bpf_reg, u8 *ip)
>  	*pprog = prog;
>  }
>  
> +static void __emit_indirect_call(u8 **pprog, int reg, bool ereg)
> +{
> +	u8 *prog = *pprog;
> +
> +	if (ereg)
> +		EMIT1(0x41);
> +
> +	EMIT2(0xFF, 0xD0 + reg);
> +
> +	*pprog = prog;
> +}
> +
> +/* call *bpf_reg */
> +static int emit_indirect_call(u8 **pprog, int bpf_reg, u8 *ip)
> +{
> +	u8 *prog = *pprog;
> +	int reg = reg2hex[bpf_reg];
> +	bool ereg = is_ereg(bpf_reg);
> +	int err = 0;
> +
> +	if (cpu_feature_enabled(X86_FEATURE_INDIRECT_THUNK_ITS)) {
> +		OPTIMIZER_HIDE_VAR(reg);
> +		err = emit_call(&prog, its_static_thunk(reg + 8*ereg), ip);
> +	} else if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE)) {
> +		EMIT_LFENCE();
> +		__emit_indirect_call(&prog, reg, ereg);
> +	} else if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) {
> +		OPTIMIZER_HIDE_VAR(reg);
> +		if (cpu_feature_enabled(X86_FEATURE_CALL_DEPTH))
> +			err = emit_call(&prog, &__x86_indirect_call_thunk_array[reg + 8*ereg], ip);
> +		else
> +			err = emit_call(&prog, &__x86_indirect_thunk_array[reg + 8*ereg], ip);
> +	} else {
> +		__emit_indirect_call(&prog, reg, ereg);

[Severity: High]
Does emit_indirect_call() emit raw indirect branches without KCFI hash
validation?

If KCFI is active, it seems __emit_indirect_call() emits a bare indirect
branch instruction without the preceding caller-side hash check.

If an attacker were able to overwrite a spilled subprogram pointer, could they
trigger this execution path to jump to an arbitrary kernel address and bypass
KCFI protections?

> +	}
> +
> +	*pprog = prog;
> +	return err;
> +}
> +
[ ... ]
> @@ -4414,6 +4472,16 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
>  	return prog;
>  }
>  
> +bool bpf_jit_supports_callx(void)
> +{
> +	/*
> +	 * FineIBT poisons ENDBR at the entry of a JITed function and expects
> +	 * indirect callers to go through the CFI preamble instead.
> +	 * callx doesn't do that yet.
> +	 */
> +	return cfi_mode != CFI_FINEIBT;

[Severity: High]
Can bpf_jit_supports_callx() incorrectly allow indirect calls to be compiled
when KCFI is enabled?

The current logic blocks FineIBT but permits compilation when the CFI mode is
CFI_KCFI.

Since emit_indirect_call() does not currently emit caller-side hash checks,
allowing compilation under KCFI seems to introduce uninstrumented indirect
branches into kernel space.

> +}
> +
>  bool bpf_jit_supports_kfunc_call(void)
>  {
>  	return true;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260922011323.1298619-1-alexei.starovoitov@gmail.com?part=7

  reply	other threads:[~2026-09-22  1:27 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  1:13 [PATCH bpf-next 00/17] bpf: Indirect calls of bpf subprogs (callx) Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 01/17] bpf: Fix infinite loop in check_max_stack_depth() Alexei Starovoitov
2026-09-22  2:01   ` bot+bpf-ci
2026-09-22  2:56     ` Alexei Starovoitov
2026-09-23 22:35   ` Eduard Zingerman
2026-09-22  1:13 ` [PATCH bpf-next 02/17] selftests/bpf: Test recursion through a global function and a callback Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 03/17] bpf: Don't fold loads from insn_array maps into constants Alexei Starovoitov
2026-09-23 22:39   ` Eduard Zingerman
2026-09-23 23:12     ` Alexei Starovoitov
2026-09-24  0:19   ` bot+bpf-ci
2026-09-22  1:13 ` [PATCH bpf-next 04/17] bpf: Prepare static analysis passes for callx instruction Alexei Starovoitov
2026-09-23 23:10   ` Eduard Zingerman
2026-09-23 23:51     ` Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 05/17] bpf: Add callx instruction to call bpf subprogs indirectly Alexei Starovoitov
2026-09-24  0:09   ` Eduard Zingerman
2026-09-22  1:13 ` [PATCH bpf-next 06/17] bpf: Add callx calls to the call graph Alexei Starovoitov
2026-09-22  1:27   ` sashiko-bot
2026-09-22  2:54     ` Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 07/17] bpf, x86: Add JIT support for callx Alexei Starovoitov
2026-09-22  1:27   ` sashiko-bot [this message]
2026-09-22  2:53     ` Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 08/17] bpf, arm64: " Alexei Starovoitov
2026-09-22 15:05   ` Puranjay Mohan
2026-09-22  1:13 ` [PATCH bpf-next 09/17] bpf: Discover subprogs described by func_info Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 10/17] bpf: Recognize pointers to functions in read-only maps Alexei Starovoitov
2026-09-22  1:31   ` sashiko-bot
2026-09-22  3:01     ` Alexei Starovoitov
2026-09-24  0:46   ` bot+bpf-ci
2026-09-24  2:12     ` Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 11/17] libbpf: Support pointers to static functions in data when linking Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 12/17] libbpf: Resolve pointers to functions in read-only data Alexei Starovoitov
2026-09-24  0:33   ` bot+bpf-ci
2026-09-24  2:13     ` Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 13/17] libbpf: Treat .data.rel.ro as " Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 14/17] libbpf: Support pointers to functions in read-only data in light skeleton Alexei Starovoitov
2026-09-22  2:01   ` bot+bpf-ci
2026-09-22  2:55     ` Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 15/17] selftests/bpf: Add tests for callx Alexei Starovoitov
2026-09-24  0:33   ` bot+bpf-ci
2026-09-24  2:13     ` Alexei Starovoitov
2026-09-22  1:13 ` [PATCH bpf-next 16/17] selftests/bpf: Add tests for callx through pointers in read-only data Alexei Starovoitov
2026-09-22  2:01   ` bot+bpf-ci
2026-09-24  0:33   ` bot+bpf-ci
2026-09-22  1:13 ` [PATCH bpf-next 17/17] bpf, docs: Document callx instruction Alexei Starovoitov

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=20260922012712.6B21C1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --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.