Skip to content

Commit 75fbef0

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
x86/mm: Fix NX bit clearing issue in kernel_map_pages_in_pgd
The following commit: 15f003d ("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: 15f003d ("x86/mm/pat: Don't implicitly allow _PAGE_RW in kernel_map_pages_in_pgd() Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent bd1d709 commit 75fbef0

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

arch/x86/mm/pat/set_memory.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ int __init kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
22152215
.pgd = pgd,
22162216
.numpages = numpages,
22172217
.mask_set = __pgprot(0),
2218-
.mask_clr = __pgprot(0),
2218+
.mask_clr = __pgprot(~page_flags & (_PAGE_NX|_PAGE_RW)),
22192219
.flags = 0,
22202220
};
22212221

@@ -2224,12 +2224,6 @@ int __init kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
22242224
if (!(__supported_pte_mask & _PAGE_NX))
22252225
goto out;
22262226

2227-
if (!(page_flags & _PAGE_NX))
2228-
cpa.mask_clr = __pgprot(_PAGE_NX);
2229-
2230-
if (!(page_flags & _PAGE_RW))
2231-
cpa.mask_clr = __pgprot(_PAGE_RW);
2232-
22332227
if (!(page_flags & _PAGE_ENC))
22342228
cpa.mask_clr = pgprot_encrypted(cpa.mask_clr);
22352229

0 commit comments

Comments
 (0)