mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: alexis.lothore@bootlin.com,ast@kernel.org,daniel@iogearbox.net,john.fastabend@gmail.com,andrii@kernel.org,martin.lau@linux.dev,eddyz87@gmail.com,memxor@gmail.com,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,tglx@kernel.org,bp@alien8.de,dave.hansen@linux.intel.com,x86@kernel.org,hpa@zytor.com,shuah@kernel.org,mingo@redhat.com,andreyknvl@gmail.com,emil@etsalapatis.com,ihor.solodrai@linux.dev,laoar.shao@gmail.com
Cc: ebpf@linuxfoundation.org,bastien.curutchet@bootlin.com,thomas.petazzoni@bootlin.com,bpf@vger.kernel.org,linux-kernel@vger.kernel.org,linux-kselftest@vger.kernel.org,alexis.lothore@bootlin.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v9 4/8] bpf, x86: emit KASAN checks in x86 JITed programs
Date: Thu,  3 Sep 2026 15:18:20 +0000 (UTC)	[thread overview]
Message-ID: <aaaee75404be1c0851e0da15b1f2903eb6bf768bc2e763fcfa5a1d45e1ffc498@mail.kernel.org> (raw)
In-Reply-To: <20260903-kasan-v9-4-2407fe99255a@bootlin.com>

[-- Attachment #1: Type: text/plain, Size: 2642 bytes --]

> The main instructions being targeted are BPF_ST, BPF_STX and BPF_LDX,
> but not all of them are being instrumented:
> - if the load/store instruction is in fact accessing the program stack,
>   emit_kasan_check silently skips the instrumentation, as we can already
>   benefit from guard pages to monitor stack accesses.
> - if the load/store instruction is a BPF_PROBE_MEM or a BPF_PROBE_ATOMIC
>   instruction, we do not instrument it, as the passed address can fault
>   (hence the custom fault management with BPF_PROBE_XXX instructions),
>   and so the corresponding kasan check could fault as well.

This isn't a bug, but could the changelog be more precise about where
the stack-access skip happens?

The text says emit_kasan_check() "silently skips the instrumentation"
for stack accesses, but the decision is actually made in do_jit() by the
new accesses_stack_only test:

arch/x86/net/bpf_jit_comp.c:do_jit() {
    ...
    insn_idx = i - 1 + bpf_prog->aux->subprog_start;
    accesses_stack_only =
        env ? !env->insn_aux_data[insn_idx].non_stack_access :
              false;
    ...
}

which reads the verifier's per-instruction non_stack_access flag set by
mark_non_stack_access() at kernel/bpf/verifier.c:6665.

emit_kasan_check() only skips when the address register is literally
BPF_REG_FP or BPF_REG_PARAMS. The list also omits BPF_PROBE_MEM32
(arena) accesses, which are handled by separate case labels and likewise
left uninstrumented.

[ ... ]

> @@ -1914,6 +2032,10 @@
>  		EMIT_ENDBR();
>
>  	ip = image + addrs[i - 1] + (prog - temp);
> +	insn_idx = i - 1 + bpf_prog->aux->subprog_start;
> +	accesses_stack_only =
> +		env ? !env->insn_aux_data[insn_idx].non_stack_access :
> +		      false;

This isn't a bug, but would a positively named predicate read more
directly here?

When env is NULL the fallback value false means "this access is not
stack-only", so every load/store takes the !accesses_stack_only path and
calls emit_kasan_check(), which immediately returns 0 because of its own
if (!env) return 0; guard at arch/x86/net/bpf_jit_comp.c:1129.

The intent (no instrumentation without a verifier env) is expressed
through a double negative plus a second guard in the callee. Would
accesses_stack_only = !env || !env->insn_aux_data[insn_idx].non_stack_access
(or a want_kasan_check predicate) make the no-env case self-evident and
drop the redundant callee check?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/33766012402

  reply	other threads:[~2026-09-03 15:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03 13:51 [PATCH bpf-next v9 0/8] bpf: add support for KASAN checks in " Alexis Lothoré (eBPF Foundation)
2026-09-03 13:51 ` [PATCH bpf-next v9 1/8] bpf: mark instructions accessing program stack Alexis Lothoré (eBPF Foundation)
2026-09-03 15:18   ` bot+bpf-ci
2026-09-03 13:51 ` [PATCH bpf-next v9 2/8] bpf: add BPF_JIT_KASAN for KASAN instrumentation of JITed programs Alexis Lothoré (eBPF Foundation)
2026-09-03 13:51 ` [PATCH bpf-next v9 3/8] bpf, x86: refactor BPF_ST management in do_jit Alexis Lothoré (eBPF Foundation)
2026-09-03 13:51 ` [PATCH bpf-next v9 4/8] bpf, x86: emit KASAN checks in x86 JITed programs Alexis Lothoré (eBPF Foundation)
2026-09-03 15:18   ` bot+bpf-ci [this message]
2026-09-03 13:51 ` [PATCH bpf-next v9 5/8] bpf, x86: enable KASAN for JITed programs on x86 Alexis Lothoré (eBPF Foundation)
2026-09-03 13:51 ` [PATCH bpf-next v9 6/8] selftests/bpf: make cmdline_contains stricter Alexis Lothoré (eBPF Foundation)
2026-09-03 13:51 ` [PATCH bpf-next v9 7/8] selftests/bpf: add helpers for KASAN in JIT testing Alexis Lothoré (eBPF Foundation)
2026-09-03 13:51 ` [PATCH bpf-next v9 8/8] selftests/bpf: add tests to validate KASAN on JIT programs Alexis Lothoré (eBPF Foundation)
2026-09-04  9:02 ` [PATCH bpf-next v9 0/8] bpf: add support for KASAN checks in JITed programs Kumar Kartikeya Dwivedi
2026-09-04 17:00 ` patchwork-bot+netdevbpf

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=aaaee75404be1c0851e0da15b1f2903eb6bf768bc2e763fcfa5a1d45e1ffc498@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=alexis.lothore@bootlin.com \
    --cc=andreyknvl@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bastien.curutchet@bootlin.com \
    --cc=bp@alien8.de \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=ebpf@linuxfoundation.org \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=hpa@zytor.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=laoar.shao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mingo@redhat.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tglx@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=x86@kernel.org \
    --cc=yonghong.song@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

all inboxes | Powered by JetHome®