From: Clark Williams <clrkwllms@kernel.org>
To: linux-rt-users@vger.kernel.org
Cc: Clark Williams <williams@redhat.com>,
Claude <noreply@anthropic.com>,
Clark Williams <clrkwllms@kernel.org>,
wander@redhat.com, debarbos@redhat.com, marco.chiappero@suse.com,
chris.friesen@windriver.com, luochunsheng@ustc.edu
Subject: [PATCH 03/12] sched_debug: Fix double-free crash in fill_waiting_task()
Date: Thu, 16 Oct 2025 21:24:35 -0500 [thread overview]
Message-ID: <20251017022444.118802-3-clrkwllms@kernel.org> (raw)
In-Reply-To: <20251017022444.118802-1-clrkwllms@kernel.org>
From: Clark Williams <williams@redhat.com>
Fix a critical double-free bug that occurs when fill_waiting_task()
returns early without allocating new memory for cpu_info->starving.
Root cause:
In sched_debug_parse(), the code saves old_tasks = cpu_info->starving,
then calls fill_waiting_task(). If fill_waiting_task() returns early
(nr_entries <= 0 or cpu_info == NULL), it doesn't allocate new memory
or update cpu_info->starving. This leaves cpu_info->starving pointing
to the old memory. When the code later frees old_tasks, it's freeing
the same memory that cpu_info->starving still points to. On the next
iteration, old_tasks again points to this already-freed memory, causing
a double-free crash.
Example crash sequence:
1. First parse: cpu_info->starving = malloc(memory A)
2. Second parse: old_tasks = memory A
nr_entries = 5, so cpu_info->starving = malloc(memory B)
free(old_tasks) → frees memory A
3. Third parse: old_tasks = memory B
nr_entries = 0, so fill_waiting_task() returns early
cpu_info->starving still points to memory B
free(old_tasks) → frees memory B
4. Fourth parse: old_tasks = memory B (already freed!)
nr_entries > 0, so cpu_info->starving = malloc(memory C)
free(old_tasks) → DOUBLE FREE of memory B → CRASH
The fix:
Explicitly set cpu_info->starving = NULL in fill_waiting_task() when
returning early without allocation. This ensures that cpu_info->starving
never points to freed memory, preventing the double-free.
Impact:
- Prevents random crashes in sched_debug backend
- Enables stable operation with varying numbers of runnable tasks
- Critical for test suite reliability
Testing:
- Verified no crash with: sudo stalld -f -v -N -b sched_debug -t 3 -c 0 -l
- Runs stably for extended periods without crashes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Clark Williams <clrkwllms@kernel.org>
Signed-off-by: Clark Williams <williams@redhat.com>
---
src/sched_debug.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/sched_debug.c b/src/sched_debug.c
index 04a12ef2a7c2..102a4e02d57d 100644
--- a/src/sched_debug.c
+++ b/src/sched_debug.c
@@ -525,6 +525,7 @@ static int fill_waiting_task(char *buffer, struct cpu_info *cpu_info)
if (cpu_info == NULL) {
warn("NULL cpu_info pointer!\n");
+ cpu_info->starving = NULL;
return 0;
}
@@ -533,8 +534,10 @@ static int fill_waiting_task(char *buffer, struct cpu_info *cpu_info)
else
nr_entries = cpu_info->nr_running;
- if (nr_entries <= 0)
+ if (nr_entries <= 0) {
+ cpu_info->starving = NULL;
return 0;
+ }
cpu_info->starving = malloc(sizeof(struct task_info) * nr_entries);
if (cpu_info->starving == NULL) {
--
2.51.0
next prev parent reply other threads:[~2025-10-17 2:24 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-17 2:24 [PATCH 01/12] sched_debug: Unify parsing methods for task_info Clark Williams
2025-10-17 2:24 ` [PATCH 02/12] sched_debug: Fix runqueue task parsing logic and state filtering Clark Williams
2025-10-21 15:58 ` Wander Lairson Costa
2025-10-17 2:24 ` Clark Williams [this message]
2025-10-21 16:01 ` [PATCH 03/12] sched_debug: Fix double-free crash in fill_waiting_task() Wander Lairson Costa
2025-10-17 2:24 ` [PATCH 04/12] stalld.c: remove noisy idle report and added report to should_skip_idle_cpus() Clark Williams
2025-10-21 16:03 ` Wander Lairson Costa
2025-10-17 2:24 ` [PATCH 05/12] stalld.c: initialize cpu_info->idle_time to be -1 Clark Williams
2025-10-21 16:15 ` Wander Lairson Costa
2025-10-17 2:24 ` [PATCH 06/12] stalld.c: get rid of misleading print about DL-Server Clark Williams
2025-10-21 16:16 ` Wander Lairson Costa
2025-10-17 2:24 ` [PATCH 07/12] stalld.c: Add starvation logging in single-threaded log-only mode Clark Williams
2025-10-21 16:27 ` Wander Lairson Costa
2025-10-17 2:24 ` [PATCH 08/12] stalld: Add -N/--no_idle_detect flag to disable idle detection Clark Williams
2025-10-21 16:33 ` Wander Lairson Costa
2025-10-17 2:24 ` [PATCH 09/12] stalld: Add defensive checks in print_boosted_info Clark Williams
2025-10-21 17:36 ` Wander Lairson Costa
2025-10-17 2:24 ` [PATCH 10/12] Makefile: Add support for legacy kernels Clark Williams
2025-10-17 12:50 ` Derek Barbosa
2025-10-21 17:43 ` Wander Lairson Costa
2025-10-17 2:24 ` [PATCH 11/12] scripts: fix run-local if bashism Clark Williams
2025-10-21 17:45 ` Wander Lairson Costa
2025-10-17 2:24 ` [PATCH 12/12] Fix segfault in adaptive/aggressive modes Clark Williams
2025-10-21 17:45 ` Wander Lairson Costa
2025-10-21 15:54 ` [PATCH 01/12] sched_debug: Unify parsing methods for task_info Wander Lairson Costa
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=20251017022444.118802-3-clrkwllms@kernel.org \
--to=clrkwllms@kernel.org \
--cc=chris.friesen@windriver.com \
--cc=debarbos@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=luochunsheng@ustc.edu \
--cc=marco.chiappero@suse.com \
--cc=noreply@anthropic.com \
--cc=wander@redhat.com \
--cc=williams@redhat.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