linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Mark Brown <broonie@kernel.org>, Miroslav Benes <mbenes@suse.cz>,
	linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 3/3] arm64: stacktrace: Implement reliable stacktrace
Date: Mon, 12 Oct 2020 18:26:05 +0100	[thread overview]
Message-ID: <20201012172605.10715-4-broonie@kernel.org> (raw)
In-Reply-To: <20201012172605.10715-1-broonie@kernel.org>

Live patching has a consistency model which requires that the
architecture provide a reliable stack trace interface which specifically
indicates that the stack has been fully walked and that it is reliable
and consistent. This is done by providing arch_stack_walk_reliable(), a
variant of arch_stack_walk() which should verify that the stack has
these properties and return an error if not.

The arm64 unwinder is already reasonably thorough in verifying the stack
as it walks it and reports errors but we additionally check that
we do not see any kretprobe trampolines on the stack. Since the unwinder
is able to resolve function graph tracer probes transparently we do not
reject those.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/Kconfig             |  1 +
 arch/arm64/kernel/stacktrace.c | 42 ++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index d1ba52e4b976..026f69515a86 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -174,6 +174,7 @@ config ARM64
 	select HAVE_FUNCTION_ARG_ACCESS_API
 	select HAVE_FUTEX_CMPXCHG if FUTEX
 	select MMU_GATHER_RCU_TABLE_FREE
+	select HAVE_RELIABLE_STACKTRACE
 	select HAVE_RSEQ
 	select HAVE_STACKPROTECTOR
 	select HAVE_SYSCALL_TRACEPOINTS
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index ad20981dfda4..795b2c14481d 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -14,6 +14,7 @@
 #include <linux/stacktrace.h>
 
 #include <asm/irq.h>
+#include <asm/kprobes.h>
 #include <asm/pointer_auth.h>
 #include <asm/stack_pointer.h>
 #include <asm/stacktrace.h>
@@ -212,4 +213,45 @@ void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
 	walk_stackframe(task, &frame, consume_entry, cookie);
 }
 
+/*
+ * This function returns an error if it detects any unreliable features of the
+ * stack.  Otherwise it guarantees that the stack trace is reliable.
+ *
+ * If the task is not 'current', the caller *must* ensure the task is inactive.
+ */
+int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry,
+			     void *cookie, struct task_struct *task)
+{
+	struct stackframe frame;
+
+	if (task == current)
+		start_backtrace(&frame,
+				(unsigned long)__builtin_frame_address(0),
+				(unsigned long)arch_stack_walk_reliable);
+	else
+		start_backtrace(&frame, thread_saved_fp(task),
+				thread_saved_pc(task));
+
+	while (1) {
+		int ret;
+
+#ifdef CONFIG_KPROBES
+		/*
+		 * Mark stacktraces with kretprobed functions on them
+		 * as unreliable.
+		 */
+		if (frame.pc == (unsigned long)kretprobe_trampoline)
+			return -EINVAL;
+#endif
+
+		if (!consume_entry(cookie, frame.pc))
+			return -EINVAL;
+		ret = unwind_frame(task, &frame);
+		if (ret == -ENOENT)
+			return 0;
+		if (ret < 0)
+			return ret;
+	}
+}
+
 #endif
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2020-10-12 17:32 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12 17:26 [RFC PATCH 0/3] arm64: Implement reliable stack trace Mark Brown
2020-10-12 17:26 ` [RFC PATCH 1/3] arm64: remove EL0 exception frame record Mark Brown
2020-10-12 17:26 ` [RFC PATCH 2/3] arm64: stacktrace: Report when we reach the end of the stack Mark Brown
2020-10-13 11:07   ` Mark Rutland
2020-10-12 17:26 ` Mark Brown [this message]
2020-10-13 10:42   ` [RFC PATCH 3/3] arm64: stacktrace: Implement reliable stacktrace Mark Brown
2020-10-13 11:42   ` Mark Rutland
2020-10-13 16:12     ` Mark Brown
2020-10-15 13:33   ` Miroslav Benes
2020-10-15 15:57     ` Mark Brown
2020-10-16 10:13       ` Miroslav Benes
2020-10-16 12:30         ` Mark Brown
2020-10-15 13:39 ` [RFC PATCH 0/3] arm64: Implement reliable stack trace Miroslav Benes
2020-10-15 14:16   ` Mark Rutland
2020-10-15 15:49     ` Mark Brown
2020-10-15 21:29       ` Josh Poimboeuf
2020-10-16 11:14         ` Mark Rutland
2020-10-20 10:03           ` Mark Rutland
2020-10-20 15:58             ` Josh Poimboeuf
2020-10-16 12:15         ` Mark Brown
2020-10-19 23:41           ` Josh Poimboeuf
2020-10-20 15:39             ` Mark Brown
2020-10-20 16:28               ` Josh Poimboeuf
2021-01-27 14:02 ` Madhavan T. Venkataraman
2021-01-27 16:40   ` Mark Rutland
2021-01-27 17:11     ` Mark Brown
2021-01-27 17:24   ` Madhavan T. Venkataraman
2021-01-27 19:54 ` Madhavan T. Venkataraman
2021-01-28 14:22   ` Mark Brown
2021-01-28 15:26     ` Josh Poimboeuf
2021-01-29 21:39       ` Madhavan T. Venkataraman
2021-02-01  3:20         ` Madhavan T. Venkataraman
2021-02-01 14:39         ` Mark Brown
2021-01-30  4:38       ` Madhavan T. Venkataraman
2021-02-01 15:21       ` Madhavan T. Venkataraman
2021-02-01 15:46         ` Madhavan T. Venkataraman
2021-02-01 16:02         ` Mark Rutland
2021-02-01 16:22           ` Mark Brown
2021-02-01 21:40             ` Madhavan T. Venkataraman
2021-02-01 21:38           ` Madhavan T. Venkataraman
2021-02-01 23:00             ` Josh Poimboeuf
2021-02-02  2:29               ` Madhavan T. Venkataraman
2021-02-02  3:36                 ` Josh Poimboeuf
2021-02-02 10:05             ` Mark Rutland
2021-02-02 13:33               ` Madhavan T. Venkataraman
2021-02-02 13:35               ` Madhavan T. Venkataraman
2021-02-02 23:32               ` Madhavan T. Venkataraman
2021-02-03 16:53                 ` Mark Rutland
2021-02-03 19:03                   ` Madhavan T. Venkataraman
2021-02-05  2:36                     ` Madhavan T. Venkataraman
2021-02-01 21:59     ` Madhavan T. Venkataraman
2021-02-02 13:36       ` Mark Brown

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=20201012172605.10715-4-broonie@kernel.org \
    --to=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=mbenes@suse.cz \
    --cc=will@kernel.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).