linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: fix race in for_each_frame
@ 2019-11-12 13:29 Mark-PK Tsai
  2019-11-12 14:14 ` 黄吕强 (Lvqiang Huang)
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mark-PK Tsai @ 2019-11-12 13:29 UTC (permalink / raw)
  To: linux
  Cc: matthias.bgg, kstewart, allison, lvqiang.huang, gregkh, info,
	tglx, linux-arm-kernel, linux-kernel, linux-mediatek, yj.chiang,
	mark-pk.tsai, alix.wu, mike-sl.lin, eddy.lin, phil.chang

The sv_pc, which is saved in the stack, may be an invalid address
if the target thread is running on another processor in the meantime.
It will cause kernel crash at `ldr r2, [sv_pc, #-4]`.

Check if sv_pc is valid before use it like unwind_frame in
arch/arm/kernel/unwind.c.

Signed-off-by: Mike-SL Lin <mike-sl.lin@mediatek.com>
Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
---
 arch/arm/lib/backtrace.S | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/lib/backtrace.S b/arch/arm/lib/backtrace.S
index 582925238d65..84f06381bbfb 100644
--- a/arch/arm/lib/backtrace.S
+++ b/arch/arm/lib/backtrace.S
@@ -64,6 +64,11 @@ for_each_frame:	tst	frame, mask		@ Check for address exceptions
 		sub	sv_pc, sv_pc, offset	@ Correct PC for prefetching
 		bic	sv_pc, sv_pc, mask	@ mask PC/LR for the mode
 
+		mov	r0, sv_pc
+		bl	kernel_text_address	@ check if sv_pc is valid
+		cmp	r0, #0			@ if sv_pc is not kernel text
+		beq	1006f			@ address, abort backtrace
+
 1003:		ldr	r2, [sv_pc, #-4]	@ if stmfd sp!, {args} exists,
 		ldr	r3, .Ldsi+4		@ adjust saved 'pc' back one
 		teq	r3, r2, lsr #11		@ instruction
-- 
2.18.0

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

end of thread, other threads:[~2019-11-13  3:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12 13:29 [PATCH] ARM: fix race in for_each_frame Mark-PK Tsai
2019-11-12 14:14 ` 黄吕强 (Lvqiang Huang)
2019-11-12 14:35 ` 黄吕强 (Lvqiang Huang)
2019-11-13  3:25   ` Mark-PK Tsai
2019-11-12 15:20 ` Mark-PK Tsai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).