Commit e1a415fe authored by Max Filippov's avatar Max Filippov Committed by sanglipeng
Browse files

xtensa: fix KASAN report for show_stack

stable inclusion
from stable-v5.10.177
commit 08bfd05987df2756aaf7b2b8f014c4cdcc6bcb39
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I88YNP

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=08bfd05987df2756aaf7b2b8f014c4cdcc6bcb39



--------------------------------

commit 1d3b7a78 upstream.

show_stack dumps raw stack contents which may trigger an unnecessary
KASAN report. Fix it by copying stack contents to a temporary buffer
with __memcpy and then printing that buffer instead of passing stack
pointer directly to the print_hex_dump.

Cc: stable@vger.kernel.org
Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent 7718a1e0
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -503,7 +503,7 @@ static size_t kstack_depth_to_print = CONFIG_PRINT_STACK_DEPTH;

void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
{
	size_t len;
	size_t len, off = 0;

	if (!sp)
		sp = stack_pointer(task);
@@ -512,9 +512,17 @@ void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
		  kstack_depth_to_print * STACK_DUMP_ENTRY_SIZE);

	printk("%sStack:\n", loglvl);
	while (off < len) {
		u8 line[STACK_DUMP_LINE_SIZE];
		size_t line_len = len - off > STACK_DUMP_LINE_SIZE ?
			STACK_DUMP_LINE_SIZE : len - off;

		__memcpy(line, (u8 *)sp + off, line_len);
		print_hex_dump(loglvl, " ", DUMP_PREFIX_NONE,
			       STACK_DUMP_LINE_SIZE, STACK_DUMP_ENTRY_SIZE,
		       sp, len, false);
			       line, line_len, false);
		off += STACK_DUMP_LINE_SIZE;
	}
	show_trace(task, sp, loglvl);
}