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 09/10] selftests/bpf: move bpf_jit_harden helper into testing_helpers
Date: Wed, 08 Jul 2026 16:43:03 +0200	[thread overview]
Message-ID: <DJT9PGET5EXB.CS5NIHIHF5B3@bootlin.com> (raw)
In-Reply-To: <20260708081638.D12501F000E9@smtp.kernel.org>

On Wed Jul 8, 2026 at 10:16 AM CEST, sashiko-bot wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The refactored `set_bpf_jit_harden` function has been moved to a common helper file and stripped of its internal `ASSERT_FAIL` calls. However, its usage in the cleanup path of `check_blindness()` was not updated to check the return value. Consequently, if restoring the sysctl fails during cleanup, the test will silently leave the system-wide `bpf_jit_harden` configuration in an altered state.
> --
>
> --- Patch [9]: [PATCH bpf-next v4 09/10] selftests/bpf: move bpf_jit_harden helper into testing_helpers ---
> commit 806a4cb4e9c458805fd71ac7ae0f57e00e8af6bc
> Author: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
>
> selftests/bpf: move bpf_jit_harden helper into testing_helpers
>
> Move set_bpf_jit_harden to testing helpers so that other selftests can
> change the hardening configuration without re-implementing a helper.
>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c b/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
>> index 0222a9a5d0761..37c405fc2b0d2 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
>> @@ -227,42 +227,6 @@ static void check_incorrect_index(void)
>>  	check_mid_insn_index();
>>  }
>>  
>> -static int set_bpf_jit_harden(char *level)
>> -{
>> -	char old_level;
>> -	int err = -1;
>> -	int fd = -1;
>> -
>> -	fd = open("/proc/sys/net/core/bpf_jit_harden", O_RDWR | O_NONBLOCK);
>> -	if (fd < 0) {
>> -		ASSERT_FAIL("open .../bpf_jit_harden returned %d (errno=%d)", fd, errno);
>> -		return -1;
>> -	}
>
> [Severity: Medium]
> Since this function's internal ASSERT_FAIL() calls were removed when moving it
> to testing_helpers.c, are we missing an error check in the cleanup path of
> check_blindness() where it restores the sysctl?
>
> tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c:check_blindness() {
>     ...
> cleanup:
>     /* restore the old one */
>     if (bpf_jit_harden != '@')
>         set_bpf_jit_harden(&bpf_jit_harden);
>     ...
> }
>
> If restoring the sysctl fails during cleanup, this will silently leave the
> system-wide bpf_jit_harden configuration in an altered state. Should the return
> value of set_bpf_jit_harden() in the cleanup path be checked and asserted?

I guess I can add an extra ASSERT_OK in the cleanup path to at least get
a log if the setting restore fails.

Alexis

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


  reply	other threads:[~2026-07-08 14:43 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é [this message]
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é

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=DJT9PGET5EXB.CS5NIHIHF5B3@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