BPF List
 help / color / mirror / Atom feed
From: "Alexis Lothoré" <alexis.lothore@bootlin.com>
To: sashiko-reviews@lists.linux.dev,
	"Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>
Cc: <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v4 04/10] bpf, x86: add helper to emit kasan checks in x86 JITed programs
Date: Wed, 08 Jul 2026 16:20:27 +0200	[thread overview]
Message-ID: <DJT985A6ZGZ3.2496O5EXL4MDR@bootlin.com> (raw)
In-Reply-To: <20260708081612.7006D1F000E9@smtp.kernel.org>

On Wed Jul 8, 2026 at 10:16 AM CEST, sashiko-bot wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] emit_kasan_check() fails to save caller-saved registers r10 (BPF_REG_AX) and r11 (AUX_REG), causing them to be clobbered by C KASAN helpers.
> - [Low] The static function emit_kasan_check() is defined but never called, leading to a -Wunused-function compiler warning and build failure.

[...]

>> +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]
> Does this introduce a -Wunused-function compiler warning? The static function
> emit_kasan_check() is added here but does not appear to be called anywhere in
> this patch. This could cause build failures on setups with -Werror, breaking
> git bisectability.

True, that standalone definition was intended to ease the review. I'll
keep it as is, unless anyone requires this to be squashed in the commit
actually calling the new helper.

[...]

>> +	/* 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]
> Could omitting r10 and r11 here lead to data corruption? 
>
> The commit message mentions skipping them to reduce overhead, but the called
> C functions (__asan_loadX, __asan_storeX) follow the System V AMD64 ABI and
> might clobber caller-saved registers like r10 and r11. 
>
> In the x86 BPF JIT, r10 is mapped to BPF_REG_AX, which is used across
> instructions to hold state (such as during constant blinding rewrites where
> BPF_ST_MEM is transformed into BPF_STX_MEM using BPF_REG_AX as its source).
>
> Would this result in storing garbage data when the C helper clobbers
> BPF_REG_AX?

Already discussed multiple time in the previous revisions.

Alexis
>
>> +
>> +	/* mov rdi, addr_reg */
>> +	EMIT_mov(BPF_REG_1, addr_reg);
> [ ... ]




-- 
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


  reply	other threads:[~2026-07-08 14:20 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  8:00 [PATCH bpf-next v4 00/10] bpf: add support for KASAN checks in JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-08  8:00 ` [PATCH bpf-next v4 01/10] bpf: propagate original instruction offset when patching program Alexis Lothoré (eBPF Foundation)
2026-07-08  8:19   ` sashiko-bot
2026-07-08 14:11     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 02/10] bpf: mark instructions accessing program stack Alexis Lothoré (eBPF Foundation)
2026-07-08  8:10   ` sashiko-bot
2026-07-08 14:15     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 03/10] bpf: add BPF_JIT_KASAN for KASAN instrumentation of JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-08 12:48   ` Andrey Konovalov
2026-07-08  8:00 ` [PATCH bpf-next v4 04/10] bpf, x86: add helper to emit kasan checks in x86 " Alexis Lothoré (eBPF Foundation)
2026-07-08  8:16   ` sashiko-bot
2026-07-08 14:20     ` Alexis Lothoré [this message]
2026-07-08  8:00 ` [PATCH bpf-next v4 05/10] bpf, x86: refactor BPF_ST management in do_jit Alexis Lothoré (eBPF Foundation)
2026-07-08  8:00 ` [PATCH bpf-next v4 06/10] bpf, x86: emit KASAN checks into x86 JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-08  8:16   ` sashiko-bot
2026-07-08 14:29     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 07/10] bpf, x86: enable KASAN for JITed programs on x86 Alexis Lothoré (eBPF Foundation)
2026-07-08  8:19   ` sashiko-bot
2026-07-08 14:33     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 08/10] selftests/bpf: add helper to check whether eBPF KASAN is active Alexis Lothoré (eBPF Foundation)
2026-07-08  8:00 ` [PATCH bpf-next v4 09/10] selftests/bpf: move bpf_jit_harden helper into testing_helpers Alexis Lothoré (eBPF Foundation)
2026-07-08  8:16   ` sashiko-bot
2026-07-08 14:43     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 10/10] selftests/bpf: add tests to validate KASAN on JIT programs Alexis Lothoré (eBPF Foundation)
2026-07-08  8:28   ` sashiko-bot
2026-07-08 14:47     ` 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=DJT985A6ZGZ3.2496O5EXL4MDR@bootlin.com \
    --to=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox