From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: sashiko-reviews@lists.linux.dev,
"Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 05/10] bpf, x86: refactor BPF_ST management in do_jit
Date: Wed, 15 Jul 2026 15:27:12 -0700 [thread overview]
Message-ID: <9ddec85b-2a70-4bf6-af09-701f485d0cae@linux.dev> (raw)
In-Reply-To: <20260709110819.6BED51F000E9@smtp.kernel.org>
On 7/9/26 4:08 AM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] The `emit_st()` helper absorbs `Arg 6` pseudo-store and `BPF_REG_PARAMS` translation, causing invalid KASAN instrumentation for BPF_ST instructions.
> --
>
> --- Patch [5]: [PATCH bpf-next v5 05/10] bpf, x86: refactor BPF_ST management in do_jit ---
> commit b88dd49e34d6904772392eec8dfdeba3542805c4
> Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
>
> bpf, x86: refactor BPF_ST management in do_jit
>
> This commit extracts the x86-64 BPF_ST instruction emission logic into a single
> emit_st() helper function. It is intended to prepare for KASAN checks being
> inserted before memory loads and stores.
>
>> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
>> index d35f58350d710..959fcaa0cde9a 100644
>> --- a/arch/x86/net/bpf_jit_comp.c
>> +++ b/arch/x86/net/bpf_jit_comp.c
>> @@ -1410,6 +1410,64 @@ static void emit_st_index(u8 **pprog, u32 size, u32 dst_reg, u32 index_reg, int
>> *pprog = prog;
>> }
>>
>> +static void emit_st(u8 **pprog, struct bpf_insn *insn, int dst_reg,
>> + s32 outgoing_arg_base, u16 outgoing_rsp)
>> +{
>> + s32 imm32 = insn->imm;
>> + u8 *prog = *pprog;
>> + s32 insn_off;
>> +
>> + switch (BPF_SIZE(insn->code)) {
> [ ... ]
>> + case BPF_DW:
>> + if (dst_reg == BPF_REG_PARAMS && insn->off == -8) {
>> + /* Arg 6: store immediate in r9 register */
>> + emit_mov_imm64(&prog, X86_REG_R9, imm32 >> 31,
>> + (u32)imm32);
>> + *pprog = prog;
>> + return;
>> + }
>> + EMIT2(add_1mod(0x48, dst_reg), 0xC7);
>> + break;
>> + }
>> +
>> + insn_off = insn->off;
>> + if (dst_reg == BPF_REG_PARAMS) {
>> + /*
>> + * Args 7+: reverse BPF negative offsets to
>> + * x86 positive rsp offsets.
>> + * BPF off=-16 → [rsp+0], off=-24 → [rsp+8], ...
>> + */
>> + insn_off = outgoing_arg_base - outgoing_rsp -
>> + insn_off - 16;
>> + dst_reg = BPF_REG_FP;
>> + }
>
> [Severity: High]
> Does hiding the BPF_REG_PARAMS translation inside emit_st() conflict with the
> stated goal of adding KASAN instrumentation before the call?
>
> If KASAN checks are inserted in do_jit() before emit_st() is called, wouldn't
> they attempt to instrument Arg 6 (which uses register r9, not memory)?
>
> Additionally, wouldn't any KASAN checks added before this helper use the raw
> BPF_REG_PARAMS pseudo-register before it is translated to BPF_REG_FP, causing
> instrumentation against an unmapped register (which evaluates to rax)?
I think sashiko is wrong, because BPF_REG_PARAMS stores should always have
non_stack_access = false, but please double check
>
> [ ... ]
>
next prev parent reply other threads:[~2026-07-15 22:27 UTC|newest]
Thread overview: 32+ 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-15 0:47 ` Ihor Solodrai
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-15 0:49 ` Ihor Solodrai
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
2026-07-15 0:53 ` Ihor Solodrai
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-15 22:27 ` Ihor Solodrai [this message]
2026-07-15 22:25 ` Ihor Solodrai
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-15 22:28 ` Ihor Solodrai
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-15 22:31 ` Ihor Solodrai
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-15 22:32 ` Ihor Solodrai
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-15 22:33 ` Ihor Solodrai
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-15 22:35 ` Ihor Solodrai
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é
2026-07-15 0:43 ` Ihor Solodrai
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=9ddec85b-2a70-4bf6-af09-701f485d0cae@linux.dev \
--to=ihor.solodrai@linux.dev \
--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