selftests/bpf: Sanitize pointer prior fclose()
Subsystems (3)
PATCH 1/1 selftests/bpf: Sanitize pointer prior fclose()
From: Björn Töpel <[email protected]>
There are scenarios where env.{sub,}test_state->stdout_saved, can be NULL, e.g. sometimes when the watchdog timeout kicks in, or if the open_memstream syscall is not available.
Avoid crashing test_progs by adding an explicit NULL check prior the fclose() call.
--- tools/testing/selftests/bpf/test_progs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/test_progs.c +4 -2
@@ -103,12 +103,14 @@ static void stdio_restore(void)pthread_mutex_lock (&stdout_lock);if (env.subtest_state) { -fclose (env.subtest_state->stdout_saved); +if (env.subtest_state->stdout_saved) +fclose (env.subtest_state->stdout_saved); env.subtest_state->stdout_saved =NULL ; stdout = env.test_state->stdout_saved; stderr = env.test_state->stdout_saved; }else { -fclose (env.test_state->stdout_saved); +if (env.test_state->stdout_saved) +fclose (env.test_state->stdout_saved); env.test_state->stdout_saved =NULL ; stdout = env.stdout_saved; stderr = env.stderr_saved;
base-commit: f3f8649585a445414521a6d5b76f41b51205086d
Signature · 1 line
2.45.2
Quoted 10 lines · Björn Töpel
From: Björn Töpel <[email protected]>
There are scenarios where env.{sub,}test_state->stdout_saved, can be NULL, e.g. sometimes when the watchdog timeout kicks in, or if the
open_memstreamsyscall is not available.Avoid crashing
test_progsby adding an explicit NULL check prior thefclose()call.Signed-off-by Björn Töpel <[email protected]>
jirka
Quoted 9 lines
--- tools/testing/selftests/bpf/test_progs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/test_progs.c +0
-0
tools/testing/selftests/bpf/test_progs.c static void stdio_restore(void) · line 108
Quoted 7 lines
tools/testing/selftests/bpf/test_progs.c +2
-1@@ -103,12 +103,14 @@ static void stdio_restore(void)pthread_mutex_lock (&stdout_lock);if (env.subtest_state) { -fclose (env.subtest_state->stdout_saved); +if (env.subtest_state->stdout_saved) +fclose (env.subtest_state->stdout_saved); env.subtest_state->stdout_saved =NULL ;
nit, setting to NULL could be inside the condition
Quoted 15 lines
tools/testing/selftests/bpf/test_progs.c +2
-1stdout = env.test_state->stdout_saved; stderr = env.test_state->stdout_saved; }else { -fclose (env.test_state->stdout_saved); +if (env.test_state->stdout_saved) +fclose (env.test_state->stdout_saved); env.test_state->stdout_saved =NULL ; stdout = env.stdout_saved; stderr = env.stderr_saved;base-commit:
f3f8649585a445414521a6d5b76f41b51205086dSignature · 1 line
2.45.2
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 10 lines · On Tue, 18 Mar 2025 09:16:47 +0100 you wrote:
From: Björn Töpel <[email protected]>
There are scenarios where env.{sub,}test_state->stdout_saved, can be NULL, e.g. sometimes when the watchdog timeout kicks in, or if the
open_memstreamsyscall is not available.Avoid crashing
test_progsby adding an explicit NULL check prior thefclose()call.[...]
Here is the summary with links:
- [bpf-next] selftests/bpf: Sanitize pointer prior fclose()
https://git.kernel.org/bpf/bpf-next/c/e16e64f9e076
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html