From: sashiko-bot@kernel.org
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 1/8] bpf: mark instructions accessing program stack
Date: Thu, 04 Jun 2026 20:36:44 +0000 [thread overview]
Message-ID: <20260604203644.81EF51F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604-kasan-v2-1-c066e627fda8@bootlin.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Patched instructions incorrectly lose their `non_stack_access` marking, causing JITs to erroneously skip KASAN instrumentation for actual memory accesses.
- [Medium] Out-of-bounds pointer arithmetic in `bpf_insn_accesses_stack_only` when JIT compiling eBPF subprograms.
--
commit ae20410c7f06315eaa729fac3ff9e9abfe3062e2
Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
bpf: mark instructions accessing program stack
This patch introduces functionality to mark BPF instructions that access the
program stack. The verifier tracks non-stack memory accesses, allowing JIT
compilers to skip emitting KASAN instrumentation for stack accesses while
enforcing it for other memory types.
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index a656a8572bdbe..393d9eacd2156 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -1583,6 +1583,22 @@ bool bpf_insn_is_indirect_target(const struct bpf_verifier_env *env, const struc
> return env->insn_aux_data[insn_idx].indirect_target;
> }
>
> +bool bpf_insn_accesses_stack_only(const struct bpf_verifier_env *env,
> + const struct bpf_prog *prog, int insn_idx)
> +{
> + struct bpf_insn *insn;
> +
> + /* cBPF: we have no verifier state, do a best-effort check based on
> + * dst/src reg
> + */
> + insn_idx += prog->aux->subprog_start;
> + insn = (struct bpf_insn *)prog->insnsi + insn_idx;
> + if (!env)
[Severity: Medium]
When JIT compiling an eBPF subprogram, prog points to the subprogram and
prog->insnsi only spans the subprogram's instructions. By adding
prog->aux->subprog_start to insn_idx, doesn't this result in an
out-of-bounds pointer arithmetic for insn?
Even though the pointer is not dereferenced here because of the if (!env)
check, could this trigger UBSAN bounds-checking traps? Should the insn
pointer calculation be deferred until inside the !env block where it is
genuinely needed for cBPF?
> + return insn->dst_reg == BPF_REG_FP ||
> + insn->src_reg == BPF_REG_FP;
> + return !env->insn_aux_data[insn_idx].non_stack_access;
> +}
> +
> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
> index 5aa3f7d99ac92..5228c910fbf56 100644
> --- a/kernel/bpf/fixups.c
> +++ b/kernel/bpf/fixups.c
[ ... ]
> @@ -185,16 +185,22 @@ static void adjust_insn_aux_data(struct bpf_verifier_env *env,
[ ... ]
> if (data[off + cnt - 1].indirect_target) {
> data[off].indirect_target = 1;
> data[off + cnt - 1].indirect_target = 0;
> }
> +
> + if (data[off + cnt - 1].non_stack_access) {
> + data[off].non_stack_access = 1;
> + data[off + cnt - 1].non_stack_access = 0;
> + }
[Severity: High]
When bpf_patch_insn_data() expands a single instruction into multiple
instructions, this logic restricts the non_stack_access flag to only the
first instruction of the patched sequence and clears it for the rest.
Since the actual memory load or store in a patched sequence often occurs on
subsequent instructions rather than the first, wouldn't they lose this flag
and incorrectly bypass KASAN checks during JIT compilation?
> }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604-kasan-v2-0-c066e627fda8@bootlin.com?part=1
next prev parent reply other threads:[~2026-06-04 20:36 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 20:21 [PATCH bpf-next v2 0/8] bpf: add support for KASAN checks in JITed programs Alexis Lothoré (eBPF Foundation)
2026-06-04 20:21 ` [PATCH bpf-next v2 1/8] bpf: mark instructions accessing program stack Alexis Lothoré (eBPF Foundation)
2026-06-04 20:36 ` sashiko-bot [this message]
2026-06-04 21:13 ` bot+bpf-ci
2026-06-05 23:20 ` Alexei Starovoitov
2026-06-04 20:22 ` [PATCH bpf-next v2 2/8] bpf: add BPF_JIT_KASAN for KASAN instrumentation of JITed programs Alexis Lothoré (eBPF Foundation)
2026-06-04 21:13 ` bot+bpf-ci
2026-06-04 20:22 ` [PATCH bpf-next v2 3/8] bpf, x86: add helper to emit kasan checks in x86 " Alexis Lothoré (eBPF Foundation)
2026-06-04 20:50 ` sashiko-bot
2026-06-04 20:22 ` [PATCH bpf-next v2 4/8] bpf, x86: refactor BPF_ST management in do_jit Alexis Lothoré (eBPF Foundation)
2026-06-04 20:57 ` sashiko-bot
2026-06-04 21:13 ` bot+bpf-ci
2026-06-05 23:22 ` Alexei Starovoitov
2026-06-04 20:22 ` [PATCH bpf-next v2 5/8] bpf, x86: emit KASAN checks into x86 JITed programs Alexis Lothoré (eBPF Foundation)
2026-06-04 21:08 ` sashiko-bot
2026-06-05 14:54 ` Yonghong Song
2026-06-05 15:50 ` Alexis Lothoré
2026-06-04 20:22 ` [PATCH bpf-next v2 6/8] bpf, x86: enable KASAN for JITed programs on x86 Alexis Lothoré (eBPF Foundation)
2026-06-04 21:21 ` sashiko-bot
2026-06-04 20:22 ` [PATCH bpf-next v2 7/8] selftests/bpf: add helper to check whether eBPF KASAN is active Alexis Lothoré (eBPF Foundation)
2026-06-04 20:22 ` [PATCH bpf-next v2 8/8] selftests/bpf: add tests to validate KASAN on JIT programs Alexis Lothoré (eBPF Foundation)
2026-06-04 21:42 ` sashiko-bot
2026-06-04 21:45 ` bot+bpf-ci
2026-06-05 15:47 ` Yonghong Song
2026-06-05 16:01 ` Alexis Lothoré
2026-06-05 17:20 ` Yonghong Song
2026-06-05 20:55 ` Alexis Lothoré
2026-06-06 4:09 ` Yonghong Song
2026-06-06 8:51 ` 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=20260604203644.81EF51F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--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