Received: by 10.223.176.5 with SMTP id f5csp716857wra; Fri, 9 Feb 2018 06:09:13 -0800 (PST) X-Google-Smtp-Source: AH8x226ayHrQ3J6Sqm/k70NsH75acu3tUbRLp55vSLEsO7uW3uCzouL4qq9MJQTIIMRomWb4jFT1 X-Received: by 2002:a17:902:b685:: with SMTP id c5-v6mr2763184pls.174.1518185353541; Fri, 09 Feb 2018 06:09:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518185353; cv=none; d=google.com; s=arc-20160816; b=aLEnfZryTEL8QtEFv+KMGsmLVXk6ji5elMhv2uWvKbJ8/zTukSfb5Jz9//ocvv1j0Z 273OWsDBiNIG013npEBpQjK2zeKe3s7mFMiwH8/7LgNzfw53eRTV/4E4OOAJdkPC+EYT K/uUNoeqMOMM5cNAjgDgaVchlHvWHfI2OyKAvPvYdJWMKSL9M8IiCCHeI44nTlINJR/w k0h7ws+qGY1t5Ozfiye5cU1AaS0woSr6bVDD3uJ9wuXc8JYSHqRjPspHLvE+Cjy2eSjP JIpknIqO2eufu+nY08BmgubQzjDxzwu1//A+EuG1VcCjz8hgiu+ms7O7oUX5aL1cvtU/ w23w== 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=E7spTSmEefd6Yb3h0d7iTUjSuW/q7YzBv7O9YpVeVuc=; b=qDinK1Kgt6EguVLOi+Kn4FfofaJnX6pVNoeElFJGT6PkBgUUj7Jf1Mx321bIm+KHlC Lp9eu3PusqZrFBbMdYIpmw9QPTYAJSnZY+c62SdPqh6JiYgusCC6O5cFccsg0D6Mlfws aHOrf7YBshAJIGArHNDNgK+8L3FdSRzTvk7QkV0bN7IUZpXE5vtqrWcWDIQkStNqQiR5 z4dPnOYWYLMqIK4cxC3Ebak229va86a5lFmwK4l59Wh8tvxWuzwZDqSgST24sj0meBpi sZm5VyldfLBKtGOaWA2WNOeS5CSeRRVCxZjLsDVhlYxs1DTTlM/E/D2T+q6dYqO5pkGT bCeQ== 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 k12si1406570pgc.587.2018.02.09.06.08.59; Fri, 09 Feb 2018 06:09:13 -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 S1752964AbeBINmf (ORCPT + 99 others); Fri, 9 Feb 2018 08:42:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:49900 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752943AbeBINmd (ORCPT ); Fri, 9 Feb 2018 08:42:33 -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 A3AE0FA5; Fri, 9 Feb 2018 13:42:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Hansen , Thomas Gleixner , Andrea Arcangeli , Jon Masters , Tim Chen , gnomes@lxorguk.ukuu.org.uk, peterz@infradead.org, ning.sun@intel.com, tboot-devel@lists.sourceforge.net, andi@firstfloor.org, luto@kernel.org, law@redhat.com, pbonzini@redhat.com, torvalds@linux-foundation.org, dwmw@amazon.co.uk, nickc@redhat.com, Jiri Kosina , Hugh Dickins , gregkh@linux-foundation.org Subject: [PATCH 4.9 16/92] x86/pti: Make unpoison of pgd for trusted boot work for real Date: Fri, 9 Feb 2018 14:38:45 +0100 Message-Id: <20180209133932.427736240@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180209133931.211869118@linuxfoundation.org> References: <20180209133931.211869118@linuxfoundation.org> User-Agent: quilt/0.65 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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dave Hansen commit 445b69e3b75e42362a5bdc13c8b8f61599e2228a upstream The inital fix for trusted boot and PTI potentially misses the pgd clearing if pud_alloc() sets a PGD. It probably works in *practice* because for two adjacent calls to map_tboot_page() that share a PGD entry, the first will clear NX, *then* allocate and set the PGD (without NX clear). The second call will *not* allocate but will clear the NX bit. Defer the NX clearing to a point after it is known that all top-level allocations have occurred. Add a comment to clarify why. [ tglx: Massaged changelog ] [ hughd notes: I have not tested tboot, but this looks to me as necessary and as safe in old-Kaiser backports as it is upstream; I'm not submitting the commit-to-be-fixed 262b6b30087, since it was undone by 445b69e3b75e, and makes conflict trouble because of 5-level's p4d versus 4-level's pgd.] Fixes: 262b6b30087 ("x86/tboot: Unbreak tboot with PTI enabled") Signed-off-by: Dave Hansen Signed-off-by: Thomas Gleixner Reviewed-by: Andrea Arcangeli Cc: Jon Masters Cc: Tim Chen Cc: gnomes@lxorguk.ukuu.org.uk Cc: peterz@infradead.org Cc: ning.sun@intel.com Cc: tboot-devel@lists.sourceforge.net Cc: andi@firstfloor.org Cc: luto@kernel.org Cc: law@redhat.com Cc: pbonzini@redhat.com Cc: torvalds@linux-foundation.org Cc: gregkh@linux-foundation.org Cc: dwmw@amazon.co.uk Cc: nickc@redhat.com Link: https://lkml.kernel.org/r/20180110224939.2695CD47@viggo.jf.intel.com Cc: Jiri Kosina Signed-off-by: Hugh Dickins Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/tboot.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/arch/x86/kernel/tboot.c +++ b/arch/x86/kernel/tboot.c @@ -134,6 +134,16 @@ static int map_tboot_page(unsigned long return -1; set_pte_at(&tboot_mm, vaddr, pte, pfn_pte(pfn, prot)); pte_unmap(pte); + + /* + * PTI poisons low addresses in the kernel page tables in the + * name of making them unusable for userspace. To execute + * code at such a low address, the poison must be cleared. + * + * Note: 'pgd' actually gets set in pud_alloc(). + */ + pgd->pgd &= ~_PAGE_NX; + return 0; }