[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] x86/entry/64: Remove %ebx handling from error_entry/exit


  • To: David Woodhouse <dwmw2@xxxxxxxxxxxxx>, stable@xxxxxxxxxxxxxxx, "Durand Wesolowski, Jimmy" <jdw@xxxxxxxxx>
  • From: Sarah Newman <srn@xxxxxxxxx>
  • Date: Fri, 10 Aug 2018 00:23:45 -0700
  • Autocrypt: addr=srn@xxxxxxxxx; prefer-encrypt=mutual; keydata= xsDNBFefnQQBDACet9GO9NJA4Fd9SM+pNWgqVYDxVSKUpzQ9RK6/5cfZdys4U6U+VqME5WNi GTP/1G+ho22RprxzlewIoO+fCpCeYM+ccbx0tx5pLxJICTDZ/vG6RGHsEgjrt+7d1MGAsw6f 8xIHDGqZ10kXrH79NiOLzjdFa4TCczGd+bWBJAOzSQ0x3+i6CeXA9nhYD+lvGwMzxMBDea1B iiyGndekQTKE7V2YEjRakbclGED7QPrGQYkOOOtjAo3arqN8AKa/BnaUYGz0sGJ7CGjObfi8 iz4Sab26nbPXqW1k2JGeG/LaIIlBfn0eqFacW/k5DiaXruOd6/Khz8YMzu9VzZVlhcq9QoFQ they4BAB8kE47OWyV42w1ZbNs168i5EEjIa6QC37ayp1PHtPH18QpsdWJPd3IImGA0dQpm9f gA/CYOx5SrCzhGr58UldviZ+c5j8v/+oo9UtH91yf2qJsapehbmvIhwRW/OnJn4CysAlbqcJ 4mr4aKjydfsnkEZkUz2Ehn0AEQEAAc0cU2FyYWggTmV3bWFuIDxzcm5AcHJnbXIuY29tPsLA /QQTAQgAJwIbAwULCQgHAwUVCgkICwUWAgMBAAIeAQIXgAUCV6JnrwUJCWjMIQAKCRANAk7W zO1EmRJsC/4zyHRyU+5QA98frZgT/JXtsWYRRJNbrxqa0h7yLle+YECrcHsgAngjVlkM/Z1q QPzF+2M2fLJCzFfagNZyUdKhPuUHT6epNzFPoSM0doxlVA1ZgT0lqZ8O2rMd9ILzbxPNZBwr pbnB3Sv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VsQTnocw/3bDd/qN8eNjGyS7t7j2qzvSwQUsdzLzlrMFmIpPninBp8HKg+uTE/wlr /ycjiNCHqPU+6XhNQdAYggptcZadh8++lp/162zFhxM0qglBVrPA491iHmqzymy9/03Xszoh DbdcLN2UEswliLrf0BqrPal2Mhp4CkSz9SIf1gKvtaamhSufgW6Y+RFazUipQTObNcRBMMO4 ds0OwDec5IUFVGgmpRC+d4BobmeHH6/91Y6h8G9w3XTzJdmskKT3uqkxNSKkcCIgnsWlJvLw QQTcLVzjSlbCLXTt2VHTaQggaJbFlqrP88jZDlb38GpfoP3bmc7649g4TTg0Et8vD5u9Re+Y 6Yflo+eKd4520SYBi3yOCJ1osmSWnkaxjsEGyg==
  • Cc: Juergen Gross <jgross@xxxxxxxx>, Brian Gerst <brgerst@xxxxxxxxx>, x86@xxxxxxxxxx, Dominik Brodowski <linux@xxxxxxxxxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Andy Lutomirski <luto@xxxxxxxxxx>, "H. Peter Anvin" <hpa@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
  • Delivery-date: Fri, 10 Aug 2018 07:24:01 +0000
  • Dkim-filter: OpenDKIM Filter v2.11.0 mail.xen.prgmr.com 0493D28C017
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Openpgp: preference=signencrypt

On 08/09/2018 05:41 AM, David Woodhouse wrote:
> On Wed, 2018-08-08 at 10:35 -0700, Sarah Newman wrote:
>> commit b3681dd548d06deb2e1573890829dff4b15abf46 upstream.
>>
>> This version applies to v4.9.
> 
> I think you can kill the 'xorl %ebx,%ebx' from error_entry too but yes,
> this does want to go to 4.9 and earlier because the 'Fixes:' tag is a
> bit of a lie — the problem existed before that, at least in theory.

The commit 2140a9942 "x86/entry/64: Relax pvops stub clobber
specifications" was what removed the "movl %ebx, %eax" line later on
originally, but it was the commit 3ac6d8c787b8 that removed the
'xorl %ebx,%ebx'. So these weren't matched.

I don't know if it's a concern, but if someone had gone to the effort of
backporting the original commit 3ac6d8c787b83, adding the removal of
'xorl %ebx,%ebx' to this patch would create merge conflicts.
For that reason and given the line is harmless, should it be left in?

> 
>> 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@xxxxxxxxx>
>> Cc: Borislav Petkov <bp@xxxxxxxxx>
>> Cc: Dominik Brodowski <linux@xxxxxxxxxxxxxxxxxxxx>
>> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
>> Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
>> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>> Cc: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
>> Cc: Juergen Gross <jgross@xxxxxxxx>
>> Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
>> Cc: x86@xxxxxxxxxx
>> Cc: stable@xxxxxxxxxxxxxxx
>> Cc: Andy Lutomirski <luto@xxxxxxxxxx>
>> 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@xxxxxxxxxx>
>> Signed-off-by: Andy Lutomirski <luto@xxxxxxxxxx>
>> Signed-off-by: Sarah Newman <srn@xxxxxxxxx>
>> ---
>>  arch/x86/entry/entry_64.S | 19 ++++---------------
>>  1 file changed, 4 insertions(+), 15 deletions(-)
>>
>> diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
>> index d58d8dc..0dab47a 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
>> @@ -1087,7 +1086,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 +1117,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)
>>  
>>
>>
>> _______________________________________________
>> Xen-devel mailing list
>> Xen-devel@xxxxxxxxxxxxxxxxxxxx
>> https://lists.xenproject.org/mailman/listinfo/xen-devel


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.