Skip to content

Commit 1296444

Browse files
committed
arm64: add on_accessible_stack()
Both unwind_frame() and dump_backtrace() try to check whether a stack address is sane to access, with very similar logic. Both will need updating in order to handle overflow stacks. Factor out this logic into a helper, so that we can avoid further duplication when we add overflow stacks. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Reviewed-by: Will Deacon <will.deacon@arm.com> Tested-by: Laura Abbott <labbott@redhat.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: James Morse <james.morse@arm.com>
1 parent e306786 commit 1296444

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎arch/arm64/include/asm/stacktrace.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,20 @@ static inline bool on_task_stack(struct task_struct *tsk, unsigned long sp)
5757
return (low <= sp && sp < high);
5858
}
5959

60+
/*
61+
* We can only safely access per-cpu stacks from current in a non-preemptible
62+
* context.
63+
*/
64+
static inline bool on_accessible_stack(struct task_struct *tsk, unsigned long sp)
65+
{
66+
if (on_task_stack(tsk, sp))
67+
return true;
68+
if (tsk != current || preemptible())
69+
return false;
70+
if (on_irq_stack(sp))
71+
return true;
72+
73+
return false;
74+
}
75+
6076
#endif /* __ASM_STACKTRACE_H */

‎arch/arm64/kernel/stacktrace.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame)
5050
if (!tsk)
5151
tsk = current;
5252

53-
/*
54-
* Switching between stacks is valid when tracing current and in
55-
* non-preemptible context.
56-
*/
57-
if (!(tsk == current && !preemptible() && on_irq_stack(fp)) &&
58-
!on_task_stack(tsk, fp))
53+
if (!on_accessible_stack(tsk, fp))
5954
return -EINVAL;
6055

6156
frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));

‎arch/arm64/kernel/traps.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
193193
if (in_entry_text(frame.pc)) {
194194
stack = frame.fp - offsetof(struct pt_regs, stackframe);
195195

196-
if (on_task_stack(tsk, stack) ||
197-
(tsk == current && !preemptible() && on_irq_stack(stack)))
196+
if (on_accessible_stack(tsk, stack))
198197
dump_mem("", "Exception stack", stack,
199198
stack + sizeof(struct pt_regs));
200199
}

0 commit comments

Comments
 (0)