提交 71c41f47 编写于 作者: P Peter Zijlstra 提交者: Zheng Zengkai

x86: Fix __get_wchan() for !STACKTRACE

mainline inclusion
from mainline-v5.16-rc1
commit 5d1ceb39
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5BLBZ
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5d1ceb3969b6b2e47e2df6d17790a7c5a20fcbb4

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

Use asm/unwind.h to implement wchan, since we cannot always rely on
STACKTRACE=y.

Fixes: bc9bbb81 ("x86: Fix get_wchan() to support the ORC unwinder")
Reported-by: NStephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: NKees Cook <keescook@chromium.org>
Link: https://lkml.kernel.org/r/20211022152104.137058575@infradead.orgSigned-off-by: NLin Yujun <linyujun809@huawei.com>
Reviewed-by: NZhang Jianhua <chris.zjh@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 9d6dc2cd
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <asm/io_bitmap.h> #include <asm/io_bitmap.h>
#include <asm/proto.h> #include <asm/proto.h>
#include <asm/frame.h> #include <asm/frame.h>
#include <asm/unwind.h>
#include "process.h" #include "process.h"
...@@ -918,13 +919,23 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) ...@@ -918,13 +919,23 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
*/ */
unsigned long get_wchan(struct task_struct *p) unsigned long get_wchan(struct task_struct *p)
{ {
unsigned long entry = 0; struct unwind_state state;
unsigned long addr = 0;
if (p == current || p->state == TASK_RUNNING) if (p == current || p->state == TASK_RUNNING)
return 0; return 0;
stack_trace_save_tsk(p, &entry, 1, 0); for (unwind_start(&state, p, NULL, NULL); !unwind_done(&state);
return entry; unwind_next_frame(&state)) {
addr = unwind_get_return_address(&state);
if (!addr)
break;
if (in_sched_functions(addr))
continue;
break;
}
return addr;
} }
long do_arch_prctl_common(struct task_struct *task, int option, long do_arch_prctl_common(struct task_struct *task, int option,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册