Skip to content

Commit de2b41b

Browse files
joergroedelKAGA-KOKO
authored andcommitted
x86, vmlinux.lds: Page-align end of ..page_aligned sections
On x86-32 the idt_table with 256 entries needs only 2048 bytes. It is page-aligned, but the end of the .bss..page_aligned section is not guaranteed to be page-aligned. As a result, objects from other .bss sections may end up on the same 4k page as the idt_table, and will accidentially get mapped read-only during boot, causing unexpected page-faults when the kernel writes to them. This could be worked around by making the objects in the page aligned sections page sized, but that's wrong. Explicit sections which store only page aligned objects have an implicit guarantee that the object is alone in the page in which it is placed. That works for all objects except the last one. That's inconsistent. Enforcing page sized objects for these sections would wreckage memory sanitizers, because the object becomes artificially larger than it should be and out of bound access becomes legit. Align the end of the .bss..page_aligned and .data..page_aligned section on page-size so all objects places in these sections are guaranteed to have their own page. [ tglx: Amended changelog ] Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Kees Cook <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 4fa640d commit de2b41b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

arch/x86/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ SECTIONS
358358
.bss : AT(ADDR(.bss) - LOAD_OFFSET) {
359359
__bss_start = .;
360360
*(.bss..page_aligned)
361+
. = ALIGN(PAGE_SIZE);
361362
*(BSS_MAIN)
362363
BSS_DECRYPTED
363364
. = ALIGN(PAGE_SIZE);

include/asm-generic/vmlinux.lds.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@
341341

342342
#define PAGE_ALIGNED_DATA(page_align) \
343343
. = ALIGN(page_align); \
344-
*(.data..page_aligned)
344+
*(.data..page_aligned) \
345+
. = ALIGN(page_align);
345346

346347
#define READ_MOSTLY_DATA(align) \
347348
. = ALIGN(align); \
@@ -737,7 +738,9 @@
737738
. = ALIGN(bss_align); \
738739
.bss : AT(ADDR(.bss) - LOAD_OFFSET) { \
739740
BSS_FIRST_SECTIONS \
741+
. = ALIGN(PAGE_SIZE); \
740742
*(.bss..page_aligned) \
743+
. = ALIGN(PAGE_SIZE); \
741744
*(.dynbss) \
742745
*(BSS_MAIN) \
743746
*(COMMON) \

0 commit comments

Comments
 (0)