From: sashiko-bot@kernel.org
To: "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 08:16:12 +0000 [thread overview]
Message-ID: <20260708081612.7006D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260708-kasan-v4-4-d5c177ab8227@bootlin.com>
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.
--
--- Patch [4]: [PATCH bpf-next v4 04/10] bpf, x86: add helper to emit kasan checks in x86 JITed programs ---
commit 702ec90119cefcab13a29595976ba78253e74ce6
Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
bpf, x86: add helper to emit kasan checks in x86 JITed programs
This commit adds the emit_kasan_check() function for x86 JIT-compiled
BPF programs. It emits KASAN shadow memory checks before memory accesses
by saving state, computing the address, and calling C KASAN helpers.
> 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]
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.
> +#ifdef CONFIG_BPF_JIT_KASAN
> + u32 bpf_size = BPF_SIZE(insn->code);
> + s32 off = insn->off;
> + u8 *prog = *pprog;
> + void *kasan_func;
> +
> + if (!env)
> + return 0;
> +
> + if (accesses_stack_only)
> + return 0;
> +
> + /* Derive KASAN check function from access type and size */
> + switch (bpf_size) {
> + case BPF_B:
> + kasan_func = is_write ? __asan_store1 : __asan_load1;
> + break;
> + case BPF_H:
> + kasan_func = is_write ? __asan_store2 : __asan_load2;
> + break;
> + case BPF_W:
> + kasan_func = is_write ? __asan_store4 : __asan_load4;
> + break;
> + case BPF_DW:
> + kasan_func = is_write ? __asan_store8 : __asan_load8;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + /* 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?
> +
> + /* mov rdi, addr_reg */
> + EMIT_mov(BPF_REG_1, addr_reg);
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708-kasan-v4-0-d5c177ab8227@bootlin.com?part=4
next prev parent reply other threads:[~2026-07-08 8:16 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 [this message]
2026-07-08 14:20 ` Alexis Lothoré
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=20260708081612.7006D1F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox