* [PATCH v2] x86/entry/64: Remove %ebx handling from error_entry/exit
@ 2018-08-17 4:19 Sarah Newman
2018-08-22 1:42 ` Andy Lutomirski
0 siblings, 1 reply; 3+ messages in thread
From: Sarah Newman @ 2018-08-17 4:19 UTC (permalink / raw)
To: stable, Andy Lutomirski, David Woodhouse
Cc: Sarah Newman, Brian Gerst, Borislav Petkov, Dominik Brodowski,
Ingo Molnar, H. Peter Anvin, Thomas Gleixner, Boris Ostrovsky,
Juergen Gross, xen-devel, x86
commit b3681dd548d06deb2e1573890829dff4b15abf46 upstream.
This version applies to v4.9.
>From Andy Lutomirski, original author:
error_entry and error_exit communicate the user vs kernel status of
the frame using %ebx. This is unnecessary -- the information is in
regs->cs. Just use regs->cs.
This makes error_entry simpler and makes error_exit more robust.
It also fixes a nasty bug. Before all the Spectre nonsense, The
xen_failsafe_callback entry point returned like this:
ALLOC_PT_GPREGS_ON_STACK
SAVE_C_REGS
SAVE_EXTRA_REGS
ENCODE_FRAME_POINTER
jmp error_exit
And it did not go through error_entry. This was bogus: RBX
contained garbage, and error_exit expected a flag in RBX.
Fortunately, it generally contained *nonzero* garbage, so the
correct code path was used. As part of the Spectre fixes, code was
added to clear RBX to mitigate certain speculation attacks. Now,
depending on kernel configuration, RBX got zeroed and, when running
some Wine workloads, the kernel crashes. This was introduced by:
commit 3ac6d8c787b8 ("x86/entry/64: Clear registers for
exceptions/interrupts, to reduce speculation attack surface")
With this patch applied, RBX is no longer needed as a flag, and the
problem goes away.
I suspect that malicious userspace could use this bug to crash the
kernel even without the offending patch applied, though.
[Historical note: I wrote this patch as a cleanup before I was aware
of the bug it fixed.]
[Note to stable maintainers: this should probably get applied to all
kernels.]
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: xen-devel@lists.xenproject.org
Cc: x86@kernel.org
Cc: stable@vger.kernel.org
Cc: Andy Lutomirski <luto@kernel.org>
Fixes: 3ac6d8c787b8 ("x86/entry/64: Clear registers for exceptions/interrupts, to reduce speculation attack surface")
Reported-and-tested-by: "M. Vefa Bicakci" <m.v.b@runbox.com>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Sarah Newman <srn@prgmr.com>
---
arch/x86/entry/entry_64.S | 20 ++++----------------
1 file changed, 4 insertions(+), 16 deletions(-)
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index d58d8dc..76c1d85e 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -774,7 +774,7 @@ ENTRY(\sym)
call \do_sym
- jmp error_exit /* %ebx: no swapgs flag */
+ jmp error_exit
.endif
END(\sym)
.endm
@@ -1043,7 +1043,6 @@ END(paranoid_exit)
/*
* Save all registers in pt_regs, and switch gs if needed.
- * Return: EBX=0: came from user mode; EBX=1: otherwise
*/
ENTRY(error_entry)
cld
@@ -1056,7 +1055,6 @@ ENTRY(error_entry)
* the kernel CR3 here.
*/
SWITCH_KERNEL_CR3
- xorl %ebx, %ebx
testb $3, CS+8(%rsp)
jz .Lerror_kernelspace
@@ -1087,7 +1085,6 @@ ENTRY(error_entry)
* for these here too.
*/
.Lerror_kernelspace:
- incl %ebx
leaq native_irq_return_iret(%rip), %rcx
cmpq %rcx, RIP+8(%rsp)
je .Lerror_bad_iret
@@ -1119,28 +1116,19 @@ ENTRY(error_entry)
/*
* Pretend that the exception came from user mode: set up pt_regs
- * as if we faulted immediately after IRET and clear EBX so that
- * error_exit knows that we will be returning to user mode.
+ * as if we faulted immediately after IRET.
*/
mov %rsp, %rdi
call fixup_bad_iret
mov %rax, %rsp
- decl %ebx
jmp .Lerror_entry_from_usermode_after_swapgs
END(error_entry)
-
-/*
- * On entry, EBX is a "return to kernel mode" flag:
- * 1: already in kernel mode, don't need SWAPGS
- * 0: user gsbase is loaded, we need SWAPGS and standard preparation for return to usermode
- */
ENTRY(error_exit)
- movl %ebx, %eax
DISABLE_INTERRUPTS(CLBR_NONE)
TRACE_IRQS_OFF
- testl %eax, %eax
- jnz retint_kernel
+ testb $3, CS(%rsp)
+ jz retint_kernel
jmp retint_user
END(error_exit)
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] x86/entry/64: Remove %ebx handling from error_entry/exit
2018-08-17 4:19 [PATCH v2] x86/entry/64: Remove %ebx handling from error_entry/exit Sarah Newman
@ 2018-08-22 1:42 ` Andy Lutomirski
2018-08-22 7:19 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Andy Lutomirski @ 2018-08-22 1:42 UTC (permalink / raw)
To: Sarah Newman
Cc: stable, Andy Lutomirski, David Woodhouse, Brian Gerst,
Borislav Petkov, Dominik Brodowski, Ingo Molnar, H. Peter Anvin,
Thomas Gleixner, Boris Ostrovsky, Juergen Gross, xen-devel,
X86 ML
On Thu, Aug 16, 2018 at 9:19 PM, Sarah Newman <srn@prgmr.com> wrote:
> commit b3681dd548d06deb2e1573890829dff4b15abf46 upstream.
>
> This version applies to v4.9.
...
Looks okay to me.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] x86/entry/64: Remove %ebx handling from error_entry/exit
2018-08-22 1:42 ` Andy Lutomirski
@ 2018-08-22 7:19 ` Greg KH
0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2018-08-22 7:19 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Sarah Newman, stable, David Woodhouse, Brian Gerst,
Borislav Petkov, Dominik Brodowski, Ingo Molnar, H. Peter Anvin,
Thomas Gleixner, Boris Ostrovsky, Juergen Gross, xen-devel,
X86 ML
On Tue, Aug 21, 2018 at 06:42:56PM -0700, Andy Lutomirski wrote:
> On Thu, Aug 16, 2018 at 9:19 PM, Sarah Newman <srn@prgmr.com> wrote:
> > commit b3681dd548d06deb2e1573890829dff4b15abf46 upstream.
> >
> > This version applies to v4.9.
>
> ...
>
> Looks okay to me.
Thanks for the review, and Sarah, thanks for the backport. Now queued
up.
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-08-22 10:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-17 4:19 [PATCH v2] x86/entry/64: Remove %ebx handling from error_entry/exit Sarah Newman
2018-08-22 1:42 ` Andy Lutomirski
2018-08-22 7:19 ` Greg KH
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).