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 v5 08/10] selftests/bpf: add helpers for KASAN in JIT testing
Date: Thu, 09 Jul 2026 11:35:35 +0000	[thread overview]
Message-ID: <20260709113536.47FC21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709-kasan-v5-8-1c64af8e4e1e@bootlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly added get_kasan_multi_shot_enabled() helper is highly unreliable due to its reliance on the broken cmdline_contains() helper, which reads uninitialized stack memory and performs incorrect prefix matching.
--

--- Patch [8]: [PATCH bpf-next v5 08/10] selftests/bpf: add helpers for KASAN in JIT testing ---
commit 89c5dbabce02201a3bf78105cd83cff83602d41f
Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>

selftests/bpf: add helpers for KASAN in JIT testing

Add two simple helpers to allow checking whether KASAN for eBPF tests
should be executed.

> diff --git a/tools/testing/selftests/bpf/unpriv_helpers.c b/tools/testing/selftests/bpf/unpriv_helpers.c
> index f997d7ec8fd08..95be839378837 100644
> --- a/tools/testing/selftests/bpf/unpriv_helpers.c
> +++ b/tools/testing/selftests/bpf/unpriv_helpers.c

[ ... ]

> @@ -142,3 +142,13 @@ bool get_unpriv_disabled(void)
>  	}
>  	return mitigations_off;
>  }
> +
> +bool get_kasan_jit_enabled(void)
> +{
> +	return config_contains("CONFIG_BPF_JIT_KASAN=y") == 1;
> +}
> +
> +bool get_kasan_multi_shot_enabled(void)
> +{
> +	return cmdline_contains("kasan_multi_shot");
> +}

[Severity: Medium]
Can this return false positives due to the parsing logic in
cmdline_contains()?

Looking at cmdline_contains(), the buffer isn't correctly null-terminated
after reading:

    if (read(fd, cmdline, sizeof(cmdline) - 1) < 0) {
        perror("read /proc/cmdline");
        goto out;
    }

    cmdline[sizeof(cmdline) - 1] = '\0';

This leaves uninitialized stack memory between the read bytes and the end of
the array, which gets tokenized by strtok().

Additionally, the token matching logic uses strlen(c) instead of the pattern
length:

    for (c = strtok(cmdline, " \n"); c; c = strtok(NULL, " \n")) {
        if (strncmp(c, pat, strlen(c)))
            continue;

Because strncmp() checks only the length of the token, any kernel parameter
that happens to be a prefix of "kasan_multi_shot" (such as "k" or "kasan")
would incorrectly return true.

Could cmdline_contains() be updated to null-terminate at the read length and
use strcmp() for exact matching to avoid non-deterministic test behavior?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260709-kasan-v5-0-1c64af8e4e1e@bootlin.com?part=8

  reply	other threads:[~2026-07-09 11:35 UTC|newest]

Thread overview: 21+ 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-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-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-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-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-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-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 [this message]
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-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-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é

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=20260709113536.47FC21F000E9@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