All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexis Lothoré" <alexis.lothore@bootlin.com>
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	sashiko-reviews@lists.linux.dev,
	"Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>
Cc: <bpf@vger.kernel.org>, "Alexei Starovoitov" <ast@kernel.org>
Subject: Re: [PATCH bpf-next v7 4/9] bpf, x86: emit KASAN checks in x86 JITed programs
Date: Tue, 25 Aug 2026 09:03:59 +0200	[thread overview]
Message-ID: <DKXU03VFF1HG.1LI7OCCH41D5E@bootlin.com> (raw)
In-Reply-To: <DKXLJLAMA1KZ.14CXAXXD5S0WQ@gmail.com>

Hi Ihor, Kumar,

On Tue Aug 25, 2026 at 2:26 AM CEST, Kumar Kartikeya Dwivedi wrote:

[...]

>>>> If %r10 is clobbered, could this corrupt the stashed BPF_REG_0 and potentially
>>>> cause a crash when real_dst_reg is used as a memory pointer in the subsequent
>>>> emit_ldx() call?
>>>>
>>>> arch/x86/net/bpf_jit_comp.c:do_jit() {
>>>>     ...
>>>>     /* Load old value */
>>>>     emit_ldx(&prog, BPF_SIZE(insn->code), BPF_REG_0, real_dst_reg, insn->off);
>>>>     ...
>>>>     /* Restore R0 after clobbering RAX */
>>>>     emit_mov_reg(&prog, true, BPF_REG_0, BPF_REG_AX);
>>>>     ...
>>>> }
>>>
>>> This looks like a real bug, R10 is used for both atomics and constant blinding.
>>> We probably also should save R11.
>>
>>
>> Hi Kumar, Alexis.
>>
>> This topic has a bit of history now [1][2].
>
> From [1],
>
> "I built the kernel with gcc 11.5, gcc 15.2 and clang 22 and
> disassembled __asan_{load,store}{1,2,4,8}: none of them touch r10 or
> r11. gcc goes up to r8, clang uses nothing above rdi."
>
> Isn't this dependent on register pressure inside the function, i.e. depending on
> different code or whatever, it might begin using those registers?
>
>> I don't quite like it, but IMO we should give in to the bots.
>>
>> Reasons to save r10 and r11:
>> * SystemV ABI
>> * bots wouldn't shut up about it (think of future llm bot reports!)
>> * if our analysis of the kasan helpers is wrong about r10/r11 usage OR
>>   if something changes (the helpers themselves, the compilers, build
>>   flags, JIT's usage of r10/r11 etc.) - we'll get clobbered regs

Indeed, there's this risk of future versions of compilers deciding to
change the way those asan helpers are compiled, it will then silently
break (not sure how big of a risk it is, though).

>> Reasons to *not* save r10 and r11:
>> * we make the bpf prog a bit smaller and faster, the win is not very
>>   clear but it's percentages, not a factor
>>
>
> Yeah, also, we're already saving a ton of other registers, I don't know whether
> saving two would matter, even if it wasn't incorrect. I wouldn't worry too much
> about KASAN performance, it's already orders of magnitude slower than normal
> kernel build.

Ok, let's settle this then, I'll re-apply the r10/r11 save/restore
mechanism. If we eventually end up wanting to optimize it, this can be
revisited later.

Alexis

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


  reply	other threads:[~2026-08-25  7:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 22:39 [PATCH bpf-next v7 0/9] bpf: add support for KASAN checks in JITed programs Alexis Lothoré (eBPF Foundation)
2026-08-21 22:39 ` [PATCH bpf-next v7 1/9] bpf: mark instructions accessing program stack Alexis Lothoré (eBPF Foundation)
2026-08-21 22:54   ` sashiko-bot
2026-08-21 23:24   ` bot+bpf-ci
2026-08-23 22:33     ` Kumar Kartikeya Dwivedi
2026-08-21 22:39 ` [PATCH bpf-next v7 2/9] bpf: add BPF_JIT_KASAN for KASAN instrumentation of JITed programs Alexis Lothoré (eBPF Foundation)
2026-08-21 22:39 ` [PATCH bpf-next v7 3/9] bpf, x86: refactor BPF_ST management in do_jit Alexis Lothoré (eBPF Foundation)
2026-08-21 22:39 ` [PATCH bpf-next v7 4/9] bpf, x86: emit KASAN checks in x86 JITed programs Alexis Lothoré (eBPF Foundation)
2026-08-21 23:24   ` bot+bpf-ci
2026-08-21 23:33   ` sashiko-bot
2026-08-23 22:30     ` Kumar Kartikeya Dwivedi
2026-08-25  0:12       ` Ihor Solodrai
2026-08-25  0:26         ` Kumar Kartikeya Dwivedi
2026-08-25  7:03           ` Alexis Lothoré [this message]
2026-08-21 22:39 ` [PATCH bpf-next v7 5/9] bpf, x86: enable KASAN for JITed programs on x86 Alexis Lothoré (eBPF Foundation)
2026-08-21 22:55   ` sashiko-bot
2026-08-21 22:39 ` [PATCH bpf-next v7 6/9] selftests/bpf: make cmdline_contains stricter Alexis Lothoré (eBPF Foundation)
2026-08-21 22:39 ` [PATCH bpf-next v7 7/9] selftests/bpf: add helpers for KASAN in JIT testing Alexis Lothoré (eBPF Foundation)
2026-08-21 22:39 ` [PATCH bpf-next v7 8/9] selftests/bpf: move bpf_jit_harden helper into testing_helpers Alexis Lothoré (eBPF Foundation)
2026-08-21 23:13   ` bot+bpf-ci
2026-08-21 22:39 ` [PATCH bpf-next v7 9/9] selftests/bpf: add tests to validate KASAN on JIT programs Alexis Lothoré (eBPF Foundation)
2026-08-21 23:36   ` bot+bpf-ci
2026-08-23 22:40   ` Kumar Kartikeya Dwivedi
2026-08-23 22:53     ` Kumar Kartikeya Dwivedi
2026-08-23 22:53 ` [PATCH bpf-next v7 0/9] bpf: add support for KASAN checks in JITed programs Kumar Kartikeya Dwivedi

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=DKXU03VFF1HG.1LI7OCCH41D5E@bootlin.com \
    --to=alexis.lothore@bootlin.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=memxor@gmail.com \
    --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.