Skip to content

Commit 45e2a9d

Browse files
keesKAGA-KOKO
authored andcommitted
x86, mm: Set NX across entire PMD at boot
When setting up permissions on kernel memory at boot, the end of the PMD that was split from bss remained executable. It should be NX like the rest. This performs a PMD alignment instead of a PAGE alignment to get the correct span of memory. Before: ---[ High Kernel Mapping ]--- ... 0xffffffff8202d000-0xffffffff82200000 1868K RW GLB NX pte 0xffffffff82200000-0xffffffff82c00000 10M RW PSE GLB NX pmd 0xffffffff82c00000-0xffffffff82df5000 2004K RW GLB NX pte 0xffffffff82df5000-0xffffffff82e00000 44K RW GLB x pte 0xffffffff82e00000-0xffffffffc0000000 978M pmd After: ---[ High Kernel Mapping ]--- ... 0xffffffff8202d000-0xffffffff82200000 1868K RW GLB NX pte 0xffffffff82200000-0xffffffff82e00000 12M RW PSE GLB NX pmd 0xffffffff82e00000-0xffffffffc0000000 978M pmd [ tglx: Changed it to roundup(_brk_end, PMD_SIZE) and added a comment. We really should unmap the reminder along with the holes caused by init,initdata etc. but thats a different issue ] Signed-off-by: Kees Cook <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Toshi Kani <[email protected]> Cc: Yasuaki Ishimatsu <[email protected]> Cc: David Vrabel <[email protected]> Cc: Wang Nan <[email protected]> Cc: Yinghai Lu <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Thomas Gleixner <[email protected]>
1 parent fb86b97 commit 45e2a9d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

arch/x86/mm/init_64.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ void mark_rodata_ro(void)
11231123
unsigned long end = (unsigned long) &__end_rodata_hpage_align;
11241124
unsigned long text_end = PFN_ALIGN(&__stop___ex_table);
11251125
unsigned long rodata_end = PFN_ALIGN(&__end_rodata);
1126-
unsigned long all_end = PFN_ALIGN(&_end);
1126+
unsigned long all_end;
11271127

11281128
printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
11291129
(end - start) >> 10);
@@ -1134,7 +1134,16 @@ void mark_rodata_ro(void)
11341134
/*
11351135
* The rodata/data/bss/brk section (but not the kernel text!)
11361136
* should also be not-executable.
1137+
*
1138+
* We align all_end to PMD_SIZE because the existing mapping
1139+
* is a full PMD. If we would align _brk_end to PAGE_SIZE we
1140+
* split the PMD and the reminder between _brk_end and the end
1141+
* of the PMD will remain mapped executable.
1142+
*
1143+
* Any PMD which was setup after the one which covers _brk_end
1144+
* has been zapped already via cleanup_highmem().
11371145
*/
1146+
all_end = roundup((unsigned long)_brk_end, PMD_SIZE);
11381147
set_memory_nx(rodata_start, (all_end - rodata_start) >> PAGE_SHIFT);
11391148

11401149
rodata_test();

0 commit comments

Comments
 (0)