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. --- csu/Makefile | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'csu/Makefile') diff --git a/csu/Makefile b/csu/Makefile index c9385df..e587434 100644 --- a/csu/Makefile +++ b/csu/Makefile @@ -27,10 +27,9 @@ subdir := csu include ../Makeconfig routines = init-first libc-start $(libc-init) sysdep version check_fds \ - libc-tls elf-init dso_handle + libc-tls dso_handle aux = errno elide-routines.os = libc-tls -static-only-routines = elf-init csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o) extra-objs = start.o \ $(start-installed-name) g$(start-installed-name) $(csu-dummies) \ @@ -59,13 +58,6 @@ CFLAGS-.os += $(no-stack-protector) # but it does not matter for this source file. CFLAGS-static-reloc.os += $(stack-protector) -# This file is not actually part of the startup code in the nonshared -# case and statically linked into applications. See -# , -# . -# Also see the note above regarding STACK_PROTECTOR_LEVEL. -CFLAGS-elf-init.oS += $(stack-protector) - ifeq (yes,$(build-shared)) extra-objs += S$(start-installed-name) gmon-start.os ifneq ($(start-installed-name),$(static-start-installed-name)) -- cgit v1.1