Skip to contentSkip to conversation

stacktrace: check whether task has a stack before saving it

PATCH New Ronald Wahl 1 participant 1 message Dec 12, 2023 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 stacktrace: check whether task has a stack before saving it

From: Ronald Wahl <[email protected]>

I encountered a crash on ARM32 when trying to dump the stack of some zombie process. This is caused by a missing check whether the task actually has a valid stack. This commit adds this check.

Commit 214d8ca6ee85 ("stacktrace: Provide common infrastructure") introduced this check for platforms that define CONFIG_ARCH_STACKWALK but ARM32 is not one of them.

Cc Thomas Gleixner <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Peter Zijlstra <[email protected]>

---
V2: - added missing put_task_stack(task) to avoid memory leak

 kernel/stacktrace.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/stacktrace.c +4 -0
index 9ed5ce989415..0bb67bd633c6 100644
@@ -298,7 +298,11 @@ unsigned int stack_trace_save_tsk(struct task_struct *task,
 		.skip	= skipnr + (current == task),
 	};
 
+	if (!try_get_task_stack(task))
+		return 0;
+
 	save_stack_trace_tsk(task, &trace);
+	put_task_stack(task);
 	return trace.nr_entries;
 }
 

--
2.43.0