All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 04/10] bpf, x86: add helper to emit kasan checks in x86 JITed programs
Date: Thu, 09 Jul 2026 10:54:12 +0000	[thread overview]
Message-ID: <20260709105412.E02921F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709-kasan-v5-4-1c64af8e4e1e@bootlin.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] `emit_kasan_check()` fails to save and restore caller-saved registers `%r10` and `%r11`, causing ABI violation and memory corruption.
- [Low] `emit_kasan_check()` is static but unreferenced, breaking the build, and KASAN configuration is incomplete.
--

--- Patch [4]: [PATCH bpf-next v5 04/10] bpf, x86: add helper to emit kasan checks in x86 JITed programs ---
commit 95547145be173ba9a87f9eff2492384b8ac25f18
Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>

bpf, x86: add helper to emit kasan checks in x86 JITed programs

This commit adds emit_kasan_check(), which emits KASAN shadow memory checks
before memory accesses in JIT-compiled BPF programs. The helper calls standard
KASAN C functions to validate the memory accesses.

> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index de7515ea1beae..d35f58350d710 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c

[ ... ]

> @@ -1110,6 +1121,90 @@ static void maybe_emit_1mod(u8 **pprog, u32 reg, bool is64)
>  	*pprog = prog;
>  }
>  
> +static int emit_kasan_check(struct bpf_verifier_env *env, u8 **pprog,
> +			    u32 addr_reg, struct bpf_insn *insn, u8 *ip,
> +			    bool is_write, bool accesses_stack_only)
> +{

[Severity: Low]
Is this static function used anywhere in this patch? It looks like it is
declared and defined but never referenced, which will cause a build failure
when compiled with -Werror=unused-function.

Additionally, the HAVE_EBPF_JIT_KASAN Kconfig option does not appear to be
selected by any architecture in this series, making the feature unreachable.
(Also noting a potential issue where adjust_insn_aux_data() in
kernel/bpf/fixups.c may retain stale state when insn_off_in_patch == -1).

> +#ifdef CONFIG_BPF_JIT_KASAN
> +	u32 bpf_size = BPF_SIZE(insn->code);
> +	s32 off = insn->off;

[ ... ]

> +	/* Save rax */
> +	EMIT1(0x50);
> +	/* Save rcx */
> +	EMIT1(0x51);
> +	/* Save rdx */
> +	EMIT1(0x52);
> +	/* Save rsi */
> +	EMIT1(0x56);
> +	/* Save rdi */
> +	EMIT1(0x57);
> +	/* Save r8 */
> +	EMIT2(0x41, 0x50);
> +	/* Save r9 */
> +	EMIT2(0x41, 0x51);

[Severity: High]
Does skipping the save and restore of %r10 and %r11 violate the System V ABI?

While the commit message notes they are skipped to reduce overhead, %r10 is
mapped to BPF_REG_AX in the x86 JIT. Because standard C functions like the
KASAN helpers clobber caller-saved registers, wouldn't this corrupt the
BPF_REG_AX register (which is used for operations like blinded constant
stores) when the KASAN check is executed?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260709-kasan-v5-0-1c64af8e4e1e@bootlin.com?part=4

  reply	other threads:[~2026-07-09 10:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 10:01 [PATCH bpf-next v5 00/10] bpf: add support for KASAN checks in JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-09 10:01 ` [PATCH bpf-next v5 01/10] bpf: propagate original instruction offset when patching program Alexis Lothoré (eBPF Foundation)
2026-07-09 10:25   ` sashiko-bot
2026-07-09 10:01 ` [PATCH bpf-next v5 02/10] bpf: mark instructions accessing program stack Alexis Lothoré (eBPF Foundation)
2026-07-09 10:35   ` sashiko-bot
2026-07-09 10:01 ` [PATCH bpf-next v5 03/10] bpf: add BPF_JIT_KASAN for KASAN instrumentation of JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-09 10:01 ` [PATCH bpf-next v5 04/10] bpf, x86: add helper to emit kasan checks in x86 " Alexis Lothoré (eBPF Foundation)
2026-07-09 10:54   ` sashiko-bot [this message]
2026-07-09 10:01 ` [PATCH bpf-next v5 05/10] bpf, x86: refactor BPF_ST management in do_jit Alexis Lothoré (eBPF Foundation)
2026-07-09 11:08   ` sashiko-bot
2026-07-09 10:01 ` [PATCH bpf-next v5 06/10] bpf, x86: emit KASAN checks into x86 JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-09 11:20   ` sashiko-bot
2026-07-09 10:01 ` [PATCH bpf-next v5 07/10] bpf, x86: enable KASAN for JITed programs on x86 Alexis Lothoré (eBPF Foundation)
2026-07-09 11:29   ` sashiko-bot
2026-07-09 10:01 ` [PATCH bpf-next v5 08/10] selftests/bpf: add helpers for KASAN in JIT testing Alexis Lothoré (eBPF Foundation)
2026-07-09 11:35   ` sashiko-bot
2026-07-09 10:01 ` [PATCH bpf-next v5 09/10] selftests/bpf: move bpf_jit_harden helper into testing_helpers Alexis Lothoré (eBPF Foundation)
2026-07-09 10:01 ` [PATCH bpf-next v5 10/10] selftests/bpf: add tests to validate KASAN on JIT programs Alexis Lothoré (eBPF Foundation)
2026-07-09 11:52   ` sashiko-bot
2026-07-09 18:53 ` [PATCH bpf-next v5 00/10] bpf: add support for KASAN checks in JITed programs Borislav Petkov
2026-07-09 19:09   ` Alexis Lothoré

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=20260709105412.E02921F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexis.lothore@bootlin.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.