From 035c012e32c11e84d64905efaf55e74f704d3668 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 25 Feb 2021 12:10:57 +0100 Subject: Reduce the statically linked startup code [BZ #23323] It turns out the startup code in csu/elf-init.c has a perfect pair of ROP gadgets (see Marco-Gisbert and Ripoll-Ripoll, "return-to-csu: A New Method to Bypass 64-bit Linux ASLR"). These functions are not needed in dynamically-linked binaries because DT_INIT/DT_INIT_ARRAY are already processed by the dynamic linker. However, the dynamic linker skipped the main program for some reason. For maximum backwards compatibility, this is not changed, and instead, the main map is consulted from __libc_start_main if the init function argument is a NULL pointer. For statically linked binaries, the old approach based on linker symbols is still used because there is nothing else available. A new symbol version __libc_start_main@@GLIBC_2.34 is introduced because new binaries running on an old libc would not run their ELF constructors, leading to difficult-to-debug issues. --- sysdeps/m68k/start.S | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'sysdeps/m68k/start.S') diff --git a/sysdeps/m68k/start.S b/sysdeps/m68k/start.S index c36b34f8d9..98da4db9f3 100644 --- a/sysdeps/m68k/start.S +++ b/sysdeps/m68k/start.S @@ -76,15 +76,14 @@ _start: pea (%a1) /* Push address of the shared library termination function. */ + /* These used to be addresses of the .fini and .init entry points. */ + clr.l -(%sp) + clr.l -(%sp) + #ifdef PIC /* Load PIC register. */ LOAD_GOT (%a5) - /* Push the address of our own entry points to `.fini' and - `.init'. */ - move.l __libc_csu_fini@GOT(%a5), -(%sp) - move.l __libc_csu_init@GOT(%a5), -(%sp) - pea (%a0) /* Push second argument: argv. */ move.l %d0, -(%sp) /* Push first argument: argc. */ @@ -94,10 +93,6 @@ _start: let the libc call main. */ jbsr __libc_start_main@PLTPC #else - /* Push the address of our own entry points to `.fini' and - `.init'. */ - pea __libc_csu_fini - pea __libc_csu_init pea (%a0) /* Push second argument: argv. */ move.l %d0, -(%sp) /* Push first argument: argc. */ -- cgit 1.4.1