BPF List
 help / color / mirror / Atom feed
From: "Alexis Lothoré" <alexis.lothore@bootlin.com>
To: sashiko-reviews@lists.linux.dev,
	"Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>
Cc: <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v4 10/10] selftests/bpf: add tests to validate KASAN on JIT programs
Date: Wed, 08 Jul 2026 16:47:49 +0200	[thread overview]
Message-ID: <DJT9T3MEILYQ.2KNU0Q7RKM3SW@bootlin.com> (raw)
In-Reply-To: <20260708082841.9FF7C1F00A3A@smtp.kernel.org>

On Wed Jul 8, 2026 at 10:28 AM CEST, sashiko-bot wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [Medium] Test fails spuriously on default kernels due to missing verification of the kasan_multi_shot requirement.
> - [Low] The variable `nsize` is assigned but never used, constituting dead code.
> --
>
> --- Patch [10]: [PATCH bpf-next v4 10/10] selftests/bpf: add tests to validate KASAN on JIT programs ---
> commit c15c25b993ae0bc70091046fa0c6b2bb1e71d099
> Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
>
> selftests/bpf: add tests to validate KASAN on JIT programs
>
> This patch adds a basic test runner to load and run BPF programs that
> trigger memory management bugs to validate KASAN instrumentation.
> It runs various memory access tests and checks kernel logs for the expected
> KASAN splat, requiring the kernel to be configured with kasan_multi_shot.
>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/kasan.c b/tools/testing/selftests/bpf/prog_tests/kasan.c
>> new file mode 100644
>> index 0000000000000..f006b92ee131a
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/prog_tests/kasan.c
>
> [ ... ]
>
>> +static int check_kasan_report_in_kernel_logs(char *buf, struct test_ctx *ctx,
>> +					     bool is_write, int size)
>> +{
>> +	char access_log[READ_CHUNK_SIZE];
>> +	char *kasan_report_start;
>> +	int nsize;
>> +
>> +	snprintf(access_log, READ_CHUNK_SIZE, KASAN_PATTERN_SLAB_UAF,
>> +		 ctx->prog_tag[0], ctx->prog_tag[1], ctx->prog_tag[2],
>> +		 ctx->prog_tag[3], ctx->prog_tag[4], ctx->prog_tag[5],
>> +		 ctx->prog_tag[6], ctx->prog_tag[7], ctx->prog_name);
>
> [ ... ]
>
>> +	kasan_report_start = strstr(buf, access_log);
>> +
>> +	if (!kasan_report_start)
>> +		return 1;
>> +
>> +	nsize = snprintf(access_log, READ_CHUNK_SIZE, KASAN_PATTERN_REPORT,
>> +			 is_write ? "Write" : "Read", size);
>
> [Severity: Low]
> This isn't a bug, but the variable nsize is assigned here and never used.
> Should this assignment be removed to avoid dead code?

I'll rather add an ASSERT on it.

>> +
>> +	if (!strstr(kasan_report_start, access_log))
>> +		return 1;
>> +
>> +	return 0;
>> +}
>
> [ ... ]
>
>> +void test_kasan(void)
>> +{
>> +	struct kasan_write_val val;
>> +	struct test_spec *test;
>> +	struct test_ctx *ctx;
>> +	struct kasan *skel;
>> +	__u32 key = 0;
>> +	int i, ret;
>> +
>> +	ctx = calloc(1, sizeof(struct test_ctx));
>> +	if (!ASSERT_OK_PTR(ctx, "alloc test ctx"))
>> +		return;
>> +
>> +	if (!is_jit_enabled() || !get_kasan_jit_enabled()) {
>> +		test__skip();
>> +		goto end;
>> +	}
>
> [Severity: Medium]
> Since the commit message notes that the kernel must run with the
> kasan_multi_shot configuration, what happens if this parameter is missing?
>
> Could this test fail spuriously on default kernels where multi-shot is
> disabled, since it doesn't verify if kasan_multi_shot is active before
> triggering multiple reports?

The current test design assumes that kasan_multi_shot is not enabled by
the test itself but by the CI runner. This is actually already the case
for the BPF CI. But maybe having a SKIP instead of FAIL is more friendly
for anyone trying to run the tests and forgetting to enable
kasan_multi_shot (some additional doc have been requested and added
since first revision, but I guess the check would not hurt).

Alexis

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


      reply	other threads:[~2026-07-08 14:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  8:00 [PATCH bpf-next v4 00/10] bpf: add support for KASAN checks in JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-08  8:00 ` [PATCH bpf-next v4 01/10] bpf: propagate original instruction offset when patching program Alexis Lothoré (eBPF Foundation)
2026-07-08  8:19   ` sashiko-bot
2026-07-08 14:11     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 02/10] bpf: mark instructions accessing program stack Alexis Lothoré (eBPF Foundation)
2026-07-08  8:10   ` sashiko-bot
2026-07-08 14:15     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 03/10] bpf: add BPF_JIT_KASAN for KASAN instrumentation of JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-08 12:48   ` Andrey Konovalov
2026-07-08  8:00 ` [PATCH bpf-next v4 04/10] bpf, x86: add helper to emit kasan checks in x86 " Alexis Lothoré (eBPF Foundation)
2026-07-08  8:16   ` sashiko-bot
2026-07-08 14:20     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 05/10] bpf, x86: refactor BPF_ST management in do_jit Alexis Lothoré (eBPF Foundation)
2026-07-08  8:00 ` [PATCH bpf-next v4 06/10] bpf, x86: emit KASAN checks into x86 JITed programs Alexis Lothoré (eBPF Foundation)
2026-07-08  8:16   ` sashiko-bot
2026-07-08 14:29     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 07/10] bpf, x86: enable KASAN for JITed programs on x86 Alexis Lothoré (eBPF Foundation)
2026-07-08  8:19   ` sashiko-bot
2026-07-08 14:33     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 08/10] selftests/bpf: add helper to check whether eBPF KASAN is active Alexis Lothoré (eBPF Foundation)
2026-07-08  8:00 ` [PATCH bpf-next v4 09/10] selftests/bpf: move bpf_jit_harden helper into testing_helpers Alexis Lothoré (eBPF Foundation)
2026-07-08  8:16   ` sashiko-bot
2026-07-08 14:43     ` Alexis Lothoré
2026-07-08  8:00 ` [PATCH bpf-next v4 10/10] selftests/bpf: add tests to validate KASAN on JIT programs Alexis Lothoré (eBPF Foundation)
2026-07-08  8:28   ` sashiko-bot
2026-07-08 14:47     ` Alexis Lothoré [this message]

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=DJT9T3MEILYQ.2KNU0Q7RKM3SW@bootlin.com \
    --to=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