Received: by 10.223.176.5 with SMTP id f5csp967979wra; Fri, 2 Feb 2018 09:01:30 -0800 (PST) X-Google-Smtp-Source: AH8x225yPygYGUDzm0YJ6rrUf0XPrsjA9xdsJ38ye2A9TvLYGPAQL2Uok6F46ymgvkaTC2Yc2tci X-Received: by 10.98.248.1 with SMTP id d1mr40771911pfh.222.1517590890099; Fri, 02 Feb 2018 09:01:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517590890; cv=none; d=google.com; s=arc-20160816; b=SeGAB0ENAtbwA0Niff82Z9e2d2rgI7vFv5+QtW+sRiVbN3E8PDK7hJjVboiN+uh5Rf JeSCXVEZmUIRA/qOy1qHYg3/Wga836lHP3NTtmNz9SyGAZ8+gGd/SZLQgoy6Yhp8ol9H a5s8vUG73b2/AHc8GPhW0ue5fIq/gcOkhaIVbJ3Z2Hq9CLbWARw6C7oK4MPXMqZZ+G8i nNnAfVe3vGUNpHEUBy90/K8BOvojwc0QuQ8sm8/vQanvpaWnNGwbsmcI8ZiYGeO9xqCX EoehyQytOvXfDrhsg5uo2KgGeiDnnScIg81NLUnS6sHH2Ycai02HUCEbOk9w8cvRgFZZ i8Ag== 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=x2sIyCL+jGOJuatqIkD4sgCZkCBAdkVCWz3+R7rZ+fI=; b=iArgNGTOJrDIunMbPAY4/TIaqdHjQV15ocJcsj1Wvu06p/4beHoD/cbqmvB9RynnzZ l+HA7+jlEMzS4lnDMTxG7VI5ZivTMTSVwJHg5qXH/qzq5/As0EI10aV7bJ+65NylUge5 FjJ7PBqkIANaw4N9oKVNqaMLQFt22XjcGEairNlXUt0S5iiKJzMxHuhTWxCIaqz+3Pgn 3Z4dxPrNawS3VxvJsvQ4scjAKGGtwjAOntA0DOM3lXfkUdLJswasnzcZyvWqrP7JZzVh zNlRpzIM4Zch/Z1VYLBguXWEU3J+5+1uUvvdRDzbM8i3zUvg64NZUTv1cF+cuIZGEifv RL7g== 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 y11si1702792pgv.424.2018.02.02.09.01.14; Fri, 02 Feb 2018 09:01:30 -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 S1752539AbeBBQ75 (ORCPT + 99 others); Fri, 2 Feb 2018 11:59:57 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34456 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752494AbeBBQ7k (ORCPT ); Fri, 2 Feb 2018 11:59:40 -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 9B570DE1; Fri, 2 Feb 2018 16:59:38 +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, Hugh Dickins , gregkh@linux-foundation.org Subject: [PATCH 4.4 11/67] x86/pti: Make unpoison of pgd for trusted boot work for real Date: Fri, 2 Feb 2018 17:57:40 +0100 Message-Id: <20180202140816.487701831@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140815.091718203@linuxfoundation.org> References: <20180202140815.091718203@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.4-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 Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20180110224939.2695CD47@viggo.jf.intel.com 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 @@ -140,6 +140,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; }