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/generic | |
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/generic')
-rw-r--r-- | sysdeps/generic/ldsodefs.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 9720a4e446..ea3f7a69d0 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -93,6 +93,10 @@ typedef struct link_map *lookup_t; : (__glibc_unlikely ((ref)->st_shndx == SHN_ABS) ? 0 \ : LOOKUP_VALUE_ADDRESS (map, map_set)) + (ref)->st_value) +/* Type of a constructor function, in DT_INIT, DT_INIT_ARRAY, + DT_PREINIT_ARRAY. */ +typedef void (*dl_init_t) (int, char **, char **); + /* On some architectures a pointer to a function is not just a pointer to the actual code of the function but rather an architecture specific descriptor. */ @@ -101,7 +105,7 @@ typedef struct link_map *lookup_t; (void *) SYMBOL_ADDRESS (map, ref, false) # define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr)) # define DL_CALL_DT_INIT(map, start, argc, argv, env) \ - ((init_t) (start)) (argc, argv, env) + ((dl_init_t) (start)) (argc, argv, env) # define DL_CALL_DT_FINI(map, start) ((fini_t) (start)) () #endif |