The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] riscv: stacktrace: Fix NULL task pointer in  ftrace_graph_ret_addr()
@ 2026-07-08  1:50 zhang.anmeng
  2026-12-01  2:09 ` [PATCH] riscv: stacktrace: Fix NULL task pointer in^J ftrace_graph_ret_addr() Paul Walmsley
  0 siblings, 1 reply; 2+ messages in thread
From: zhang.anmeng @ 2026-07-08  1:50 UTC (permalink / raw)
  To: pjw, palmer, aou
  Cc: linux-riscv, linux-kernel, alex, qirui.001, hu.shengming, gao.rui,
	luo.haiyang, zhang.run, zhangchunyan

From: Anmeng Zhang <zhang.anmeng@zte.com.cn>

When dump_backtrace() is called with a NULL task argument, and the
call stack contains functions that are being traced,
walk_stackframe() eventually calls ftrace_graph_ret_addr() with the
NULL task pointer, which results in a NULL pointer dereference when
accessing task->curr_ret_stack.

Fix this by assigning the task pointer to the current task in
walk_stackframe() when it is NULL, keeping the behavior consistent
with other architectures.

Fixes: ecbf894165a2 ("riscv: Fix ftrace_graph_ret_addr() to use the correct task pointer")
Reviewed-by: Shengming Hu <hu.shengming@zte.com.cn>
Reviewed-by: Rui Gao <gao.rui@zte.com.cn>
Reviewed-by: Luo Haiyang <luo.haiyang@zte.com.cn>
Reviewed-by: Run Zhang <zhang.run@zte.com.cn>
Signed-off-by: Anmeng Zhang <zhang.anmeng@zte.com.cn>
---
 arch/riscv/kernel/stacktrace.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
index c7555447149b..d19545efb5dd 100644
--- a/arch/riscv/kernel/stacktrace.c
+++ b/arch/riscv/kernel/stacktrace.c
@@ -52,11 +52,14 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
 	int graph_idx = 0;
 	int level = 0;

+	if (task == NULL)
+		task = current;
+
 	if (regs) {
 		fp = frame_pointer(regs);
 		sp = user_stack_pointer(regs);
 		pc = instruction_pointer(regs);
-	} else if (task == NULL || task == current) {
+	} else if (task == current) {
 		fp = (unsigned long)__builtin_frame_address(0);
 		sp = current_stack_pointer;
 		pc = (unsigned long)walk_stackframe;
-- 
2.43.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-01  2:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08  1:50 [PATCH] riscv: stacktrace: Fix NULL task pointer in ftrace_graph_ret_addr() zhang.anmeng
2026-12-01  2:09 ` [PATCH] riscv: stacktrace: Fix NULL task pointer in^J ftrace_graph_ret_addr() Paul Walmsley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox