about summary refs log tree commit diff
path: root/sysdeps/s390/s390-32/start.S
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-02-25 12:10:57 +0100
committerFlorian Weimer <fweimer@redhat.com>2021-02-25 12:13:02 +0100
commit035c012e32c11e84d64905efaf55e74f704d3668 (patch)
tree7b08a9e9cbd8e4dd2e420cd6b7c204aeb5d61ccc /sysdeps/s390/s390-32/start.S
parenta79328c745219dcb395070cdcd3be065a8347f24 (diff)
downloadglibc-035c012e32c11e84d64905efaf55e74f704d3668.tar.gz
glibc-035c012e32c11e84d64905efaf55e74f704d3668.tar.xz
glibc-035c012e32c11e84d64905efaf55e74f704d3668.zip
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.
Diffstat (limited to 'sysdeps/s390/s390-32/start.S')
-rw-r--r--sysdeps/s390/s390-32/start.S10
1 files changed, 2 insertions, 8 deletions
diff --git a/sysdeps/s390/s390-32/start.S b/sysdeps/s390/s390-32/start.S
index aba90739c1..b6cfa4caf3 100644
--- a/sysdeps/s390/s390-32/start.S
+++ b/sysdeps/s390/s390-32/start.S
@@ -175,18 +175,16 @@ _start:
 	 */
 	stm     %r14,%r15,96(%r15)      # store rtld_fini/stack_end to parameter area
 	la      %r7,96(%r15)
-	l       %r6,.L2-.Llit(%r13)     # load pointer to __libc_csu_fini
-	l       %r5,.L1-.Llit(%r13)     # load pointer to __libc_csu_init
 	l       %r2,.L3-.Llit(%r13)     # load pointer to main
 	l       %r1,.L4-.Llit(%r13)	# load pointer to __libc_start_main
 #ifdef PIC
 	l       %r12,.L5-.Llit(%r13)    # load .got pointer
-	la	%r6,0(%r13,%r6)
-	la	%r5,0(%r13,%r5)
 	la	%r12,0(%r13,%r12)
 	l	%r2,0(%r12,%r2)
 	la	%r1,0(%r13,%r1)
 #endif
+	lhi	%r6, 0			# Used to fini.
+	lhi	%r5, 0			# Used to init.
 
 	/* ok, now branch to the libc main routine */
 	basr    %r14,%r1
@@ -197,13 +195,9 @@ _start:
 	cfi_endproc
 .Llit:
 #ifndef PIC
-.L1:    .long  __libc_csu_init
-.L2:    .long  __libc_csu_fini
 .L3:    .long  main
 .L4:    .long  __libc_start_main
 #else
-.L1:    .long  __libc_csu_init-.Llit
-.L2:    .long  __libc_csu_fini-.Llit
 .L3:    .long  main@GOT
 .L4:    .long  __libc_start_main@plt-.Llit
 .L5:    .long  _GLOBAL_OFFSET_TABLE_-.Llit