x86/vmlinux: Actually use _etext for the end of the text segment
authorKees Cook <keescook@chromium.org>
Tue, 29 Oct 2019 21:13:37 +0000 (14:13 -0700)
committerBorislav Petkov <bp@suse.de>
Mon, 4 Nov 2019 16:54:16 +0000 (17:54 +0100)
Various calculations are using the end of the exception table (which
does not need to be executable) as the end of the text segment. Instead,
in preparation for moving the exception table into RO_DATA, move _etext
after the exception table and update the calculations.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: linux-alpha@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-c6x-dev@linux-c6x.org
Cc: linux-ia64@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-s390@vger.kernel.org
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
Cc: Ross Zwisler <zwisler@chromium.org>
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Lendacky <Thomas.Lendacky@amd.com>
Cc: Will Deacon <will@kernel.org>
Cc: x86-ml <x86@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Link: https://lkml.kernel.org/r/20191029211351.13243-16-keescook@chromium.org
arch/x86/include/asm/sections.h
arch/x86/kernel/vmlinux.lds.S
arch/x86/mm/init_64.c
arch/x86/mm/pti.c

index 71b32f2570abc933429d01c4d98047c850a09563..036c360910c5d35e71b3cf0cac6c6555ed73a71c 100644 (file)
@@ -6,7 +6,6 @@
 #include <asm/extable.h>
 
 extern char __brk_base[], __brk_limit[];
-extern struct exception_table_entry __stop___ex_table[];
 extern char __end_rodata_aligned[];
 
 #if defined(CONFIG_X86_64)
index 41362e90142d7eef3f055e806aef881c898cecf9..a1a758e25b2b2377ef7fb3fcd27f4ad700c0c912 100644 (file)
@@ -143,15 +143,14 @@ SECTIONS
                *(.text.__x86.indirect_thunk)
                __indirect_thunk_end = .;
 #endif
-
-               /* End of text section */
-               _etext = .;
        } :text = 0x9090
 
        EXCEPTION_TABLE(16)
 
-       /* .text should occupy whole number of pages */
+       /* End of text section, which should occupy whole number of pages */
+       _etext = .;
        . = ALIGN(PAGE_SIZE);
+
        X86_ALIGN_RODATA_BEGIN
        RO_DATA(PAGE_SIZE)
        X86_ALIGN_RODATA_END
index a6b5c653727badfd0823a6035eb5c1f9e0f5eb3c..26299e9ce6da7fa2a37eac6830627645b88b4488 100644 (file)
@@ -1263,7 +1263,7 @@ int kernel_set_to_readonly;
 void set_kernel_text_rw(void)
 {
        unsigned long start = PFN_ALIGN(_text);
-       unsigned long end = PFN_ALIGN(__stop___ex_table);
+       unsigned long end = PFN_ALIGN(_etext);
 
        if (!kernel_set_to_readonly)
                return;
@@ -1282,7 +1282,7 @@ void set_kernel_text_rw(void)
 void set_kernel_text_ro(void)
 {
        unsigned long start = PFN_ALIGN(_text);
-       unsigned long end = PFN_ALIGN(__stop___ex_table);
+       unsigned long end = PFN_ALIGN(_etext);
 
        if (!kernel_set_to_readonly)
                return;
@@ -1301,7 +1301,7 @@ void mark_rodata_ro(void)
        unsigned long start = PFN_ALIGN(_text);
        unsigned long rodata_start = PFN_ALIGN(__start_rodata);
        unsigned long end = (unsigned long) &__end_rodata_hpage_align;
-       unsigned long text_end = PFN_ALIGN(&__stop___ex_table);
+       unsigned long text_end = PFN_ALIGN(&_etext);
        unsigned long rodata_end = PFN_ALIGN(&__end_rodata);
        unsigned long all_end;
 
index 7f2140414440dbc3193b95b3c1ddbda917eaf794..44a9f068eee00b502731b15dcbe6a6faa2727581 100644 (file)
@@ -574,7 +574,7 @@ static void pti_clone_kernel_text(void)
         */
        unsigned long start = PFN_ALIGN(_text);
        unsigned long end_clone  = (unsigned long)__end_rodata_aligned;
-       unsigned long end_global = PFN_ALIGN((unsigned long)__stop___ex_table);
+       unsigned long end_global = PFN_ALIGN((unsigned long)_etext);
 
        if (!pti_kernel_image_global_ok())
                return;