From: sashiko-bot@kernel.org
To: "Feng Yang" <yangfeng59949@163.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v2 bpf-next 5/5] selftests/bpf: Fix potential NULL pointer dereference in strscpy call
Date: Wed, 22 Jul 2026 07:58:40 +0000 [thread overview]
Message-ID: <20260722075840.C733E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260722074748.674080-6-yangfeng59949@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Medium] The patch prevents a NULL pointer dereference in the worker thread by replacing a NULL `subtest_state->name` with an empty string, but misses other instances where a NULL `subtest_state->name` causes undefined behavior or crashes (e.g., in single-process mode and server thread IPC parsing).
--
--- Patch [5]: [PATCH v2 bpf-next 5/5] selftests/bpf: Fix potential NULL pointer dereference in strscpy call ---
commit b6c49e61911a21bc238d913cde0b42bf364476d1
Author: Feng Yang <yangfeng@kylinos.cn>
selftests/bpf: Fix potential NULL pointer dereference in strscpy call
In test__start_subtest_with_desc, if strdup fails or an empty name is passed,
the function returns early. Later, worker_main_send_subtests copies the name
via strscpy, which leads to a NULL pointer dereference.
> diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> index ea9c887201aee..ab88268db9e2e 100644
> --- a/tools/testing/selftests/bpf/test_progs.c
> +++ b/tools/testing/selftests/bpf/test_progs.c
> @@ -1882,7 +1882,8 @@ static int worker_main_send_subtests(int sock, struct test_state *state)
>
> msg.subtest_done.num = i;
>
> - strscpy(msg.subtest_done.name, subtest_state->name, MAX_SUBTEST_NAME);
> + const char *name = subtest_state->name ? : "";
> + strscpy(msg.subtest_done.name, name, MAX_SUBTEST_NAME);
[Severity: Medium]
This isn't a bug introduced by this patch, but since we are handling a NULL
subtest_state->name here, could a NULL name also cause issues in other places?
For example, in single-process mode, print_subtest_name() receives a NULL
subtest_name and passes it directly to fprintf() as a %s format argument,
triggering undefined behavior:
tools/testing/selftests/bpf/test_progs.c:print_subtest_name() {
...
fprintf(env.stdout_saved, "#%-*s %s/%s",
TEST_NUM_WIDTH, test_num_str,
test_name, subtest_name);
...
}
When JSON output is requested, dump_test_log() passes it to the JSON writer:
tools/testing/selftests/bpf/test_progs.c:dump_test_log() {
...
jsonw_string_field(w, "name", subtest_state->name);
...
}
This leads to a crash when jsonw_puts() dereferences it unconditionally:
tools/bpf/bpftool/json_writer.c:jsonw_puts() {
...
for (; *str; ++str)
...
}
Also, could a strdup() failure in dispatch_thread_send_subtests() lead to
subtest_state->name being NULL again on the server side?
tools/testing/selftests/bpf/test_progs.c:dispatch_thread_send_subtests() {
...
subtest_state->name = strdup(msg.subtest_done.name);
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260722074748.674080-1-yangfeng59949@163.com?part=5
prev parent reply other threads:[~2026-07-22 7:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 7:47 [PATCH v2 bpf-next 0/5] Fix several issues in test_progs.c Feng Yang
2026-07-22 7:47 ` [PATCH v2 bpf-next 1/5] selftests/bpf: Fix double free of subtest_state->name Feng Yang
2026-07-22 7:47 ` [PATCH v2 bpf-next 2/5] selftests/bpf: Fix missing allocation null checks in test_progs.c Feng Yang
2026-07-22 7:59 ` sashiko-bot
2026-07-22 8:45 ` bot+bpf-ci
2026-07-22 7:47 ` [PATCH v2 bpf-next 3/5] selftests/bpf: Use calloc to allocate subtest_states Feng Yang
2026-07-22 7:47 ` [PATCH v2 bpf-next 4/5] selftests/bpf: Fix memory leak on subtest_states reallocation Feng Yang
2026-07-22 7:47 ` [PATCH v2 bpf-next 5/5] selftests/bpf: Fix potential NULL pointer dereference in strscpy call Feng Yang
2026-07-22 7:58 ` sashiko-bot [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=20260722075840.C733E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yangfeng59949@163.com \
/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