Received: by 10.223.185.116 with SMTP id b49csp719237wrg; Wed, 21 Feb 2018 05:56:03 -0800 (PST) X-Google-Smtp-Source: AH8x224kkAAfXqdiNqdofvPM3VqruV68Fn0ED0WH8R21FGSdeXsicHyEZz9W9MncqFZzkqlH70bq X-Received: by 2002:a17:902:5609:: with SMTP id h9-v6mr3235165pli.302.1519221363101; Wed, 21 Feb 2018 05:56:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519221363; cv=none; d=google.com; s=arc-20160816; b=qa37WJKaeldVd3a7MNL3doeuidHEJE4ByKzb5voLNDDBYrewbjvxxT7P6Q5JY5I1aD rFySDw0dIrW7qoUHOiyufBBL1YH/BKc0uMZX0fYgQKp1/YqugOowZUt9hw64Z/OTSf93 5F6EBgDxkoOMYQaneqC5kZoy3GHmy+SY8G61bhsoKpHmULqnbesziaWoD2jydBAbH027 kx/U0YVsGTyV3/Uv8J5PuCvBr+sl9zPXvZTDda2l3LOybaN3QRyIVhGCpS9+xHe9x3dz 6uyvEDDh0VV8DrJNU1eSAL7pKSwuyBlgqwVYs3fdjFk/ojBunqjWAfOYiE/iYw3YGAPz AoFA== 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=C2EWzshnXRDh+0r6Yp/QsPMUacAeOJot/o2Qnc/S3n4=; b=IHFAFawLBl2+n+gJ81FJjr33kYjWxq8gBtZWJfiUUIi/hVGm+cZ6zDtlFxaAzaY1d7 jNojI5Eqi0gCHNShnWsV27uslw0C+1Q0q0yJaSxpNn1s6BXvna+aiYR2AUWxwyTT/cPB qxPT5WALkxgzRsg/UFPtdxxbLnGvMRgfexRyd8UzaBHo2vTWtmoxnlHwHuS6ktFLgIAW /9uhYgurDDmzC2jkgEJ+NHNy5qgxpb6YzLTqvAw2dIK/Mnke9jJsSVid9ocyTuf6XQHP raKRLCICVlCLJdDz7n8dE+pamRcsP5oCULDhULFf7JeArvHczt9KbN0+IVeHGACLcRTc lXcw== 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 a89-v6si5833682pla.611.2018.02.21.05.55.48; Wed, 21 Feb 2018 05:56: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 S937095AbeBUNm2 (ORCPT + 99 others); Wed, 21 Feb 2018 08:42:28 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:41542 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965122AbeBUNHU (ORCPT ); Wed, 21 Feb 2018 08:07:20 -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 6458DFCA; Wed, 21 Feb 2018 13:07:19 +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.15 040/163] x86/entry/64: Clear extra registers beyond syscall arguments, to reduce speculation attack surface Date: Wed, 21 Feb 2018 13:47:49 +0100 Message-Id: <20180221124532.559314707@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 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 @@ -235,13 +235,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