diff options
author | Florian Weimer <fweimer@redhat.com> | 2021-02-25 12:10:57 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2021-02-25 12:13:02 +0100 |
commit | 035c012e32c11e84d64905efaf55e74f704d3668 (patch) | |
tree | 7b08a9e9cbd8e4dd2e420cd6b7c204aeb5d61ccc /sysdeps/mips | |
parent | a79328c745219dcb395070cdcd3be065a8347f24 (diff) | |
download | glibc-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/mips')
-rw-r--r-- | sysdeps/mips/start.S | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/sysdeps/mips/start.S b/sysdeps/mips/start.S index 28e2ed17ad..4ec42a2a7f 100644 --- a/sysdeps/mips/start.S +++ b/sysdeps/mips/start.S @@ -96,13 +96,13 @@ ENTRY_POINT: # if _MIPS_SIM == _ABIO32 PTR_SUBIU $29, 32 # endif - PTR_LA $7, __libc_csu_init /* init */ - PTR_LA $8, __libc_csu_fini + move $7, $0 /* Used to be init. */ # if _MIPS_SIM == _ABIO32 - PTR_S $8, 16($29) /* fini */ + PTR_S $0, 16($29) /* Used to be fini. */ PTR_S $2, 20($29) /* rtld_fini */ PTR_S $29, 24($29) /* stack_end */ # else + move $8, $0 /* Used to be fini. */ move $9, $2 /* rtld_fini */ move $10, $29 /* stack_end */ # endif @@ -143,19 +143,17 @@ ENTRY_POINT: /* Lay out last arguments, and call __libc_start_main(). */ # ifdef __PIC__ sw $7, 24($sp) /* stack_end */ - lw $4, %got(__libc_csu_fini)($3) - lw $7, %got(__libc_csu_init)($3) /* init */ - sw $4, 16($sp) /* fini */ + move $4, $0 /* Used to be ini. */ + sw $0, 16($sp) /* Used to be fini. */ lw $4, %got(main)($3) /* main */ lw $3, %call16(__libc_start_main)($3) sw $2, 20($sp) /* rtld_fini */ move $25, $3 jalr $3 # else - lw $4, 1f sw $7, 24($sp) /* stack_end */ - lw $7, 2f /* init */ - sw $4, 16($sp) /* fini */ + move $7, $0 /* Used to be init. */ + sw $0, 16($sp) /* Used to be fini. */ lw $4, 3f /* main */ sw $2, 20($sp) /* rtld_fini */ /* Load and call __libc_start_main(). */ @@ -165,8 +163,6 @@ ENTRY_POINT: hlt: b hlt /* Crash if somehow it does return. */ # ifndef __PIC__ .align 2 -1: .word __libc_csu_fini -2: .word __libc_csu_init 3: .word main 4: .word __libc_start_main # endif |