]> git.baikalelectronics.ru Git - kernel.git/commitdiff
x86, vmlinux.lds: Page-align end of ..page_aligned sections
authorJoerg Roedel <jroedel@suse.de>
Tue, 21 Jul 2020 09:34:48 +0000 (11:34 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 22 Jul 2020 07:38:37 +0000 (09:38 +0200)
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 <jroedel@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20200721093448.10417-1-joro@8bytes.org
arch/x86/kernel/vmlinux.lds.S
include/asm-generic/vmlinux.lds.h

index 3bfc8dd8a43dbfb52563552284e5315859704749..9a03e5b23135af92649938ea8a9dfc1c0443f21b 100644 (file)
@@ -358,6 +358,7 @@ SECTIONS
        .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
                __bss_start = .;
                *(.bss..page_aligned)
+               . = ALIGN(PAGE_SIZE);
                *(BSS_MAIN)
                BSS_DECRYPTED
                . = ALIGN(PAGE_SIZE);
index db600ef218d7d2e56b6fdf895b1958f80fa05462..052e0f05a984170de74aa31d781530bb528a0549 100644 (file)
 
 #define PAGE_ALIGNED_DATA(page_align)                                  \
        . = ALIGN(page_align);                                          \
-       *(.data..page_aligned)
+       *(.data..page_aligned)                                          \
+       . = ALIGN(page_align);
 
 #define READ_MOSTLY_DATA(align)                                                \
        . = ALIGN(align);                                               \
        . = ALIGN(bss_align);                                           \
        .bss : AT(ADDR(.bss) - LOAD_OFFSET) {                           \
                BSS_FIRST_SECTIONS                                      \
+               . = ALIGN(PAGE_SIZE);                                   \
                *(.bss..page_aligned)                                   \
+               . = ALIGN(PAGE_SIZE);                                   \
                *(.dynbss)                                              \
                *(BSS_MAIN)                                             \
                *(COMMON)                                               \