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/nios2/start.S | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'sysdeps/nios2') diff --git a/sysdeps/nios2/start.S b/sysdeps/nios2/start.S index 0a6c587..7c96969 100644 --- a/sysdeps/nios2/start.S +++ b/sysdeps/nios2/start.S @@ -92,18 +92,11 @@ _start: addi r2, r2, %lo(_gp_got - 1b) add r22, r22, r2 - /* Push fini */ - movhi r8, %call_hiadj(__libc_csu_fini) - addi r8, r8, %call_lo(__libc_csu_fini) - add r8, r8, r22 - ldw r8, 0(r8) - stw r8, 0(sp) - - /* r7 == init */ - movhi r7, %call_hiadj(__libc_csu_init) - addi r7, r7, %call_lo(__libc_csu_init) - add r7, r7, r22 - ldw r7, 0(r7) + /* Used to be fini. */ + stw zero, 0(sp) + + /* Used to be init. */ + mov r7, zero /* r6 == argv */ addi r6, sp, 16 -- cgit v1.1