elf: Expose ELF header in compat_start_thread()
authorGabriel Krisman Bertazi <krisman@collabora.com>
Sun, 4 Oct 2020 03:25:31 +0000 (23:25 -0400)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 26 Oct 2020 12:46:46 +0000 (13:46 +0100)
Like it is done for SET_PERSONALITY with x86, which requires the ELF header
to select correct personality parameters, x86 requires the headers on
compat_start_thread() to choose starting CS for ELF32 binaries, instead of
relying on the going-away TIF_IA32/X32 flags.

Add an indirection macro to ELF invocations of START_THREAD, that x86 can
reimplement to receive the extra parameter just for ELF files.  This
requires no changes to other architectures who don't need the header
information, they can continue to use the original start_thread for ELF and
non-ELF binaries, and it prevents affecting non-ELF code paths for x86.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20201004032536.1229030-6-krisman@collabora.com
fs/binfmt_elf.c
fs/compat_binfmt_elf.c
include/linux/elf.h

index b6b3d052ca86dee2084da5d806d7848e80cac1c1..b23f7553fe9b911e71d10ad0ca27dbd5b84713a6 100644 (file)
@@ -1307,7 +1307,7 @@ out_free_interp:
 #endif
 
        finalize_exec(bprm);
-       start_thread(regs, elf_entry, bprm->p);
+       START_THREAD(elf_ex, regs, elf_entry, bprm->p);
        retval = 0;
 out:
        return retval;
index 2d24c765cbd7aea5440a4e386ca343b9b5eb0383..12b991368f0a5e64c3ac1ee965d70ec7421a9b60 100644 (file)
 #endif
 
 #ifdef compat_start_thread
-#undef start_thread
-#define        start_thread            compat_start_thread
+#define COMPAT_START_THREAD(ex, regs, new_ip, new_sp)  \
+       compat_start_thread(regs, new_ip, new_sp)
+#endif
+
+#ifdef COMPAT_START_THREAD
+#undef START_THREAD
+#define START_THREAD           COMPAT_START_THREAD
 #endif
 
 #ifdef compat_arch_setup_additional_pages
index 5d5b0321da0bd81db3afa2bbe802252ca7e58a94..6dbcfe7a3fd7349b4027c64c2421867a92e16de0 100644 (file)
        SET_PERSONALITY(ex)
 #endif
 
+#ifndef START_THREAD
+#define START_THREAD(elf_ex, regs, elf_entry, start_stack)     \
+       start_thread(regs, elf_entry, start_stack)
+#endif
+
 #define ELF32_GNU_PROPERTY_ALIGN       4
 #define ELF64_GNU_PROPERTY_ALIGN       8