Skip to content

Commit 316d097

Browse files
hansendcKAGA-KOKO
authored andcommitted
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: fb43d6c ("x86/mm: Do not auto-massage page protections") Reported-by: Fengguang Wu <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Ingo Molnar <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Juergen Gross <[email protected]> Cc: Kees Cook <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: [email protected] Cc: Linus Torvalds <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Nadav Amit <[email protected]> Cc: Dan Williams <[email protected]> Cc: Arjan van de Ven <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b7c21bc commit 316d097

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

arch/x86/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ config X86
5252
select ARCH_HAS_DEVMEM_IS_ALLOWED
5353
select ARCH_HAS_ELF_RANDOMIZE
5454
select ARCH_HAS_FAST_MULTIPLIER
55+
select ARCH_HAS_FILTER_PGPROT
5556
select ARCH_HAS_FORTIFY_SOURCE
5657
select ARCH_HAS_GCOV_PROFILE_ALL
5758
select ARCH_HAS_KCOV if X86_64
@@ -273,6 +274,9 @@ config ARCH_HAS_CPU_RELAX
273274
config ARCH_HAS_CACHE_LINE_SIZE
274275
def_bool y
275276

277+
config ARCH_HAS_FILTER_PGPROT
278+
def_bool y
279+
276280
config HAVE_SETUP_PER_CPU_AREA
277281
def_bool y
278282

arch/x86/include/asm/pgtable.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
601601

602602
#define canon_pgprot(p) __pgprot(massage_pgprot(p))
603603

604+
static inline pgprot_t arch_filter_pgprot(pgprot_t prot)
605+
{
606+
return canon_pgprot(prot);
607+
}
608+
604609
static inline int is_new_memtype_allowed(u64 paddr, unsigned long size,
605610
enum page_cache_mode pcm,
606611
enum page_cache_mode new_pcm)

mm/mmap.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,20 @@ pgprot_t protection_map[16] __ro_after_init = {
100100
__S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
101101
};
102102

103+
#ifndef CONFIG_ARCH_HAS_FILTER_PGPROT
104+
static inline pgprot_t arch_filter_pgprot(pgprot_t prot)
105+
{
106+
return prot;
107+
}
108+
#endif
109+
103110
pgprot_t vm_get_page_prot(unsigned long vm_flags)
104111
{
105-
return __pgprot(pgprot_val(protection_map[vm_flags &
112+
pgprot_t ret = __pgprot(pgprot_val(protection_map[vm_flags &
106113
(VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
107114
pgprot_val(arch_vm_get_page_prot(vm_flags)));
115+
116+
return arch_filter_pgprot(ret);
108117
}
109118
EXPORT_SYMBOL(vm_get_page_prot);
110119

0 commit comments

Comments
 (0)