Received: by 10.223.185.116 with SMTP id b49csp739329wrg; Wed, 21 Feb 2018 06:12:35 -0800 (PST) X-Google-Smtp-Source: AH8x225OuD5DLl7r9M6h26k9lVaUvEqzXvG9lCUBbdxdXkaCmr8+eEx33/M/0wURlVOgHNM96RUv X-Received: by 10.98.192.203 with SMTP id g72mr3493917pfk.27.1519222355501; Wed, 21 Feb 2018 06:12:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519222355; cv=none; d=google.com; s=arc-20160816; b=vxnNJm13UdkluSCeH2u2TLwnIFupJHYBpLxmJ9APkyoCp85pecmbE/qGx/+8k4EeY2 xwuN1k9cI8F/FVHTsagmUNIyypjcJvPlceu3jJ00HgBUgjugcMA28eqM6HzxfC0Fvgys vIAmmCrTz2tGVOrKcSojSwqW54QWkwJ6ZmZmA/XawJ7WVxzjgcZwAwqbsqLy2NQDUEw3 d0A+QHISY8cVChOm0pa9sOKhizeUqYDVGh4nHjDf0mju5Ctu0kHz0mAFN9YZQatd1uk8 kcAesCdo1QnPXpyx+PSA7VrzsjQv69yFHJ97jTGAlBMj/qhjpjqeUVYd2LZ2b3UtMXUo 7NRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AQE6QDGclNT60NZwm4hWDdCM6bX7XzRI6kasUakaQiQ=; b=bU32cY/8nr/QRsjTJyLRLK7bGK4s+XEw4JEhFhwRjP0HEVN2H6IJhtUrkRU6aTPBxQ b1TPsC9WKvMxXRL30mnhl6wQRNQrOtunelKrJvaauvz7iBTTrCx4WBa1PB6pLyNk4COJ FdJMKr4bzPsLbYXaTGtO+7BvBMKKeEt6+ng0pX4XD9B1vnh8extv3ZIw0lHle93q1gAm 6AvBqVdCwphtu7uxbVL7T3RC6cqkMrs2oACSr3GEBWgJULCbqyVgO6/Cax4RgdZ0SrJX /gc2H66uradMaBH1muYmHu5MYb4CyHNDIyGPK+HH4FrsWGTo7o8R8j4DuLAXrrDRljL6 HNtw== 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 h71si1399072pgc.3.2018.02.21.06.12.20; Wed, 21 Feb 2018 06:12:35 -0800 (PST) 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 S935436AbeBUNBQ (ORCPT + 99 others); Wed, 21 Feb 2018 08:01:16 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:37836 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935414AbeBUNBM (ORCPT ); Wed, 21 Feb 2018 08:01:12 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6ECC31125; Wed, 21 Feb 2018 13:00:59 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Andi Kleen , Dan Williams , Andy Lutomirski , Borislav Petkov , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Josh Poimboeuf , Peter Zijlstra , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.14 040/167] x86/entry/64: Clear extra registers beyond syscall arguments, to reduce speculation attack surface Date: Wed, 21 Feb 2018 13:47:31 +0100 Message-Id: <20180221124526.787999801@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124524.639039577@linuxfoundation.org> References: <20180221124524.639039577@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit 8e1eb3fa009aa7c0b944b3c8b26b07de0efb3200 upstream. At entry userspace may have (maliciously) populated the extra registers outside the syscall calling convention with arbitrary values that could be useful in a speculative execution (Spectre style) attack. Clear these registers to minimize the kernel's attack surface. Note, this only clears the extra registers and not the unused registers for syscalls less than 6 arguments, since those registers are likely to be clobbered well before their values could be put to use under speculation. Note, Linus found that the XOR instructions can be executed with minimized cost if interleaved with the PUSH instructions, and Ingo's analysis found that R10 and R11 should be included in the register clearing beyond the typical 'extra' syscall calling convention registers. Suggested-by: Linus Torvalds Reported-by: Andi Kleen Signed-off-by: Dan Williams Cc: Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/151787988577.7847.16733592218894189003.stgit@dwillia2-desk3.amr.corp.intel.com [ Made small improvements to the changelog and the code comments. ] Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/entry_64.S | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -231,13 +231,26 @@ GLOBAL(entry_SYSCALL_64_after_hwframe) pushq %r8 /* pt_regs->r8 */ pushq %r9 /* pt_regs->r9 */ pushq %r10 /* pt_regs->r10 */ + /* + * Clear extra registers that a speculation attack might + * otherwise want to exploit. Interleave XOR with PUSH + * for better uop scheduling: + */ + xorq %r10, %r10 /* nospec r10 */ pushq %r11 /* pt_regs->r11 */ + xorq %r11, %r11 /* nospec r11 */ pushq %rbx /* pt_regs->rbx */ + xorl %ebx, %ebx /* nospec rbx */ pushq %rbp /* pt_regs->rbp */ + xorl %ebp, %ebp /* nospec rbp */ pushq %r12 /* pt_regs->r12 */ + xorq %r12, %r12 /* nospec r12 */ pushq %r13 /* pt_regs->r13 */ + xorq %r13, %r13 /* nospec r13 */ pushq %r14 /* pt_regs->r14 */ + xorq %r14, %r14 /* nospec r14 */ pushq %r15 /* pt_regs->r15 */ + xorq %r15, %r15 /* nospec r15 */ UNWIND_HINT_REGS TRACE_IRQS_OFF