Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5048362ybi; Sat, 20 Jul 2019 11:43:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOKfV+AgTJL9e7QdyfbpA/3nu9VMSQYtaOM8mVDm3rFx//yhDdDV3g4/MsWhJtXw3Fu75n X-Received: by 2002:a17:902:e287:: with SMTP id cf7mr63697755plb.32.1563648214971; Sat, 20 Jul 2019 11:43:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563648214; cv=none; d=google.com; s=arc-20160816; b=kz4WWrd2GDDHEpEJRy7i4o3eKXcIcAS54pzR2ymol8JUVH7Tmpq+SfGdRCAtegUfEK Bos/qXB7p+Fbw17BwOAj3+keKhmTKaEo1QB+O8Gm8QkNbAx/lln7BQ6LbflRau1xqSKn DNVZviC15YbyJMvL/nBR49/bYS3p2ndPiTMRD915WdYZPRl/zmpX2CgZzndIqLNAXeEg fGGezN2/tJsXIehOoOPcFck9Fk977ixY1ohS9jRnB4AnyQkhRf127qG5LzgFx+ostwMM 9y3fwF/whKnfZeeE+Q87GqzDHKgcm8WMekf0rGKUSgZTn+Pru6Fyx3HTJeAr71EkAzXA SghA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=VPxvWfzidbdufHwjHsLIFDhjZhE7VbFOLoJl9Ptv77M=; b=H7maeg79o/nmArcoVzCN50xxO1Didq51sbA2lc7T64EAFbvBetY79AKQuarykgWqYG 8QTnn8sP/5/C81CCFcdmLPB9fMJ9fs1Q6+MDMF9SmS1sPM7ENKZ9B2U/jTB87lWWNjMl F76ML/bakafFkAbY6v9swR+c9GwU9DzI6UYst0gRZgmr9Eu2VPo2fyFKnK+0DHpoTbAd 8yZFfB56nggQWnif+SUabi6VPvCo7u+XMJuo9dHfcpChy65jKsIMG8W0AQ6cfqSnwSUL MQIp2LcgdtrAJNnHBcFc6I0qeYRCiCjnQfNIS2xaZhypHJlhQAlf8MXZuytwa7djFvXg OaEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=e8LG49vr; 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 v136si3851385pfc.9.2019.07.20.11.43.19; Sat, 20 Jul 2019 11:43:34 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=e8LG49vr; 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 S1728027AbfGTLU5 (ORCPT + 99 others); Sat, 20 Jul 2019 07:20:57 -0400 Received: from merlin.infradead.org ([205.233.59.134]:55616 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728011AbfGTLU5 (ORCPT ); Sat, 20 Jul 2019 07:20:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VPxvWfzidbdufHwjHsLIFDhjZhE7VbFOLoJl9Ptv77M=; b=e8LG49vrxiW/CUiccLMNo2oo0 6FM7kyVLsvyZGKhOT6sQYLLa2ST6gJftGn0Cj0sGVUsXfPW7KZsKlvgAQIj7TT2xdv5fVn7axzrAp jzTUuRF5scF+w8GQIq2FZbwt95R76pfZ13KRvJZKCjtHcNTb1h+G6nUVUIP/KeF3gqSZ1HaR8sjgn XIRuTSpGYXPV0+sBnq8mefXLrw5vZ9AI/vJoY0FQJfBKZ/Six7svf4KtId42jKIVUlaKQVF56ZIsK MJ7NtMzaH/5FHYHhmdR4+r9yGUVtqYKBeGeh0l1TmZBf/HijexwvGZ8ZmvA3zkKjvYDIHk+KBGDy4 lU37zNYHQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1honPW-0001JR-1I; Sat, 20 Jul 2019 11:20:18 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9758F20BAF36D; Sat, 20 Jul 2019 13:20:14 +0200 (CEST) Date: Sat, 20 Jul 2019 13:20:14 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: Sean Christopherson , Steven Rostedt , Eiichi Tsukata , edwintorok@gmail.com, Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, LKML , Josh Poimboeuf , Joel Fernandes , Andy Lutomirski , Dave Hansen Subject: Re: [PATCH] x86/entry/64: Prevent clobbering of saved CR2 value Message-ID: <20190720112014.GR3402@hirez.programming.kicks-ass.net> References: <20190702053151.26922-1-devel@etsukata.com> <20190702072821.GX3419@hirez.programming.kicks-ass.net> <20190702113355.5be9ebfe@gandalf.local.home> <20190702133905.1482b87e@gandalf.local.home> <20190719202836.GB13680@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 20, 2019 at 10:56:41AM +0200, Thomas Gleixner wrote: > The recent fix for CR2 corruption introduced a new way to reliably corrupt > the saved CR2 value. > > CR2 is saved early in the entry code in RDX, which is the third argument to > the fault handling functions. But it missed that between saving and > invoking the fault handler enter_from_user_mode() can be called. RDX is a > caller saved register so the invoked function can freely clobber it with > the obvious consequences. > > The TRACE_IRQS_OFF call is safe as it calls through the thunk which > preserves RDX. > > Store CR2 in R12 instead which is a callee saved register and move R12 to > RDX just before calling the fault handler. > > Fixes: a0d14b8909de ("x86/mm, tracing: Fix CR2 corruption") > Reported-by: Sean Christopherson > Signed-off-by: Thomas Gleixner D'0h :-( Sorry about that. Acked-by: Peter Zijlstra (Intel) > --- > arch/x86/entry/entry_64.S | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > --- a/arch/x86/entry/entry_64.S > +++ b/arch/x86/entry/entry_64.S > @@ -875,7 +875,12 @@ apicinterrupt IRQ_WORK_VECTOR irq_work > UNWIND_HINT_REGS > > .if \read_cr2 > - GET_CR2_INTO(%rdx); /* can clobber %rax */ > + /* > + * Store CR2 early so subsequent faults cannot clobber it. Use R12 as > + * intermediate storage as RDX can be clobbered in enter_from_user_mode(). > + * GET_CR2_INTO can clobber RAX. > + */ > + GET_CR2_INTO(%r12); > .endif > > .if \shift_ist != -1 > @@ -904,6 +909,10 @@ apicinterrupt IRQ_WORK_VECTOR irq_work > subq $\ist_offset, CPU_TSS_IST(\shift_ist) > .endif > > + .if \read_cr2 > + movq %r12, %rdx /* Move CR2 into 3rd argument */ > + .endif > + > call \do_sym > > .if \shift_ist != -1