Received: by 10.223.185.116 with SMTP id b49csp711681wrg; Wed, 21 Feb 2018 05:48:30 -0800 (PST) X-Google-Smtp-Source: AH8x227HdViGnMAB5HV8vraTpxWFDX1XJ7cm0JKXKUvt8VHyijtyZIES/F6JN+ZwTvg7TPKb5Sk6 X-Received: by 2002:a17:902:b403:: with SMTP id x3-v6mr3208153plr.359.1519220910048; Wed, 21 Feb 2018 05:48:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519220910; cv=none; d=google.com; s=arc-20160816; b=JSp090GFn41BnNUzt1ZldxC5pGE4OyFvhZpTGN3KLTzb/Lo0FdCU4vDDKTV3WeFkf7 /KkJXrWowutiBue07y2crIK3k8Y/J6cgT3elQ1itK3B1CPvt3iDa/gK5yXQWLuebVuVR 5miMUbcGZhv872hmScethrzgtW8x3hnRrviGkjaOPPyjgNbEZaCPrl7TkvsAUjpP4+hC IOFDhL2WAkpY0qiXDUDU0y5azFgFDWmY6pcfA2sUxukjE4ZosO/3xNjoU6321l6j7HsB BR/rlXGrJ4a486szeW06AdI0op7A0vfgga6L+ifWQ+OoC4OwzbAGWjLnzWo/USrSsJoz /ZRw== 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=h+rh9CtVQJhNQgA4EZMv1G6FmaI1rCqNbJlzrISOHMY=; b=VukCfqY3DTsHqDOKZUV7O01GOC1LcTs8sTThGWVRJ4T4o17I4Opjg98m0cO/NYaNk5 dw9zjq6lkFYdjNNXb9ujbuUEtsKHJIhYPxjOOw6/XOpHjIjB9fTt0c1znmt+J/63Nrlc ihQY8T7GDU5295Vj0LusLAZyp5g+M9ca7WWtK/2biHI45ppOu4J/JAX9b0Y7eZdacF25 XdH1ZKw9h5yzPJCpHfpSFLPethibTRbY35SIHV1kPpa+gWzPftjSYB84zQI3oYFnYutH ngLIMqHtqM3BH0cnGmGHAxPYnu6TSIQaHtj0YPsb3dyUUjqV2aYqzYVSscILEojEOXE5 W6fw== 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 t132si1170930pgc.238.2018.02.21.05.48.15; Wed, 21 Feb 2018 05:48:29 -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 S965503AbeBUNKA (ORCPT + 99 others); Wed, 21 Feb 2018 08:10:00 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:43248 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965490AbeBUNJ5 (ORCPT ); Wed, 21 Feb 2018 08:09:57 -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 034EA11A7; Wed, 21 Feb 2018 13:09:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Dominik Brodowski , Andy Lutomirski , Borislav Petkov , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Josh Poimboeuf , Peter Zijlstra , Thomas Gleixner , dan.j.williams@intel.com, Ingo Molnar Subject: [PATCH 4.15 062/163] x86/entry/64: Introduce the PUSH_AND_CLEAN_REGS macro Date: Wed, 21 Feb 2018 13:48:11 +0100 Message-Id: <20180221124533.890417390@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: Dominik Brodowski commit 3f01daecd545e818098d84fd1ad43e19a508d705 upstream. Those instances where ALLOC_PT_GPREGS_ON_STACK is called just before SAVE_AND_CLEAR_REGS can trivially be replaced by PUSH_AND_CLEAN_REGS. This macro uses PUSH instead of MOV and should therefore be faster, at least on newer CPUs. Suggested-by: Linus Torvalds Signed-off-by: Dominik Brodowski 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 Cc: dan.j.williams@intel.com Link: http://lkml.kernel.org/r/20180211104949.12992-5-linux@dominikbrodowski.net Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/calling.h | 36 ++++++++++++++++++++++++++++++++++++ arch/x86/entry/entry_64.S | 6 ++---- 2 files changed, 38 insertions(+), 4 deletions(-) --- a/arch/x86/entry/calling.h +++ b/arch/x86/entry/calling.h @@ -137,6 +137,42 @@ For 32-bit we have the following convent UNWIND_HINT_REGS offset=\offset .endm + .macro PUSH_AND_CLEAR_REGS + /* + * Push registers and 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. + * Interleave XOR with PUSH for better uop scheduling: + */ + pushq %rdi /* pt_regs->di */ + pushq %rsi /* pt_regs->si */ + pushq %rdx /* pt_regs->dx */ + pushq %rcx /* pt_regs->cx */ + pushq %rax /* pt_regs->ax */ + pushq %r8 /* pt_regs->r8 */ + xorq %r8, %r8 /* nospec r8 */ + pushq %r9 /* pt_regs->r9 */ + xorq %r9, %r9 /* nospec r9 */ + pushq %r10 /* pt_regs->r10 */ + 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 + .endm + .macro POP_REGS pop_rdi=1 skip_r11rcx=0 popq %r15 popq %r14 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -564,8 +564,7 @@ END(irq_entries_start) call switch_to_thread_stack 1: - ALLOC_PT_GPREGS_ON_STACK - SAVE_AND_CLEAR_REGS + PUSH_AND_CLEAR_REGS ENCODE_FRAME_POINTER testb $3, CS(%rsp) @@ -1112,8 +1111,7 @@ ENTRY(xen_failsafe_callback) addq $0x30, %rsp UNWIND_HINT_IRET_REGS pushq $-1 /* orig_ax = -1 => not a system call */ - ALLOC_PT_GPREGS_ON_STACK - SAVE_AND_CLEAR_REGS + PUSH_AND_CLEAR_REGS ENCODE_FRAME_POINTER jmp error_exit END(xen_failsafe_callback)