From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Lars Wendler <wendler.lars@web.de>,
Laura Abbott <labbott@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Betkov <bp@alien8.de>, Juergen Gross <jgross@suse.com>,
Andy Lutomirski <luto@kernel.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>
Subject: [PATCH 4.14 07/14] x86/pti: Switch to kernel CR3 at early in entry_SYSCALL_compat()
Date: Thu, 4 Jan 2018 13:09:24 +0100 [thread overview]
Message-ID: <20180104120918.024405382@linuxfoundation.org> (raw)
In-Reply-To: <20180104120917.043667757@linuxfoundation.org>
4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <tglx@linutronix.de>
commit d7732ba55c4b6a2da339bb12589c515830cfac2c upstream.
The preparation for PTI which added CR3 switching to the entry code
misplaced the CR3 switch in entry_SYSCALL_compat().
With PTI enabled the entry code tries to access a per cpu variable after
switching to kernel GS. This fails because that variable is not mapped to
user space. This results in a double fault and in the worst case a kernel
crash.
Move the switch ahead of the access and clobber RSP which has been saved
already.
Fixes: 8a09317b895f ("x86/mm/pti: Prepare the x86/entry assembly code for entry/exit CR3 switching")
Reported-by: Lars Wendler <wendler.lars@web.de>
Reported-by: Laura Abbott <labbott@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@kernel.org>,
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
Cc: Peter Zijlstra <peterz@infradead.org>,
Cc: Greg KH <gregkh@linuxfoundation.org>, ,
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Cc: Juergen Gross <jgross@suse.com>
Link: https://lkml.kernel.org/r/alpine.DEB.2.20.1801031949200.1957@nanos
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
arch/x86/entry/entry_64_compat.S | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -190,8 +190,13 @@ ENTRY(entry_SYSCALL_compat)
/* Interrupts are off on entry. */
swapgs
- /* Stash user ESP and switch to the kernel stack. */
+ /* Stash user ESP */
movl %esp, %r8d
+
+ /* Use %rsp as scratch reg. User ESP is stashed in r8 */
+ SWITCH_TO_KERNEL_CR3 scratch_reg=%rsp
+
+ /* Switch to the kernel stack */
movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
/* Construct struct pt_regs on stack */
@@ -220,12 +225,6 @@ GLOBAL(entry_SYSCALL_compat_after_hwfram
pushq $0 /* pt_regs->r15 = 0 */
/*
- * We just saved %rdi so it is safe to clobber. It is not
- * preserved during the C calls inside TRACE_IRQS_OFF anyway.
- */
- SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi
-
- /*
* User mode is traced as though IRQs are on, and SYSENTER
* turned them off.
*/
next prev parent reply other threads:[~2018-01-04 12:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-04 12:09 [PATCH 4.14 00/14] 4.14.12-stable review Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 01/14] exec: Weaken dumpability for secureexec Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 02/14] capabilities: fix buffer overread on very short xattr Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 03/14] x86/cpu, x86/pti: Do not enable PTI on AMD processors Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 04/14] x86/pti: Make sure the user/kernel PTEs match Greg Kroah-Hartman
2018-01-04 12:09 ` Greg Kroah-Hartman [this message]
2018-01-04 12:09 ` [PATCH 4.14 08/14] x86/process: Define cpu_tss_rw in same section as declaration Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 09/14] Revert "xfrm: Fix stack-out-of-bounds read in xfrm_state_find." Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 10/14] rtc: m41t80: m41t80_sqw_set_rate should return 0 on success Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 11/14] rtc: m41t80: fix m41t80_sqw_round_rate return value Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 12/14] rtc: m41t80: avoid i2c read in m41t80_sqw_recalc_rate Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 13/14] rtc: m41t80: avoid i2c read in m41t80_sqw_is_prepared Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 14/14] rtc: m41t80: remove unneeded checks from m41t80_sqw_set_rate Greg Kroah-Hartman
2018-01-04 18:52 ` [PATCH 4.14 00/14] 4.14.12-stable review Guenter Roeck
2018-01-05 12:13 ` Greg Kroah-Hartman
2018-01-04 19:46 ` Dan Rue
2018-01-05 8:04 ` Greg Kroah-Hartman
2018-01-04 22:03 ` Shuah Khan
[not found] ` <5a4e68a8.e4a0df0a.b9e2d.7b39@mx.google.com>
[not found] ` <7h4lo12mfk.fsf@baylibre.com>
2018-01-05 7:55 ` Greg Kroah-Hartman
2018-01-08 14:58 ` Guillaume Tucker
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=20180104120918.024405382@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=boris.ostrovsky@oracle.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=jgross@suse.com \
--cc=labbott@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=wendler.lars@web.de \
/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).