BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v9 8/8] selftests/bpf: add tests to validate KASAN on JIT programs
Date: Thu, 03 Sep 2026 14:10:57 +0000	[thread overview]
Message-ID: <20260903141058.722411F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260903-kasan-v9-8-2407fe99255a@bootlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Uninitialized stack variables in BPF programs cause the BPF verifier to reject the programs unless compiled with auto-initialization.
--

commit 90ac04f2b17e345bd3d2714823f9bf8e9abd88df
Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>

selftests/bpf: add tests to validate KASAN on JIT programs
    
Add a basic KASAN test runner that loads and test-run programs that can
trigger memory management bugs. The test captures kernel logs and ensure
that the expected KASAN splat is emitted by searching for the
corresponding first lines in the report.

> diff --git a/tools/testing/selftests/bpf/progs/kasan.c b/tools/testing/selftests/bpf/progs/kasan.c
> new file mode 100644
> index 0000000000000..fe8e0dd228a09
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/kasan.c
> @@ -0,0 +1,502 @@
[ ... ]
> +SEC("tcx/ingress")
> +int st_on_stack(struct __sk_buff *skb)
> +{
> +	struct kasan_test_val val;
> +
> +	bpf_kfunc_kasan_poison(&val, sizeof(struct kasan_test_val));

[Severity: Medium]
Does this code cause a BPF verifier rejection? The BPF verifier requires
stack memory to be initialized before it is read. By passing the pointer
to val to bpf_kfunc_kasan_poison() when val is uninitialized, the verifier
will reject the program unless the kfunc argument is annotated to allow
uninitialized memory (or the toolchain automatically initializes stack
variables).

This exact pattern appears in all the _on_stack tests in this file (such as
stx_on_stack, ldx_on_stack, simple_atomic_on_stack, etc.). Should val be
initialized (for example, struct kasan_test_val val = {};)?

[ ... ]
> +SEC("tcx/ingress")
> +int ldx_oob(struct __sk_buff *skb)
> +{
> +	struct bpf_testmod_oob *val;
> +	struct kasan_test_val volatile tmp;
> +
> +	val = bpf_testmod_oob_alloc();
> +	if (!val)
> +		return 0;
> +
> +	switch (access_size) {
> +	case 1:
> +		tmp.data_1 = (__u8)val->redzone_1;
> +		break;
> +	case 2:
> +		tmp.data_2 = (__u16)val->redzone_2;
> +		break;
> +	case 4:
> +		tmp.data_4 = (__u32)val->redzone_4;
> +		break;
> +	case 8:
> +		tmp.data_8 = (__u64)val->redzone_8;
> +		break;
> +	}
> +	bpf_testmod_oob_free(val);
> +	return tmp.data_1;
> +}

[Severity: Medium]
Can tmp.data_1 be returned uninitialized here? If access_size != 1,
tmp.data_1 is never written to during the switch statement, but it is read
on the return path. This will cause the BPF verifier to reject the program for
an invalid read from uninitialized stack memory.

Should tmp be initialized when declared?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260903-kasan-v9-0-2407fe99255a@bootlin.com?part=8

  reply	other threads:[~2026-09-03 14:11 UTC|newest]

Thread overview: 14+ 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 JITed programs 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
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-03 14:10   ` sashiko-bot [this message]
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=20260903141058.722411F00A3E@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