]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0138-x86-unwinder-orc-Dont-bail-on-stack-overflow.patch
KPTI: add follow-up fixes
[pve-kernel.git] / patches / kernel / 0138-x86-unwinder-orc-Dont-bail-on-stack-overflow.patch
CommitLineData
321d628a
FG
1From bb0be747b5ee45f07f5514a214231c9061261b50 Mon Sep 17 00:00:00 2001
2From: Andy Lutomirski <luto@kernel.org>
3Date: Mon, 4 Dec 2017 15:07:08 +0100
e4cdf2a5 4Subject: [PATCH 138/241] x86/unwinder/orc: Dont bail on stack overflow
321d628a
FG
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9CVE-2017-5754
10
11If the stack overflows into a guard page and the ORC unwinder should work
12well: by construction, there can't be any meaningful data in the guard page
13because no writes to the guard page will have succeeded.
14
15But there is a bug that prevents unwinding from working correctly: if the
16starting register state has RSP pointing into a stack guard page, the ORC
17unwinder bails out immediately.
18
19Instead of bailing out immediately check whether the next page up is a
20valid check page and if so analyze that. As a result the ORC unwinder will
21start the unwind.
22
23Tested by intentionally overflowing the task stack. The result is an
24accurate call trace instead of a trace consisting purely of '?' entries.
25
26There are a few other bugs that are triggered if the unwinder encounters a
27stack overflow after the first step, but they are outside the scope of this
28fix.
29
30Signed-off-by: Andy Lutomirski <luto@kernel.org>
31Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
32Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
33Cc: Borislav Petkov <bp@alien8.de>
34Cc: Borislav Petkov <bpetkov@suse.de>
35Cc: Brian Gerst <brgerst@gmail.com>
36Cc: Dave Hansen <dave.hansen@intel.com>
37Cc: Dave Hansen <dave.hansen@linux.intel.com>
38Cc: David Laight <David.Laight@aculab.com>
39Cc: Denys Vlasenko <dvlasenk@redhat.com>
40Cc: Eduardo Valentin <eduval@amazon.com>
41Cc: Greg KH <gregkh@linuxfoundation.org>
42Cc: H. Peter Anvin <hpa@zytor.com>
43Cc: Josh Poimboeuf <jpoimboe@redhat.com>
44Cc: Juergen Gross <jgross@suse.com>
45Cc: Linus Torvalds <torvalds@linux-foundation.org>
46Cc: Peter Zijlstra <peterz@infradead.org>
47Cc: Rik van Riel <riel@redhat.com>
48Cc: Will Deacon <will.deacon@arm.com>
49Cc: aliguori@amazon.com
50Cc: daniel.gruss@iaik.tugraz.at
51Cc: hughd@google.com
52Cc: keescook@google.com
53Link: https://lkml.kernel.org/r/20171204150604.991389777@linutronix.de
54Signed-off-by: Ingo Molnar <mingo@kernel.org>
55(cherry picked from commit d3a09104018cf2ad5973dfa8a9c138ef9f5015a3)
56Signed-off-by: Andy Whitcroft <apw@canonical.com>
57Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
58(cherry picked from commit e5c3115ac69cddd384d6f7abc4a0ef030b247498)
59Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
60---
61 arch/x86/kernel/unwind_orc.c | 14 ++++++++++++--
62 1 file changed, 12 insertions(+), 2 deletions(-)
63
64diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
65index 570b70d3f604..cea85bfe93f7 100644
66--- a/arch/x86/kernel/unwind_orc.c
67+++ b/arch/x86/kernel/unwind_orc.c
68@@ -552,8 +552,18 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
69 }
70
71 if (get_stack_info((unsigned long *)state->sp, state->task,
72- &state->stack_info, &state->stack_mask))
73- return;
74+ &state->stack_info, &state->stack_mask)) {
75+ /*
76+ * We weren't on a valid stack. It's possible that
77+ * we overflowed a valid stack into a guard page.
78+ * See if the next page up is valid so that we can
79+ * generate some kind of backtrace if this happens.
80+ */
81+ void *next_page = (void *)PAGE_ALIGN((unsigned long)state->sp);
82+ if (get_stack_info(next_page, state->task, &state->stack_info,
83+ &state->stack_mask))
84+ return;
85+ }
86
87 /*
88 * The caller can provide the address of the first frame directly
89--
902.14.2
91