Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4194538ybl; Mon, 13 Jan 2020 09:24:40 -0800 (PST) X-Google-Smtp-Source: APXvYqyw44G/CjHNWqz+fzbiaHXnvYCsUMidlKclY6631+Lgp5DMrezSYwMbBhjKYaDCfgyhJIF6 X-Received: by 2002:a9d:10d:: with SMTP id 13mr12833148otu.149.1578936280716; Mon, 13 Jan 2020 09:24:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578936280; cv=none; d=google.com; s=arc-20160816; b=p1Us9q7XkjWWHCNMHnaxiZ1lIL3nC/n+S5h0iGHwmH0ZJDrxEg56jqY2z0moJiLOwy op0uxoJ2KM5AZrZYKpbDKOLg08ZjlxIwBI9tBa4xUgBDdpHjWGtiZCLdRkUelNIfgP8N qoXCNOpIq9Ldx4XQSwUkkKm8h5U546SWVdAF1cGH7w4TDdn3zmDM7J7hKD7Hs3FsqA5p j/AcglALD9UnfokvehAOfHoe4ejRssKBiNCvDhDoSpOQ6PHc/H8el1xriTQYcdLDHavt C6n5b+G/fSpOczBaZf3SvCXJ7svFyNQ1ANT49HawTV0Nm/bExoFOYYptCwSn7a7ktv19 Qqaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2P+n9AHZxQUcSdE2/YIPafU5Cg2hYuaoKoSQGL9WASg=; b=0EWVQuCWQfd2VCMuGOJz+KmsQiNqTYQAUPAXleTfy1DgOLIlVEYgey+ctSwE7JEfDW gXWbExd1ZEt7fAkaoa3xPMMmT/bOgLKnvCPqmV6VOCc0c2BaD7SNW1eGeunn3/v0woGF MShmL4KcilJ3gICCr9ZTkpwGVvsHQ7EDUBHojD/h1ikATi3Ybmjn1RDLi4SjEUzQl/G4 GRO5/btOX0UYUkofL1j+PQX5kuUIazDByH/wFfUKs0AccrDExvdHJUHAw2RJB8fwicbH 64M8EZ8mjWowdVEpOce+tJ1BcGO4SvfcikLUyMxqynHmEHycMk2d6msfGTP7N5TGMiWZ RC6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OLapDzxI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si5977998oie.87.2020.01.13.09.24.28; Mon, 13 Jan 2020 09:24:40 -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; dkim=pass header.i=@kernel.org header.s=default header.b=OLapDzxI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728863AbgAMRXT (ORCPT + 99 others); Mon, 13 Jan 2020 12:23:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:41628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728847AbgAMRXQ (ORCPT ); Mon, 13 Jan 2020 12:23:16 -0500 Received: from dogfood.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B30E621569; Mon, 13 Jan 2020 17:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578936195; bh=yc2upCJC1oIV4r6mrOZ4qqD4lozYeYb8kOlT9po9Zz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OLapDzxIfuetZiW2VU/osuqqHFd+PoxAO7ibvMaSfG9Il5L7MT339KNxbkSymQ3ZP UyQNdkfLuQPPXEZ4zQ32zWGJsUWkh7deJ8fsENgYgkbi/Ukf4ykDm7Z7uWmRgE1id3 TZOWpubOLdUl1IwCpMQrtAb6rlf/bBtBGtYxKz4Y= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Anshuman Khandual , Arnd Bergmann , Dan Williams , Dave Young , Saravana Kannan Subject: [PATCH 04/13] x86/mm: fix NX bit clearing issue in kernel_map_pages_in_pgd Date: Mon, 13 Jan 2020 18:22:36 +0100 Message-Id: <20200113172245.27925-5-ardb@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200113172245.27925-1-ardb@kernel.org> References: <20200113172245.27925-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 15f003d20782 ("x86/mm/pat: Don't implicitly allow _PAGE_RW in kernel_map_pages_in_pgd()") modified kernel_map_pages_in_pgd() to manage writable permissions of memory mappings in the EFI page table in a different way, but in the process, it removed the ability to clear NX attributes from read-only mappings, by clobbering the clear mask if _PAGE_RW is not being requested. Failure to remove the NX attribute from read-only mappings is unlikely to be a security issue, but it does prevent us from tightening the permissions in the EFI page tables going forward, so let's fix it now. Fixes: 15f003d20782 ("x86/mm/pat: Don't implicitly allow _PAGE_RW in kernel_map_pages_in_pgd() Signed-off-by: Ard Biesheuvel --- arch/x86/mm/pat/set_memory.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 20823392f4f2..62a8ebe72a52 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2215,7 +2215,7 @@ int __init kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address, .pgd = pgd, .numpages = numpages, .mask_set = __pgprot(0), - .mask_clr = __pgprot(0), + .mask_clr = __pgprot(~page_flags & (_PAGE_NX|_PAGE_RW)), .flags = 0, }; @@ -2224,12 +2224,6 @@ int __init kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address, if (!(__supported_pte_mask & _PAGE_NX)) goto out; - if (!(page_flags & _PAGE_NX)) - cpa.mask_clr = __pgprot(_PAGE_NX); - - if (!(page_flags & _PAGE_RW)) - cpa.mask_clr = __pgprot(_PAGE_RW); - if (!(page_flags & _PAGE_ENC)) cpa.mask_clr = pgprot_encrypted(cpa.mask_clr); -- 2.20.1