Skip to content

Commit 5854e4d

Browse files
Li HuafeiRussell King (Oracle)
authored andcommitted
ARM: 9233/1: stacktrace: Skip frame pointer boundary check for call_with_stack()
When using the frame pointer unwinder, it was found that the stack trace output of stack_trace_save() is incomplete if the stack contains call_with_stack(): [0x7f00002c] dump_stack_task+0x2c/0x90 [hrtimer] [0x7f0000a0] hrtimer_hander+0x10/0x18 [hrtimer] [0x801a67f0] __hrtimer_run_queues+0x1b0/0x3b4 [0x801a7350] hrtimer_run_queues+0xc4/0xd8 [0x801a597c] update_process_times+0x3c/0x88 [0x801b5a98] tick_periodic+0x50/0xd8 [0x801b5bf4] tick_handle_periodic+0x24/0x84 [0x8010ffc4] twd_handler+0x38/0x48 [0x8017d220] handle_percpu_devid_irq+0xa8/0x244 [0x80176e9c] generic_handle_domain_irq+0x2c/0x3c [0x8052e3a8] gic_handle_irq+0x7c/0x90 [0x808ab15c] generic_handle_arch_irq+0x60/0x80 [0x8051191c] call_with_stack+0x1c/0x20 For the frame pointer unwinder, unwind_frame() checks stackframe::fp by stackframe::sp. Since call_with_stack() switches the SP from one stack to another, stackframe::fp and stackframe: :sp will point to different stacks, so we can no longer check stackframe::fp by stackframe::sp. Skip checking stackframe::fp at this point to avoid this problem. Signed-off-by: Li Huafei <[email protected]> Reviewed-by: Linus Waleij <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent 09cffec commit 5854e4d

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

arch/arm/kernel/stacktrace.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <asm/stacktrace.h>
1010
#include <asm/traps.h>
1111

12+
#include "reboot.h"
13+
1214
#if defined(CONFIG_FRAME_POINTER) && !defined(CONFIG_ARM_UNWIND)
1315
/*
1416
* Unwind the current stack frame and store the new register values in the
@@ -39,29 +41,53 @@
3941
* Note that with framepointer enabled, even the leaf functions have the same
4042
* prologue and epilogue, therefore we can ignore the LR value in this case.
4143
*/
42-
int notrace unwind_frame(struct stackframe *frame)
44+
45+
extern unsigned long call_with_stack_end;
46+
47+
static int frame_pointer_check(struct stackframe *frame)
4348
{
4449
unsigned long high, low;
4550
unsigned long fp = frame->fp;
51+
unsigned long pc = frame->pc;
52+
53+
/*
54+
* call_with_stack() is the only place we allow SP to jump from one
55+
* stack to another, with FP and SP pointing to different stacks,
56+
* skipping the FP boundary check at this point.
57+
*/
58+
if (pc >= (unsigned long)&call_with_stack &&
59+
pc < (unsigned long)&call_with_stack_end)
60+
return 0;
4661

4762
/* only go to a higher address on the stack */
4863
low = frame->sp;
4964
high = ALIGN(low, THREAD_SIZE);
5065

51-
#ifdef CONFIG_CC_IS_CLANG
5266
/* check current frame pointer is within bounds */
67+
#ifdef CONFIG_CC_IS_CLANG
5368
if (fp < low + 4 || fp > high - 4)
5469
return -EINVAL;
55-
56-
frame->sp = frame->fp;
57-
frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
58-
frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 4));
5970
#else
60-
/* check current frame pointer is within bounds */
6171
if (fp < low + 12 || fp > high - 4)
6272
return -EINVAL;
73+
#endif
74+
75+
return 0;
76+
}
77+
78+
int notrace unwind_frame(struct stackframe *frame)
79+
{
80+
unsigned long fp = frame->fp;
81+
82+
if (frame_pointer_check(frame))
83+
return -EINVAL;
6384

6485
/* restore the registers from the stack frame */
86+
#ifdef CONFIG_CC_IS_CLANG
87+
frame->sp = frame->fp;
88+
frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
89+
frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 4));
90+
#else
6591
frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp - 12));
6692
frame->sp = READ_ONCE_NOCHECK(*(unsigned long *)(fp - 8));
6793
frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp - 4));

arch/arm/lib/call_with_stack.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ UNWIND( .setfp fpreg, sp )
4646
pop {fpreg, pc}
4747
UNWIND( .fnend )
4848
#endif
49+
.globl call_with_stack_end
50+
call_with_stack_end:
4951
ENDPROC(call_with_stack)

0 commit comments

Comments
 (0)