Received: by 10.223.185.116 with SMTP id b49csp1023892wrg; Wed, 21 Feb 2018 10:45:03 -0800 (PST) X-Google-Smtp-Source: AH8x227ofmWxkZWsUx9eDHw5xNdNkTdf703Z8FD3BffKj1ZU7i8OoZsnSVqgN38uk/H8Z6EEYldB X-Received: by 2002:a17:902:8ec7:: with SMTP id x7-v6mr3955100plo.330.1519238703324; Wed, 21 Feb 2018 10:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519238703; cv=none; d=google.com; s=arc-20160816; b=xKW9si9jcmH/OKt68R/DfMGcW0ybtQpPOaZMi/6KNbjYKQpjEK1DhmV3Itpb8JBoQM Cu1g/KHc2+94aL4gxahCUMkpm6z309B1yMIE2tdnS4pZgVRkCdygQDSs30durMBvPQZd T0V1OojAP4gHw7Cg2rI951eMhrf+I0sJN+uPcZ50yM4MV1EyayFP3ZaQjKqGw++RpAqJ fZqiQ7Hul6baFapTpiF/j8KC7/hBewdE5kYqRaATxVEm9AiocYntMm0WzCACC2KzcMd4 Htlf536PWocxAQSytB9BTmT39lIh6fQRSGB8I8XNIUNtvpkKCRxOuxDhXn6bgJVvv+Gf wZKQ== 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=DbSwcU1EDgrYraAKeULX0sFIJMCXUBAD2MNMfJXpu70=; b=Usc4b/b/jVvn7gykxp57tDnb5rrc7QrV8gz1IVT2ZIVfOoRECl+aWb2pEtbIeDSmaF b6tx+LofVBpoojzhDTuYk3AU7l4Gx/AixMs94rvetR+Oq/yI1CkkKjP0GrG9vEKYdcL6 +L9ZweDHijk6NWZaBSKFQgeXNfrbJs8VIBHElCTOgmA/sZwACdKqZNYBFNSGdmCZpgEk ODBp0ZDiTSIpE3plh4p8GmTcgvoBTipR4q4T+xOQzpm309W+O2KRODSJJF+FpbmFhKOc KPacjXGig9r0MwdbId3/GYkiZJ/0KEINlyxfvmfBbp3LwhyQAVT5rgy10NxB4kInbaEJ 1KLQ== 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 j185si13764pfc.44.2018.02.21.10.44.49; Wed, 21 Feb 2018 10:45:03 -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 S936919AbeBUNfM (ORCPT + 99 others); Wed, 21 Feb 2018 08:35:12 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42964 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965421AbeBUNJ0 (ORCPT ); Wed, 21 Feb 2018 08:09:26 -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 CFCF71060; Wed, 21 Feb 2018 13:09:25 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Williams , Andy Lutomirski , Borislav Petkov , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Josh Poimboeuf , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.15 058/163] x86/entry/64: Clear registers for exceptions/interrupts, to reduce speculation attack surface Date: Wed, 21 Feb 2018 13:48:07 +0100 Message-Id: <20180221124533.671163678@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit 3ac6d8c787b835b997eb23e43e09aa0895ef7d58 upstream. Clear the 'extra' registers on entering the 64-bit kernel for exceptions and interrupts. The common registers are not cleared since they are likely clobbered well before they can be exploited in a speculative execution attack. Originally-From: 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: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/151787989146.7847.15749181712358213254.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/calling.h | 19 +++++++++++++++++++ arch/x86/entry/entry_64.S | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) --- a/arch/x86/entry/calling.h +++ b/arch/x86/entry/calling.h @@ -147,6 +147,25 @@ For 32-bit we have the following convent UNWIND_HINT_REGS offset=\offset .endm + /* + * Sanitize registers of values that a speculation attack + * might otherwise want to exploit. The lower registers are + * likely clobbered well before they could be put to use in + * a speculative execution gadget: + */ + .macro CLEAR_REGS_NOSPEC + xorl %ebp, %ebp + xorl %ebx, %ebx + xorq %r8, %r8 + xorq %r9, %r9 + xorq %r10, %r10 + xorq %r11, %r11 + xorq %r12, %r12 + xorq %r13, %r13 + xorq %r14, %r14 + xorq %r15, %r15 + .endm + .macro POP_EXTRA_REGS popq %r15 popq %r14 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -575,6 +575,7 @@ END(irq_entries_start) ALLOC_PT_GPREGS_ON_STACK SAVE_C_REGS SAVE_EXTRA_REGS + CLEAR_REGS_NOSPEC ENCODE_FRAME_POINTER testb $3, CS(%rsp) @@ -1133,6 +1134,7 @@ ENTRY(xen_failsafe_callback) ALLOC_PT_GPREGS_ON_STACK SAVE_C_REGS SAVE_EXTRA_REGS + CLEAR_REGS_NOSPEC ENCODE_FRAME_POINTER jmp error_exit END(xen_failsafe_callback) @@ -1178,6 +1180,7 @@ ENTRY(paranoid_entry) cld SAVE_C_REGS 8 SAVE_EXTRA_REGS 8 + CLEAR_REGS_NOSPEC ENCODE_FRAME_POINTER 8 movl $1, %ebx movl $MSR_GS_BASE, %ecx @@ -1230,8 +1233,8 @@ ENTRY(error_entry) cld SAVE_C_REGS 8 SAVE_EXTRA_REGS 8 + CLEAR_REGS_NOSPEC ENCODE_FRAME_POINTER 8 - xorl %ebx, %ebx testb $3, CS+8(%rsp) jz .Lerror_kernelspace @@ -1428,6 +1431,7 @@ ENTRY(nmi) pushq %r14 /* pt_regs->r14 */ pushq %r15 /* pt_regs->r15 */ UNWIND_HINT_REGS + CLEAR_REGS_NOSPEC ENCODE_FRAME_POINTER /*