public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] arm64: avoid race condition issue in dump_backtrace
@ 2018-03-22  3:06 Ji Zhang
  2018-03-22  4:57 ` Baruch Siach
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Ji Zhang @ 2018-03-22  3:06 UTC (permalink / raw)
  To: linux-arm-kernel

When we dump the backtrace of some specific task, there is a potential race
condition due to the task may be running on other cores if SMP enabled.
That is because for current implementation, if the task is not the current
task, we will get the registers used for unwind from cpu_context saved in
thread_info, which is the snapshot before context switch, but if the task
is running on other cores, the registers and the content of stack are
changed.
This may cause that we get the wrong backtrace or incomplete backtrace or
even crash the kernel.
To avoid this case, do not dump the backtrace of the tasks which are
running on other cores.
This patch cannot solve the issue completely but can shrink the window of
race condition.

Signed-off-by: Ji Zhang <ji.zhang@mediatek.com>
---
 arch/arm64/kernel/traps.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index eb2d151..95749364 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -113,6 +113,9 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 	if (tsk == current) {
 		frame.fp = (unsigned long)__builtin_frame_address(0);
 		frame.pc = (unsigned long)dump_backtrace;
+	else if (tsk->state == TASK_RUNNING) {
+		pr_notice("Do not dump other running tasks\n");
+		return;
 	} else {
 		/*
 		 * task blocked in __switch_to
-- 
1.9.1

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

end of thread, other threads:[~2018-04-20  5:43 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-22  3:06 [PATCH] arm64: avoid race condition issue in dump_backtrace Ji Zhang
2018-03-22  4:57 ` Baruch Siach
2018-03-22  5:33   ` Ji.Zhang
2018-03-22  5:59 ` Mark Rutland
2018-03-22  9:35   ` Ji.Zhang
2018-03-26 11:39     ` Mark Rutland
2018-03-28  9:33       ` Ji.Zhang
2018-03-28 10:12         ` Mark Rutland
2018-03-30  8:08           ` Ji.Zhang
2018-04-04  9:04             ` Mark Rutland
2018-04-08  7:58               ` Ji.Zhang
2018-04-09 11:26                 ` Mark Rutland
2018-04-11  6:30                   ` Ji.Zhang
2018-04-11 10:46                     ` Mark Rutland
2018-04-12  6:13                       ` Ji.Zhang
2018-04-20  5:43                         ` Ji.Zhang
2018-03-24 11:01 ` kbuild test robot

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