Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp28396imm; Fri, 21 Sep 2018 17:23:40 -0700 (PDT) X-Google-Smtp-Source: ACcGV63CX8jb3s6mwbyQtZJa76F+7glbFdjmX3ym1ActmzFLaBPQrXbXbc1yr5NhwH80TLBAZUKQ X-Received: by 2002:a63:115f:: with SMTP id 31-v6mr116774pgr.53.1537575820349; Fri, 21 Sep 2018 17:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537575820; cv=none; d=google.com; s=arc-20160816; b=HhKXA1L2bAamNU4s8Fa6dv03vYFXAVFc/Y6+e38lRUM7ZdN687RQojE+hbApSJwTLp r/hzag3jJFhk9yt+3E5VGQ9pMLuuHc1O9APi+L5tZRrnspQixOIzZKwyuiDvvex2xfVo s8k0qUSjHcTLM/tCbnWYHU3ZA6QSapllH5NutAo21kaJAWjnHm3uFMfhwh2Xsupo1JC1 a/25465issKcR53WpyJZdL73wfWsdMGEYVNegsgXu38NdYDCB3LAI1pkwZPjIOw5RRRw +j7AFidlYi3rh8jMVKEtQQCOB7kmy+KC/4DQGKHw01VHLLGH0Fj0T5m79F6K2eJgjF++ O7LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=yJkjKcRCORFJs1STneZByyEwUfiyiK+gL7UsQ6Nv37o=; b=Dvk0h8KtQgfuf7gKHOeOX3bxZ/N4d8rclrSIYsXlNMFvEb4EeZiVLHgU1PEWhH/Ga8 zRZiM8Wf2xhhLCklXbUwmhsNx5sVwDaBihrarLzBHWv5Uh/Q8RefOFLyPjJiMqsr6lMW BkxCLc2iDEkYmiSHBN1sqXHV/mLe+VSkw1sdmoRlJH74Ia4JamVZqrp4oJyot55IoDJe qsL9M/HRXRf9Yz51ZdzZFXlWe0sAh47F+LYmt1EuFA5r1QdRHOI/A+b549O2h6AXPp6/ DmJWzFxAVBcf3QlRIBzLzXK8Yh3IBqUj5U7lZdFLdnF1OSObQlWJnfcMxZaiXcjS13he Ol+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 29-v6si26414584pgz.215.2018.09.21.17.23.25; Fri, 21 Sep 2018 17:23:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391966AbeIVGMn (ORCPT + 99 others); Sat, 22 Sep 2018 02:12:43 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44277 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391974AbeIVGKt (ORCPT ); Sat, 22 Sep 2018 02:10:49 -0400 Received: from [2a02:8011:400e:2:cbab:f00:c93f:614] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1g3Vdy-0008BS-53; Sat, 22 Sep 2018 01:19:30 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1g3Vdo-0000sq-Eo; Sat, 22 Sep 2018 01:19:20 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "H. Peter Anvin" , "Dave Hansen" , "Greg KH" , "Ingo Molnar" , "Andy Lutomirski" , "Brian Gerst" , "Josh Poimboeuf" , "Juergen Gross" , "Peter Zijlstra" , "Denys Vlasenko" , "Dominik Brodowski" , "Boris Ostrovsky" , xen-devel@lists.xenproject.org, "Thomas Gleixner" , "Linus Torvalds" , "Borislav Petkov" Date: Sat, 22 Sep 2018 01:15:42 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 39/63] x86/entry/64: Remove %ebx handling from error_entry/exit In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:cbab:f00:c93f:614 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.58-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Andy Lutomirski commit b3681dd548d06deb2e1573890829dff4b15abf46 upstream. 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. If you're nervous about that, a more conservative fix to add xorl %ebx,%ebx; incl %ebx before the jump to error_exit should also fix the problem. ] Reported-and-tested-by: M. Vefa Bicakci Signed-off-by: Andy Lutomirski Cc: Boris Ostrovsky Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: Denys Vlasenko Cc: Dominik Brodowski Cc: Greg KH Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: xen-devel@lists.xenproject.org Fixes: 3ac6d8c787b8 ("x86/entry/64: Clear registers for exceptions/interrupts, to reduce speculation attack surface") Link: http://lkml.kernel.org/r/b5010a090d3586b2d6e06c7ad3ec5542d1241c45.1532282627.git.luto@kernel.org Signed-off-by: Ingo Molnar [bwh: Backported to 3.16: - error_exit moved EBX to EAX before testing it, so delete both instructions - error_exit does RESTORE_REST earlier, so adjust the offset to saved CS accordingly - Drop inapplicable comment changes - Adjust filename, context] Signed-off-by: Ben Hutchings --- --- a/arch/x86/kernel/entry_64.S +++ b/arch/x86/kernel/entry_64.S @@ -1135,7 +1135,7 @@ ENTRY(\sym) .if \paranoid jmp paranoid_exit /* %ebx: no swapgs flag */ .else - jmp error_exit /* %ebx: no swapgs flag */ + jmp error_exit .endif CFI_ENDPROC @@ -1411,7 +1411,6 @@ END(paranoid_exit) /* * Exception entry point. This expects an error code/orig_rax on the stack. - * returns in "no swapgs flag" in %ebx. */ ENTRY(error_entry) XCPT_FRAME @@ -1440,7 +1439,6 @@ ENTRY(error_entry) * the kernel CR3 here. */ SWITCH_KERNEL_CR3 - xorl %ebx,%ebx testl $3,CS+8(%rsp) je error_kernelspace error_swapgs: @@ -1456,7 +1454,6 @@ error_sti: * for these here too. */ error_kernelspace: - incl %ebx leaq native_irq_return_iret(%rip),%rcx cmpq %rcx,RIP+8(%rsp) je error_bad_iret @@ -1477,22 +1474,18 @@ error_bad_iret: mov %rsp,%rdi call fixup_bad_iret mov %rax,%rsp - decl %ebx /* Return to usergs */ jmp error_sti CFI_ENDPROC END(error_entry) - -/* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */ ENTRY(error_exit) DEFAULT_FRAME - movl %ebx,%eax RESTORE_REST DISABLE_INTERRUPTS(CLBR_NONE) TRACE_IRQS_OFF GET_THREAD_INFO(%rcx) - testl %eax,%eax - jne retint_kernel + testb $3, CS-ARGOFFSET(%rsp) + jz retint_kernel LOCKDEP_SYS_EXIT_IRQ movl TI_flags(%rcx),%edx movl $_TIF_WORK_MASK,%edi