Blob Blame History Raw
From 1706f8b6ab50cd25e8fdabe8d50a37ce89bd60e0 Mon Sep 17 00:00:00 2001
From: Lianbo Jiang <lijiang@redhat.com>
Date: Thu, 6 Jan 2022 12:01:17 +0800
Subject: [PATCH 04/11] Fix for "bt -v" option to display the stack-end address
 correctly

The "bt -v" command prints incorrect stack-end address when the
"CONFIG_THREAD_INFO_IN_TASK=y" is enabled in kernel, the "bt -v"
command output shows that the value stored at 0xffff8dee0312c198
is 0xffffffffc076400a, however, the value stored actually at
0xffff8dee0312c198 is NULL(0x0000000000000000), the stack-end
address is incorrect.

Without the patch:
crash> bt -v
PID: 28642  TASK: ffff8dee0312c180  CPU: 0   COMMAND: "insmod"
  possible stack overflow: ffff8dee0312c198: ffffffffc076400a != STACK_END_MAGIC
                                             ^^^^^^^^^^^^^^^^

crash> rd 0xffff8dee0312c198
ffff8dee0312c198:  0000000000000000                    ........
                   ^^^^^^^^^^^^^^^^

With the patch:
crash> bt -v
PID: 28642  TASK: ffff8dee0312c180  CPU: 0   COMMAND: "insmod"
  possible stack overflow: ffff991340bc0000: ffffffffc076400a != STACK_END_MAGIC

crash> rd 0xffff991340bc0000
ffff991340bc0000:  ffffffffc076400a                    .@v.....

Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
---
 task.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/task.c b/task.c
index bb6a5da8ad33..b5ddc88e0acb 100644
--- a/task.c
+++ b/task.c
@@ -11202,7 +11202,7 @@ check_stack_overflow(void)
 {
 	int i, overflow, cpu_size, cpu, total;
 	char buf[BUFSIZE];
-	ulong magic, task, stackbase;
+	ulong magic, task, stackbase, location;
 	struct task_context *tc;
 
 	if (!tt->stack_end_magic && 
@@ -11286,9 +11286,15 @@ check_stack_end_magic:
 		if (magic != STACK_END_MAGIC) {
 			if (!overflow)
 				print_task_header(fp, tc, 0);
+
+			if (tt->flags & THREAD_INFO_IN_TASK)
+				location = task_to_stackbase(tc->task);
+			else
+				location = tc->thread_info + SIZE(thread_info);
+
 			fprintf(fp, 
 			    "  possible stack overflow: %lx: %lx != STACK_END_MAGIC\n",
-				tc->thread_info + SIZE(thread_info), magic);
+				location, magic);
 			overflow++, total++;
 		}
 
-- 
2.20.1