linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv2 13/14] arm64: add on_accessible_stack()
Date: Tue, 15 Aug 2017 13:50:48 +0100	[thread overview]
Message-ID: <1502801449-29246-14-git-send-email-mark.rutland@arm.com> (raw)
In-Reply-To: <1502801449-29246-1-git-send-email-mark.rutland@arm.com>

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>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/include/asm/stacktrace.h | 16 ++++++++++++++++
 arch/arm64/kernel/stacktrace.c      |  7 +------
 arch/arm64/kernel/traps.c           |  3 +--
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h
index 4c68d8a..92ddb6d 100644
--- a/arch/arm64/include/asm/stacktrace.h
+++ b/arch/arm64/include/asm/stacktrace.h
@@ -57,4 +57,20 @@ static inline bool on_task_stack(struct task_struct *tsk, unsigned long sp)
 	return (low <= sp && sp < high);
 }
 
+/*
+ * We can only safely access per-cpu stacks from current in a non-preemptible
+ * context.
+ */
+static inline bool on_accessible_stack(struct task_struct *tsk, unsigned long sp)
+{
+	if (on_task_stack(tsk, sp))
+		return true;
+	if (tsk != current || preemptible())
+		return false;
+	if (on_irq_stack(sp))
+		return true;
+
+	return false;
+}
+
 #endif	/* __ASM_STACKTRACE_H */
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 35588ca..3144584 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -50,12 +50,7 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame)
 	if (!tsk)
 		tsk = current;
 
-	/*
-	 * Switching between stacks is valid when tracing current and in
-	 * non-preemptible context.
-	 */
-	if (!(tsk == current && !preemptible() && on_irq_stack(fp)) &&
-	    !on_task_stack(tsk, fp))
+	if (!on_accessible_stack(tsk, fp))
 		return -EINVAL;
 
 	frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index 9633773..d01c598 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -193,8 +193,7 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
 		if (in_entry_text(frame.pc)) {
 			stack = frame.fp - offsetof(struct pt_regs, stackframe);
 
-			if (on_task_stack(tsk, stack) ||
-			    (tsk == current && !preemptible() && on_irq_stack(stack)))
+			if (on_accessible_stack(tsk, stack))
 				dump_mem("", "Exception stack", stack,
 					 stack + sizeof(struct pt_regs));
 		}
-- 
1.9.1

  parent reply	other threads:[~2017-08-15 12:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 12:50 [PATCHv2 00/14] arm64: VMAP_STACK support Mark Rutland
2017-08-15 12:50 ` [PATCHv2 01/14] arm64: remove __die()'s stack dump Mark Rutland
2017-08-15 12:50 ` [PATCHv2 02/14] fork: allow arch-override of VMAP stack alignment Mark Rutland
2017-08-15 16:09   ` Andy Lutomirski
2017-08-15 16:30     ` Mark Rutland
2017-08-15 16:33       ` Andy Lutomirski
2017-08-15 16:39         ` Mark Rutland
2017-08-15 17:02           ` Catalin Marinas
2017-08-15 12:50 ` [PATCHv2 03/14] arm64: kernel: remove {THREAD,IRQ_STACK}_START_SP Mark Rutland
2017-08-15 12:50 ` [PATCHv2 04/14] arm64: factor out PAGE_* and CONT_* definitions Mark Rutland
2017-08-15 12:50 ` [PATCHv2 05/14] arm64: clean up THREAD_* definitions Mark Rutland
2017-08-15 12:50 ` [PATCHv2 06/14] arm64: clean up irq stack definitions Mark Rutland
2017-08-15 12:50 ` [PATCHv2 07/14] arm64: move SEGMENT_ALIGN to <asm/memory.h> Mark Rutland
2017-08-15 12:50 ` [PATCHv2 08/14] efi/arm64: add EFI_KIMG_ALIGN Mark Rutland
2017-08-15 12:50 ` [PATCHv2 09/14] arm64: factor out entry stack manipulation Mark Rutland
2017-08-15 12:50 ` [PATCHv2 10/14] arm64: assembler: allow adr_this_cpu to use the stack pointer Mark Rutland
2017-08-15 12:50 ` [PATCHv2 11/14] arm64: use an irq " Mark Rutland
2017-08-15 12:50 ` [PATCHv2 12/14] arm64: add basic VMAP_STACK support Mark Rutland
2017-08-15 12:50 ` Mark Rutland [this message]
2017-08-15 12:50 ` [PATCHv2 14/14] arm64: add VMAP_STACK overflow detection Mark Rutland
2017-08-15 14:00 ` [PATCHv2 00/14] arm64: VMAP_STACK support Will Deacon
2017-08-15 17:18 ` Laura Abbott
2017-08-15 17:39   ` Mark Rutland
2017-08-15 17:44     ` Catalin Marinas
2017-08-15 18:15       ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1502801449-29246-14-git-send-email-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).