Received: by 10.192.165.148 with SMTP id m20csp452106imm; Wed, 25 Apr 2018 02:11:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx49C2gR2EqL3I8nQMkjzeCsrnOtreD/zzj3nWDFNCl7XH+ZJwiuo7gYKeVtx9HnsVQm4RGLu X-Received: by 2002:a17:902:bd41:: with SMTP id b1-v6mr27790547plx.302.1524647514857; Wed, 25 Apr 2018 02:11:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524647514; cv=none; d=google.com; s=arc-20160816; b=SEtmZcb4Fs716tE1ygWALfsnyKnkaDiQ2/n0SOq4v94qByF8N5VrKbr7EElkqJnUOR KLDiyKE6TNw+HIIc/t5GtftT/NUIMrBKNjNCGnGrModlA6Xad2Yuqs+8A0hbZikJP4EN OGh90ikM8D2BEbK3qZzOb7lcD5p1/ylejI+EQisKZ5FvUQb9zvKgLDGQWpHN4oHfkxaw 1MpYIvD/34rBh7X4S3wk0thRnY0jsIQ1KZ/hqwXUMWQW49n29dhuRP5a0GOyCU2Rw2ml rxhn4K4ELd6qDB5rcnnKW5IDr09Nb6l1XKSfVcg6VlBit+Vp6Q4ZIvzG2GDF2Rl2w87O /rvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=ACxVWOprtasmNYE9an/ZOMWR9NHvBVEwEpEMC9xccS0=; b=e15CHOXJqT5URHz4wsQiZ7siN8v2QAUrc9kbUad4JC2EBaPJ6tk8jz5nHFD9rDYFN7 xJdb5XZlvCZ6A8EN66Xl/IJqWuSjNv0sbZnnVZg6kYM8Y5Zmkmxdvh+IApXAVJ6gB2dj 1Qp7FDgwLoMdNfcnabzyLfw86rfFO2u8R5LF0d0gG/bkQAF15TKbdSC9bY7RAB3tvVo1 rR4LzS0QHtcCRC2/svORXHlqC0188T7Tz2VQFUu8g4JNpxUv4zWWh2WAcvLGot76UNwQ brvYLLVYoO68PKXlWSHrBFVdHW9lDd1BOTkPP3PHb/f92j7ra/x3modtbPRdtfrLM0O9 7iXw== 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 b8-v6si2566451pls.261.2018.04.25.02.11.40; Wed, 25 Apr 2018 02:11:54 -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; 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 S1751928AbeDYJKS (ORCPT + 99 others); Wed, 25 Apr 2018 05:10:18 -0400 Received: from terminus.zytor.com ([198.137.202.136]:33755 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751496AbeDYJKQ (ORCPT ); Wed, 25 Apr 2018 05:10:16 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w3P99D1Q1424116; Wed, 25 Apr 2018 02:09:13 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w3P99Dsl1424113; Wed, 25 Apr 2018 02:09:13 -0700 Date: Wed, 25 Apr 2018 02:09:13 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Dave Hansen Message-ID: Cc: torvalds@linux-foundation.org, keescook@google.com, mingo@kernel.org, namit@vmware.com, dave.hansen@linux.intel.com, bp@alien8.de, gregkh@linuxfoundation.org, dan.j.williams@intel.com, hpa@zytor.com, peterz@infradead.org, dwmw2@infradead.org, aarcange@redhat.com, jpoimboe@redhat.com, luto@kernel.org, jgross@suse.com, arjan@linux.intel.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, fengguang.wu@intel.com, hughd@google.com Reply-To: namit@vmware.com, mingo@kernel.org, keescook@google.com, torvalds@linux-foundation.org, dan.j.williams@intel.com, gregkh@linuxfoundation.org, bp@alien8.de, dave.hansen@linux.intel.com, dwmw2@infradead.org, aarcange@redhat.com, jpoimboe@redhat.com, peterz@infradead.org, hpa@zytor.com, luto@kernel.org, jgross@suse.com, tglx@linutronix.de, arjan@linux.intel.com, fengguang.wu@intel.com, hughd@google.com, linux-kernel@vger.kernel.org In-Reply-To: <20180420222028.99D72858@viggo.jf.intel.com> References: <20180420222028.99D72858@viggo.jf.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/pti: Filter at vma->vm_page_prot population Git-Commit-ID: 316d097c4cd4e7f2ef50c40cff2db266593c4ec4 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 316d097c4cd4e7f2ef50c40cff2db266593c4ec4 Gitweb: https://git.kernel.org/tip/316d097c4cd4e7f2ef50c40cff2db266593c4ec4 Author: Dave Hansen AuthorDate: Fri, 20 Apr 2018 15:20:28 -0700 Committer: Thomas Gleixner CommitDate: Wed, 25 Apr 2018 11:02:51 +0200 x86/pti: Filter at vma->vm_page_prot population commit ce9962bf7e22bb3891655c349faff618922d4a73 0day reported warnings at boot on 32-bit systems without NX support: attempted to set unsupported pgprot: 8000000000000025 bits: 8000000000000000 supported: 7fffffffffffffff WARNING: CPU: 0 PID: 1 at arch/x86/include/asm/pgtable.h:540 handle_mm_fault+0xfc1/0xfe0: check_pgprot at arch/x86/include/asm/pgtable.h:535 (inlined by) pfn_pte at arch/x86/include/asm/pgtable.h:549 (inlined by) do_anonymous_page at mm/memory.c:3169 (inlined by) handle_pte_fault at mm/memory.c:3961 (inlined by) __handle_mm_fault at mm/memory.c:4087 (inlined by) handle_mm_fault at mm/memory.c:4124 The problem is that due to the recent commit which removed auto-massaging of page protections, filtering page permissions at PTE creation time is not longer done, so vma->vm_page_prot is passed unfiltered to PTE creation. Filter the page protections before they are installed in vma->vm_page_prot. Fixes: fb43d6cb91 ("x86/mm: Do not auto-massage page protections") Reported-by: Fengguang Wu Signed-off-by: Dave Hansen Signed-off-by: Thomas Gleixner Acked-by: Ingo Molnar Cc: Andrea Arcangeli Cc: Juergen Gross Cc: Kees Cook Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: David Woodhouse Cc: Hugh Dickins Cc: linux-mm@kvack.org Cc: Linus Torvalds Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Greg Kroah-Hartman Cc: Nadav Amit Cc: Dan Williams Cc: Arjan van de Ven Link: https://lkml.kernel.org/r/20180420222028.99D72858@viggo.jf.intel.com --- arch/x86/Kconfig | 4 ++++ arch/x86/include/asm/pgtable.h | 5 +++++ mm/mmap.c | 11 ++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 00fcf81f2c56..c07f492b871a 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -52,6 +52,7 @@ config X86 select ARCH_HAS_DEVMEM_IS_ALLOWED select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_FAST_MULTIPLIER + select ARCH_HAS_FILTER_PGPROT select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_KCOV if X86_64 @@ -273,6 +274,9 @@ config ARCH_HAS_CPU_RELAX config ARCH_HAS_CACHE_LINE_SIZE def_bool y +config ARCH_HAS_FILTER_PGPROT + def_bool y + config HAVE_SETUP_PER_CPU_AREA def_bool y diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 5f49b4ff0c24..f1633de5a675 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -601,6 +601,11 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) #define canon_pgprot(p) __pgprot(massage_pgprot(p)) +static inline pgprot_t arch_filter_pgprot(pgprot_t prot) +{ + return canon_pgprot(prot); +} + static inline int is_new_memtype_allowed(u64 paddr, unsigned long size, enum page_cache_mode pcm, enum page_cache_mode new_pcm) diff --git a/mm/mmap.c b/mm/mmap.c index 188f195883b9..9d5968d1e8e3 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -100,11 +100,20 @@ pgprot_t protection_map[16] __ro_after_init = { __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 }; +#ifndef CONFIG_ARCH_HAS_FILTER_PGPROT +static inline pgprot_t arch_filter_pgprot(pgprot_t prot) +{ + return prot; +} +#endif + pgprot_t vm_get_page_prot(unsigned long vm_flags) { - return __pgprot(pgprot_val(protection_map[vm_flags & + pgprot_t ret = __pgprot(pgprot_val(protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) | pgprot_val(arch_vm_get_page_prot(vm_flags))); + + return arch_filter_pgprot(ret); } EXPORT_SYMBOL(vm_get_page_prot);