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/csky/abiv2/start.S | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'sysdeps/csky/abiv2') diff --git a/sysdeps/csky/abiv2/start.S b/sysdeps/csky/abiv2/start.S index d65e37e61b..a565cfa87b 100644 --- a/sysdeps/csky/abiv2/start.S +++ b/sysdeps/csky/abiv2/start.S @@ -66,13 +66,9 @@ _start: .Lgetpc: lrw gb, .Lgetpc@GOTPC addu gb, t0 - lrw a3, __libc_csu_fini@GOT - ldr.w a3, (gb, a3 << 0) - stw a3, (sp, 0) - lrw a3, __libc_csu_init@GOT - addu a3, gb - ldw a3, (a3, 0) + movi a3, 0 /* Used to be init. */ + stw a3, (sp, 0) /* Used to be fini. */ lrw t0, main@GOT addu t0, gb @@ -85,14 +81,9 @@ _start: ldr.w t1, (gb, t1 << 0) jsr t1 #else - /* Fetch address of __libc_csu_fini. */ - lrw a0, __libc_csu_fini - /* Push __libc_csu_fini */ - stw a0, (sp, 0) - - /* Set up the other arguments in registers. */ + movi a3, 0 /* Used to be init. */ + stw a3, (sp, 0) /* Used to be fini. */ lrw a0, main - lrw a3, __libc_csu_init /* Let the libc call main and exit with its return code. */ jsri __libc_start_main -- cgit 1.4.1