about summary refs log tree commit diff
path: root/elf
Commit message (Collapse)AuthorAgeFilesLines
* Fix _dl_profile_fixup data-dependency issue (Bug 23690)Tulio Magno Quites Machado Filho2018-11-301-5/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is a data-dependency between the fields of struct l_reloc_result and the field used as the initialization guard. Users of the guard expect writes to the structure to be observable when they also observe the guard initialized. The solution for this problem is to use an acquire and release load and store to ensure previous writes to the structure are observable if the guard is initialized. The previous implementation used DL_FIXUP_VALUE_ADDR (l_reloc_result->addr) as the initialization guard, making it impossible for some architectures to load and store it atomically, i.e. hppa and ia64, due to its larger size. This commit adds an unsigned int to l_reloc_result to be used as the new initialization guard of the struct, making it possible to load and store it atomically in all architectures. The fix ensures that the values observed in l_reloc_result are consistent and do not lead to crashes. The algorithm is documented in the code in elf/dl-runtime.c (_dl_profile_fixup). Not all data races have been eliminated. Tested with build-many-glibcs and on powerpc, powerpc64, and powerpc64le. [BZ #23690] * elf/dl-runtime.c (_dl_profile_fixup): Guarantee memory modification order when accessing reloc_result->addr. * include/link.h (reloc_result): Add field init. * nptl/Makefile (tests): Add tst-audit-threads. (modules-names): Add tst-audit-threads-mod1 and tst-audit-threads-mod2. Add rules to build tst-audit-threads. * nptl/tst-audit-threads-mod1.c: New file. * nptl/tst-audit-threads-mod2.c: Likewise. * nptl/tst-audit-threads.c: Likewise. * nptl/tst-audit-threads.h: Likewise. Signed-off-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* elf/dl-exception.c: Include <_itoa.h> for _itoa prototypeH.J. Lu2018-11-291-0/+1
| | | | | | Tested with build-many-glibcs.py. * elf/dl-exception.c: Include <_itoa.h>.
* _dl_exception_create_format: Support %x/%lx/%zxH.J. Lu2018-11-293-1/+145
| | | | | | | | | | Add support for %x, %lx and %zx to _dl_exception_create_format and pad to the full width with 0. * elf/Makefile (tests-internal): Add tst-create_format1. * elf/dl-exception.c (_dl_exception_create_format): Support %x, %lx and %zx. * elf/tst-create_format1.c: New file.
* C-SKY: Add dynamic relocations to elf.hMao Han2018-11-291-1/+66
| | | | | | | | | | | | | | | | | | | | | | | | * elf/elf.h (EM_CSKY, R_CKCORE_NONE, R_CKCORE_ADDR32) (R_CKCORE_PCRELIMM8BY4, R_CKCORE_PCRELIMM11BY2, R_CKCORE_PCREL32) (R_CKCORE_PCRELJSR_IMM11BY2, R_CKCORE_RELATIVE, R_CKCORE_COPY) (R_CKCORE_GLOB_DAT, R_CKCORE_JUMP_SLOT, R_CKCORE_GOTOFF) (R_CKCORE_GOTPC, R_CKCORE_GOT32, R_CKCORE_PLT32, R_CKCORE_ADDRGOT) (R_CKCORE_ADDRPLT, R_CKCORE_PCREL_IMM26BY2, R_CKCORE_PCREL_IMM16BY2) (R_CKCORE_PCREL_IMM16BY4, R_CKCORE_PCREL_IMM10BY2) (R_CKCORE_PCREL_IMM10BY4, R_CKCORE_ADDR_HI16, R_CKCORE_ADDR_LO16) (R_CKCORE_GOTPC_HI16, R_CKCORE_GOTPC_LO16, R_CKCORE_GOTOFF_HI16) (R_CKCORE_GOTOFF_LO16, R_CKCORE_GOT12, R_CKCORE_GOT_HI16) (R_CKCORE_GOT_LO16, R_CKCORE_PLT12, R_CKCORE_PLT_HI16) (R_CKCORE_PLT_LO16, R_CKCORE_ADDRGOT_HI16, R_CKCORE_ADDRGOT_LO16) (R_CKCORE_ADDRPLT_HI16, R_CKCORE_ADDRPLT_LO16) (R_CKCORE_PCREL_JSR_IMM26BY2, R_CKCORE_TOFFSET_LO16) (R_CKCORE_DOFFSET_LO16, R_CKCORE_PCREL_IMM18BY2) (R_CKCORE_DOFFSET_IMM18, R_CKCORE_DOFFSET_IMM18BY2) (R_CKCORE_DOFFSET_IMM18BY4, R_CKCORE_GOT_IMM18BY4) (R_CKCORE_PLT_IMM18BY4, R_CKCORE_PCREL_IMM7BY4, R_CKCORE_TLS_LE32) (R_CKCORE_TLS_IE32, R_CKCORE_TLS_GD32, R_CKCORE_TLS_LDM32) (R_CKCORE_TLS_LDO32, R_CKCORE_TLS_DTPMOD32, R_CKCORE_TLS_DTPOFF32) (R_CKCORE_TLS_TPOFF32): New defines.
* RISC-V: properly terminate call chain (bug 23125)Andreas Schwab2018-10-302-1/+41
| | | | | | Mark the ra register as undefined in _start, so that unwinding through main works correctly. Also, don't use a tail call so that ra points after the call to __libc_start_main, not after the previous call.
* Add new ELF note types from Linux 4.19 to elf.h.Joseph Myers2018-10-251-0/+2
| | | | | | | | | | This patch adds NT_MIPS_DSP and NT_MIPS_FP_MODE from Linux 4.19 to elf.h. Tested for x86_64. * elf/elf.h (NT_MIPS_DSP): New macro. (NT_MIPS_FP_MODE): Likewise.
* elf: Fix the ld flags not be applied to tst-execstack-mod.soZong Li2018-10-251-1/+1
| | | | | | The Makefile variable name lacked the file extension (.so). As a result, tst-execstack-mod.so was not linked with the -z execstack flag.
* Add more checks for valid ld.so.cache file (bug 18093)Andreas Schwab2018-10-242-1/+9
|
* Add missing unwind information to ld.so on powerpc32 (bug 23707)Andreas Schwab2018-09-263-2/+74
|
* Fix ifunc support with DT_TEXTREL segments (BZ#20480)Adhemerval Zanella2018-09-253-12/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, DT_TEXTREL is incompatible with IFUNC. When DT_TEXTREL or DF_TEXTREL is seen, the dynamic linker calls __mprotect on the segments with PROT_READ|PROT_WRITE before applying dynamic relocations. It leads to segfault when performing IFUNC resolution (which requires PROT_EXEC as well for the IFUNC resolver). This patch makes it call __mprotect with extra PROT_WRITE bit, which will keep the PROT_EXEC bit if exists, and thus fixes the segfault. FreeBSD rtld libexec/rtld-elf/rtld.c (reloc_textrel_prot) does the same. Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, sparc64-linux-gnu, sparcv9-linux-gnu, and armv8-linux-gnueabihf. Adam J. Richte <adam_richter2004@yahoo.com> Adhemerval Zanella <adhemerval.zanella@linaro.org> Fangrui Song <maskray@google.com> [BZ #20480] * config.h.in (CAN_TEXTREL_IFUNC): New define. * configure.ac: Add check if linker supports textrel relocation with ifunc. * elf/dl-reloc.c (_dl_relocate_object): Use all required flags on DT_TEXTREL segments, not only PROT_READ and PROT_WRITE. * elf/Makefile (ifunc-pie-tests): Add tst-ifunc-textrel. (CFLAGS-tst-ifunc-textrel.c): New rule. * elf/tst-ifunc-textrel.c: New file.
* Include most of elf/ modules-names in modules-names-tests.Joseph Myers2018-09-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm testing a patch to let the compiler expand calls to floor in libm as built-in function calls as much as possible, instead of calling __floor, so that no architecture-specific __floor inlines are needed, and then to arrange for non-inlined calls to end up calling __floor, as done with sqrt and __ieee754_sqrt. This shows up elf/tst-relsort1mod2.c calling floor, which must not be converted to a call to __floor. Now, while an IS_IN (libm) conditional could be added to the existing conditionals on such redirections in include/math.h, the _ISOMAC conditional ought to suffice (code in other glibc libraries shouldn't be calling floor or sqrt anyway, as they aren't provided in libc and the other libraries don't link with libm). But while tests are mostly now built with _ISOMAC defined, test modules in modules-names aren't unless also listed in modules-names-tests. As far as I can see, all the modules in modules-names in elf/ are in fact parts of tests and so listing them in modules-names-tests is appropriate, so they get built with something closer to the headers used for user code, except in a few cases that actually rely on something from internal headers. This patch duly sets modules-names-tests there accordingly (filtering out those tests that fail to build without internal headers). Tested for x86_64, and with build-many-glibcs.py. * elf/Makefile (modules-names-tests): New variable.
* Fix test failure with -DNDEBUG.Carlos O'Donell2018-08-301-6/+6
| | | | | | | | | | | | The elf/tst-dlopen-aout.c test uses asserts to verify properties of the test execution. Instead of using assert it should use xpthread_create and xpthread_join to catch errors starting the threads and fail the test. This shows up in Fedora 28 when building for i686-pc-linux-gnu and using gcc 8.1.1. Tested on i686, and fixes a check failure with -DNDEBUG. Signed-off-by: Carlos O'Donell <carlos@redhat.com>
* Add NT_VMCOREDD, AT_MINSIGSTKSZ from Linux 4.18 to elf.h.Joseph Myers2018-08-201-0/+4
| | | | | | | | | | This patch adds two new constants from Linux 4.18 to elf.h, NT_VMCOREDD and AT_MINSIGSTKSZ. Tested for x86_64. * elf/elf.c (NT_VMCOREDD): New macro. (AT_MINSIGSTKSZ): Likewise.
* Rename the glibc.tune namespace to glibc.cpuSiddhesh Poyarekar2018-08-023-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The glibc.tune namespace is vaguely named since it is a 'tunable', so give it a more specific name that describes what it refers to. Rename the tunable namespace to 'cpu' to more accurately reflect what it encompasses. Also rename glibc.tune.cpu to glibc.cpu.name since glibc.cpu.cpu is weird. * NEWS: Mention the change. * elf/dl-tunables.list: Rename tune namespace to cpu. * sysdeps/powerpc/dl-tunables.list: Likewise. * sysdeps/x86/dl-tunables.list: Likewise. * sysdeps/aarch64/dl-tunables.list: Rename tune.cpu to cpu.name. * elf/dl-hwcaps.c (_dl_important_hwcaps): Adjust. * elf/dl-hwcaps.h (GET_HWCAP_MASK): Likewise. * manual/README.tunables: Likewise. * manual/tunables.texi: Likewise. * sysdeps/powerpc/cpu-features.c: Likewise. * sysdeps/unix/sysv/linux/aarch64/cpu-features.c (init_cpu_features): Likewise. * sysdeps/x86/cpu-features.c: Likewise. * sysdeps/x86/cpu-features.h: Likewise. * sysdeps/x86/cpu-tunables.c: Likewise. * sysdeps/x86_64/Makefile: Likewise. * sysdeps/x86/dl-cet.c: Likewise. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* check-execstack: Permit sysdeps to xfail some libsSamuel Thibault2018-07-201-1/+1
| | | | | | | | | | | * scripts/check-execstack.awk: Consider `xfail' variable containing a list of libraries whose stack executability is expected. * elf/Makefile ($(objpfx)check-execstack.out): Pass $(check-execstack-xfail) to check-execstack.awk through `xfail' variable. * sysdeps/mach/hurd/i386/Makefile (check-execstack-xfail): Set to ld.so libc.so libpthread.so.
* x86: Support IBT and SHSTK in Intel CET [BZ #21598]H.J. Lu2018-07-164-25/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Intel Control-flow Enforcement Technology (CET) instructions: https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-en forcement-technology-preview.pdf includes Indirect Branch Tracking (IBT) and Shadow Stack (SHSTK). GNU_PROPERTY_X86_FEATURE_1_IBT is added to GNU program property to indicate that all executable sections are compatible with IBT when ENDBR instruction starts each valid target where an indirect branch instruction can land. Linker sets GNU_PROPERTY_X86_FEATURE_1_IBT on output only if it is set on all relocatable inputs. On an IBT capable processor, the following steps should be taken: 1. When loading an executable without an interpreter, enable IBT and lock IBT if GNU_PROPERTY_X86_FEATURE_1_IBT is set on the executable. 2. When loading an executable with an interpreter, enable IBT if GNU_PROPERTY_X86_FEATURE_1_IBT is set on the interpreter. a. If GNU_PROPERTY_X86_FEATURE_1_IBT isn't set on the executable, disable IBT. b. Lock IBT. 3. If IBT is enabled, when loading a shared object without GNU_PROPERTY_X86_FEATURE_1_IBT: a. If legacy interwork is allowed, then mark all pages in executable PT_LOAD segments in legacy code page bitmap. Failure of legacy code page bitmap allocation causes an error. b. If legacy interwork isn't allowed, it causes an error. GNU_PROPERTY_X86_FEATURE_1_SHSTK is added to GNU program property to indicate that all executable sections are compatible with SHSTK where return address popped from shadow stack always matches return address popped from normal stack. Linker sets GNU_PROPERTY_X86_FEATURE_1_SHSTK on output only if it is set on all relocatable inputs. On a SHSTK capable processor, the following steps should be taken: 1. When loading an executable without an interpreter, enable SHSTK if GNU_PROPERTY_X86_FEATURE_1_SHSTK is set on the executable. 2. When loading an executable with an interpreter, enable SHSTK if GNU_PROPERTY_X86_FEATURE_1_SHSTK is set on interpreter. a. If GNU_PROPERTY_X86_FEATURE_1_SHSTK isn't set on the executable or any shared objects loaded via the DT_NEEDED tag, disable SHSTK. b. Otherwise lock SHSTK. 3. After SHSTK is enabled, it is an error to load a shared object without GNU_PROPERTY_X86_FEATURE_1_SHSTK. To enable CET support in glibc, --enable-cet is required to configure glibc. When CET is enabled, both compiler and assembler must support CET. Otherwise, it is a configure-time error. To support CET run-time control, 1. _dl_x86_feature_1 is added to the writable ld.so namespace to indicate if IBT or SHSTK are enabled at run-time. It should be initialized by init_cpu_features. 2. For dynamic executables: a. A l_cet field is added to struct link_map to indicate if IBT or SHSTK is enabled in an ELF module. _dl_process_pt_note or _rtld_process_pt_note is called to process PT_NOTE segment for GNU program property and set l_cet. b. _dl_open_check is added to check IBT and SHSTK compatibilty when dlopening a shared object. 3. Replace i386 _dl_runtime_resolve and _dl_runtime_profile with _dl_runtime_resolve_shstk and _dl_runtime_profile_shstk, respectively if SHSTK is enabled. CET run-time control can be changed via GLIBC_TUNABLES with $ export GLIBC_TUNABLES=glibc.tune.x86_shstk=[permissive|on|off] $ export GLIBC_TUNABLES=glibc.tune.x86_ibt=[permissive|on|off] 1. permissive: SHSTK is disabled when dlopening a legacy ELF module. 2. on: IBT or SHSTK are always enabled, regardless if there are IBT or SHSTK bits in GNU program property. 3. off: IBT or SHSTK are always disabled, regardless if there are IBT or SHSTK bits in GNU program property. <cet.h> from CET-enabled GCC is automatically included by assembly codes to add GNU_PROPERTY_X86_FEATURE_1_IBT and GNU_PROPERTY_X86_FEATURE_1_SHSTK to GNU program property. _CET_ENDBR is added at the entrance of all assembly functions whose address may be taken. _CET_NOTRACK is used to insert NOTRACK prefix with indirect jump table to support IBT. It is defined as notrack when _CET_NOTRACK is defined in <cet.h>. [BZ #21598] * configure.ac: Add --enable-cet. * configure: Regenerated. * elf/Makefille (all-built-dso): Add a comment. * elf/dl-load.c (filebuf): Moved before "dynamic-link.h". Include <dl-prop.h>. (_dl_map_object_from_fd): Call _dl_process_pt_note on PT_NOTE segment. * elf/dl-open.c: Include <dl-prop.h>. (dl_open_worker): Call _dl_open_check. * elf/rtld.c: Include <dl-prop.h>. (dl_main): Call _rtld_process_pt_note on PT_NOTE segment. Call _rtld_main_check. * sysdeps/generic/dl-prop.h: New file. * sysdeps/i386/dl-cet.c: Likewise. * sysdeps/unix/sysv/linux/x86/cpu-features.c: Likewise. * sysdeps/unix/sysv/linux/x86/dl-cet.h: Likewise. * sysdeps/x86/cet-tunables.h: Likewise. * sysdeps/x86/check-cet.awk: Likewise. * sysdeps/x86/configure: Likewise. * sysdeps/x86/configure.ac: Likewise. * sysdeps/x86/dl-cet.c: Likewise. * sysdeps/x86/dl-procruntime.c: Likewise. * sysdeps/x86/dl-prop.h: Likewise. * sysdeps/x86/libc-start.h: Likewise. * sysdeps/x86/link_map.h: Likewise. * sysdeps/i386/dl-trampoline.S (_dl_runtime_resolve): Add _CET_ENDBR. (_dl_runtime_profile): Likewise. (_dl_runtime_resolve_shstk): New. (_dl_runtime_profile_shstk): Likewise. * sysdeps/linux/x86/Makefile (sysdep-dl-routines): Add dl-cet if CET is enabled. (CFLAGS-.o): Add -fcf-protection if CET is enabled. (CFLAGS-.os): Likewise. (CFLAGS-.op): Likewise. (CFLAGS-.oS): Likewise. (asm-CPPFLAGS): Add -fcf-protection -include cet.h if CET is enabled. (tests-special): Add $(objpfx)check-cet.out. (cet-built-dso): New. (+$(cet-built-dso:=.note)): Likewise. (common-generated): Add $(cet-built-dso:$(common-objpfx)%=%.note). ($(objpfx)check-cet.out): New. (generated): Add check-cet.out. * sysdeps/x86/cpu-features.c: Include <dl-cet.h> and <cet-tunables.h>. (TUNABLE_CALLBACK (set_x86_ibt)): New prototype. (TUNABLE_CALLBACK (set_x86_shstk)): Likewise. (init_cpu_features): Call get_cet_status to check CET status and update dl_x86_feature_1 with CET status. Call TUNABLE_CALLBACK (set_x86_ibt) and TUNABLE_CALLBACK (set_x86_shstk). Disable and lock CET in libc.a. * sysdeps/x86/cpu-tunables.c: Include <cet-tunables.h>. (TUNABLE_CALLBACK (set_x86_ibt)): New function. (TUNABLE_CALLBACK (set_x86_shstk)): Likewise. * sysdeps/x86/sysdep.h (_CET_NOTRACK): New. (_CET_ENDBR): Define if not defined. (ENTRY): Add _CET_ENDBR. * sysdeps/x86/dl-tunables.list (glibc.tune): Add x86_ibt and x86_shstk. * sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve): Add _CET_ENDBR. (_dl_runtime_profile): Likewise.
* elf: Accept absolute (SHN_ABS) symbols whose value is zero [BZ #23307]Maciej W. Rozycki2018-06-295-2/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have this condition in `check_match' (in elf/dl-lookup.c): if (__glibc_unlikely ((sym->st_value == 0 /* No value. */ && stt != STT_TLS) || ELF_MACHINE_SYM_NO_MATCH (sym) || (type_class & (sym->st_shndx == SHN_UNDEF)))) return NULL; which causes all !STT_TLS symbols whose value is zero to be silently ignored in lookup. This may make sense for regular symbols, however not for absolute (SHN_ABS) ones, where zero is like any value, there's no special meaning attached to it. Consequently legitimate programs fail, for example taking the `elf/tst-absolute-sym' test case, substituting 0 for 0x55aa in `elf/tst-absolute-sym-lib.lds' and then trying to run the resulting program we get this: $ .../elf/tst-absolute-sym .../elf/tst-absolute-sym: symbol lookup error: .../elf/tst-absolute-sym-lib.so: undefined symbol: absolute $ even though the symbol clearly is there: $ readelf --dyn-syms .../elf/tst-absolute-sym-lib.so | grep '\babsolute\b' 7: 00000000 0 NOTYPE GLOBAL DEFAULT ABS absolute $ The check for the zero value has been there since forever or commit d66e34cd4234/08162fa88891 ("Implemented runtime dynamic linker to support ELF shared libraries.") dating back to May 2nd 1995, and the problem triggers regardless of commit e7feec374c63 ("elf: Correct absolute (SHN_ABS) symbol run-time calculation [BZ #19818]") being present or not. Fix the issue then, by permitting `sym->st_value' to be 0 for SHN_ABS symbols in lookup. [BZ #23307] * elf/dl-lookup.c (check_match): Do not reject a symbol whose `st_value' is 0 if `st_shndx' is SHN_ABS. * elf/tst-absolute-zero.c: New file. * elf/tst-absolute-zero-lib.c: New file. * elf/tst-absolute-zero-lib.lds: New file. * elf/Makefile (tests): Add `tst-absolute-zero'. (modules-names): Add `tst-absolute-zero-lib'. (LDLIBS-tst-absolute-zero-lib.so): New variable. ($(objpfx)tst-absolute-zero-lib.so): New dependency. ($(objpfx)tst-absolute-zero: New dependency.
* New configure option --disable-crypt.Zack Weinberg2018-06-292-9/+22
| | | | | | | | Some Linux distributions are experimenting with a new, separately maintained and hopefully more agile implementation of the crypt API. To facilitate this, add a configure option which disables glibc's embedded libcrypt. When this option is given, libcrypt.* and crypt.h will not be built nor installed.
* _dl_map_object_deps: Use struct scratch_buffer [BZ #18023]Florian Weimer2018-06-271-12/+16
| | | | | | The function comment suggests that _dl_map_object_deps cannot use malloc, but it already allocates the l_initfini array on the heap, so the additional allocation should be acceptable.
* Add Andes nds32 dynamic relocations to elf.hVincent Chen2018-06-211-0/+10
| | | | | | | | | | | * elf/elf.h (R_NDS32_NONE): New define. (R_NDS32_32_RELA): Likewise. (R_NDS32_COPY): Likewise. (R_NDS32_GLOB_DAT): Likewise. (R_NDS32_JUMP_SLOT): Likewise. (R_NDS32_RELATIVE): Likewise. (R_NDS32_TLS_TPOFF): Likewise. (R_NDS32_TLS_DESC): Likewise.
* elf.h: Add BPF relocation types.Mark Wielaard2018-06-211-1/+2
| | | | | | | | The BPF ELF format has new relocation types R_BPF_64_64 and R_BPF_64_32. The existing R_BPF_MAP_FD was an extension that never got implemented. Remove it, because the constant conflicts with the official R_BPF_64_64. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Fix comments in _dl_dst_count and _dl_dst_substitute.Carlos O'Donell2018-06-121-6/+8
| | | | | | | | | The comments in _dl_dst_count is adjusted to match what the code does which is count DSTs from the start of the string. With the removal of DL_DST_COUNT we no longer accept an input that starts at the first $. In _dl_dst_substitute we adjust the comment to indicate that both conditions must be true for the SUID/SGID $ORIGIN exception.
* Improve DST handling (Bug 23102, Bug 21942, Bug 18018, Bug 23259).Carlos O'Donell2018-06-123-93/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit improves DST handling significantly in the following ways: firstly is_dst () is overhauled to correctly process DST sequences that would be accepted given the ELF gABI. This means that we actually now accept slightly more sequences than before. Now we accept $ORIGIN$ORIGIN, but in the past we accepted only $ORIGIN\0 or $ORIGIN/..., but this kind of behaviour results in unexpected and uninterpreted DST sequences being used as literal search paths leading to security defects. Therefore the first step in correcting this defect is making is_dst () properly account for all DSTs and making the function context free in the sense that it counts DSTs without knowledge of path, or AT_SECURE. Next, _dl_dst_count () is also simplified to count all DSTs regardless of context. Then in _dl_dst_substitute () we reintroduce context-dependent processing for such things as AT_SECURE handling. At the level of _dl_dst_substitute we can have access to things like the true start of the string sequence to validate $ORIGIN-based paths rooted in trusted directories. Lastly, we tighten up the accepted sequences in AT_SECURE, and avoid leaving known unexpanded DSTs, this is noted in the NEWS entry. Verified with a sequence of 68 tests on x86_64 that cover non-AT_SECURE and AT_SECURE testing using a sysroot (requires root to run). The tests cover cases for bug 23102, bug 21942, bug 18018, and bug 23259. These tests are not yet appropriate for the glibc regression testsuite, but with the upcoming test-in-container testing framework it should be possible to include these tests upstream soon. See the mailing list for the tests: https://www.sourceware.org/ml/libc-alpha/2018-06/msg00251.html
* Avoid cancellable I/O primitives in ld.so.Zack Weinberg2018-06-124-28/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Neither the <dlfcn.h> entry points, nor lazy symbol resolution, nor initial shared library load-up, are cancellation points, so ld.so should exclusively use I/O primitives that are not cancellable. We currently achieve this by having the cancellation hooks compile as no-ops when IS_IN(rtld); this patch changes to using exclusively _nocancel primitives in the source code instead, which makes the intent clearer and significantly reduces the amount of code compiled under IS_IN(rtld) as well as IS_IN(libc) -- in particular, elf/Makefile no longer thinks we require a copy of unwind.c in rtld-libc.a. (The older mechanism is preserved as a backstop.) The bulk of the change is splitting up the files that define the _nocancel I/O functions, so they don't also define the variants that *are* cancellation points; after which, the existing logic for picking out the bits of libc that need to be recompiled as part of ld.so Just Works. I did this for all of the _nocancel functions, not just the ones used by ld.so, for consistency. fcntl was a little tricky because it's only a cancellation point for certain opcodes (F_SETLKW(64), which can block), and the existing __fcntl_nocancel wasn't applying the FCNTL_ADJUST_CMD hook, which strikes me as asking for trouble, especially as the only nontrivial definition of FCNTL_ADJUST_CMD (for powerpc64) changes F_*LK* opcodes. To fix this, fcntl_common moves to fcntl_nocancel.c along with __fcntl_nocancel, and changes its name to the extern (but hidden) symbol __fcntl_nocancel_adjusted, so that regular fcntl can continue calling it. __fcntl_nocancel now applies FCNTL_ADJUST_CMD; so that both both fcntl.c and fcntl_nocancel.c can see it, the only nontrivial definition moves from sysdeps/u/s/l/powerpc/powerpc64/fcntl.c to .../powerpc64/sysdep.h and becomes entirely a macro, instead of a macro that calls an inline function. The nptl version of libpthread also changes a little, because its "compat-routines" formerly included files that defined all the _nocancel functions it uses; instead of continuing to duplicate them, I exported the relevant ones from libc.so as GLIBC_PRIVATE. Since the Linux fcntl.c calls a function defined by fcntl_nocancel.c, it can no longer be used from libpthread.so; instead, introduce a custom forwarder, pt-fcntl.c, and export __libc_fcntl from libc.so as GLIBC_PRIVATE. The nios2-linux ABI doesn't include a copy of vfork() in libpthread, and it was handling that by manipulating libpthread-routines in .../linux/nios2/Makefile; it is cleaner to do what other such ports do, and have a pt-vfork.S that defines no symbols. Right now, it appears that Hurd does not implement _nocancel I/O, so sysdeps/generic/not-cancel.h will forward everything back to the regular functions. This changed the names of some of the functions that sysdeps/mach/hurd/dl-sysdep.c needs to interpose. * elf/dl-load.c, elf/dl-misc.c, elf/dl-profile.c, elf/rtld.c * sysdeps/unix/sysv/linux/dl-sysdep.c Include not-cancel.h. Use __close_nocancel instead of __close, __open64_nocancel instead of __open, __read_nocancel instead of __libc_read, and __write_nocancel instead of __libc_write. * csu/check_fds.c (check_one_fd) * sysdeps/posix/fdopendir.c (__fdopendir) * sysdeps/posix/opendir.c (__alloc_dir): Use __fcntl_nocancel instead of __fcntl and/or __libc_fcntl. * sysdeps/unix/sysv/linux/pthread_setname.c (pthread_setname_np) * sysdeps/unix/sysv/linux/pthread_getname.c (pthread_getname_np) * sysdeps/unix/sysv/linux/i386/smp.h (is_smp_system): Use __open64_nocancel instead of __open_nocancel. * sysdeps/unix/sysv/linux/not-cancel.h: Move all of the hidden_proto declarations to the end and issue them if either IS_IN(libc) or IS_IN(rtld). * sysdeps/unix/sysv/linux/Makefile [subdir=io] (sysdep_routines): Add close_nocancel, fcntl_nocancel, nanosleep_nocancel, open_nocancel, open64_nocancel, openat_nocancel, pause_nocancel, read_nocancel, waitpid_nocancel, write_nocancel. * io/Versions [GLIBC_PRIVATE]: Add __libc_fcntl, __fcntl_nocancel, __open64_nocancel, __write_nocancel. * posix/Versions: Add __nanosleep_nocancel, __pause_nocancel. * nptl/pt-fcntl.c: New file. * nptl/Makefile (pthread-compat-wrappers): Remove fcntl. (libpthread-routines): Add pt-fcntl. * include/fcntl.h (__fcntl_nocancel_adjusted): New function. (__libc_fcntl): Remove attribute_hidden. * sysdeps/unix/sysv/linux/fcntl.c (__libc_fcntl): Call __fcntl_nocancel_adjusted, not fcntl_common. (__fcntl_nocancel): Move to new file fcntl_nocancel.c. (fcntl_common): Rename to __fcntl_nocancel_adjusted; also move to fcntl_nocancel.c. * sysdeps/unix/sysv/linux/fcntl_nocancel.c: New file. * sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c: Remove file. * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h: Define FCNTL_ADJUST_CMD here, as a self-contained macro. * sysdeps/unix/sysv/linux/close.c: Move __close_nocancel to... * sysdeps/unix/sysv/linux/close_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/nanosleep.c: Move __nanosleep_nocancel to... * sysdeps/unix/sysv/linux/nanosleep_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/open.c: Move __open_nocancel to... * sysdeps/unix/sysv/linux/open_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/open64.c: Move __open64_nocancel to... * sysdeps/unix/sysv/linux/open64_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/openat.c: Move __openat_nocancel to... * sysdeps/unix/sysv/linux/openat_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/openat64.c: Move __openat64_nocancel to... * sysdeps/unix/sysv/linux/openat64_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/pause.c: Move __pause_nocancel to... * sysdeps/unix/sysv/linux/pause_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/read.c: Move __read_nocancel to... * sysdeps/unix/sysv/linux/read_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/waitpid.c: Move __waitpid_nocancel to... * sysdeps/unix/sysv/linux/waitpid_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/write.c: Move __write_nocancel to... * sysdeps/unix/sysv/linux/write_nocancel.c: ...this new file. * sysdeps/unix/sysv/linux/nios2/Makefile: Don't override libpthread-routines. * sysdeps/unix/sysv/linux/nios2/pt-vfork.S: New file which defines nothing. * sysdeps/mach/hurd/dl-sysdep.c: Define __read instead of __libc_read, and __write instead of __libc_write. Define __open64 in addition to __open.
* Mark _init and _fini as hidden [BZ #23145]H.J. Lu2018-06-081-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | _init and _fini are special functions provided by glibc for linker to define DT_INIT and DT_FINI in executable and shared library. They should never be put in dynamic symbol table. This patch marks them as hidden to remove them from dynamic symbol table. Tested with build-many-glibcs.py. [BZ #23145] * elf/Makefile (tests-special): Add $(objpfx)check-initfini.out. ($(all-built-dso:=.dynsym): New target. (common-generated): Add $(all-built-dso:$(common-objpfx)%=%.dynsym). ($(objpfx)check-initfini.out): New target. (generated): Add check-initfini.out. * scripts/check-initfini.awk: New file. * sysdeps/aarch64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/alpha/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/arm/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/hppa/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/i386/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/ia64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/m68k/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/microblaze/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/mips/mips32/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/mips/mips64/n32/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/mips/mips64/n64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/nios2/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/powerpc/powerpc32/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/powerpc/powerpc64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/s390/s390-32/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/s390/s390-64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/sh/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/sparc/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/x86_64/crti.S (_init): Mark as hidden. (_fini): Likewise.
* static-PIE: Update DT_DEBUG for debugger [BZ #23206]H.J. Lu2018-05-291-0/+16
| | | | | | | | | | | This is needed to support debugging dlopened shared libraries in static PIE. [BZ #23206] * elf/dl-reloc-static-pie.c (_dl_relocate_static_pie): Initialize _r_debug and update DT_DEBUG for debugger. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Fix BZ 20419. A PT_NOTE in a binary could be arbitratily large, so usingPaul Pluzhnikov2018-05-054-4/+77
| | | | | | | | | | | | | alloca for it may cause stack overflow. If the note is larger than __MAX_ALLOCA_CUTOFF, use dynamically allocated memory to read it in. 2018-05-05 Paul Pluzhnikov <ppluzhnikov@google.com> [BZ #20419] * elf/dl-load.c (open_verify): Fix stack overflow. * elf/Makefile (tst-big-note): New test. * elf/tst-big-note-lib.S: New. * elf/tst-big-note.c: New.
* Add NT_PPC_PKEY from Linux 4.16 to elf.h.Joseph Myers2018-04-231-0/+2
| | | | | | | | This patch adds the NT_PPC_PKEY macro from Linux 4.16 to elf.h. Tested for x86_64. * elf/elf.h (NT_PPC_PKEY): New macro.
* elf: Correct absolute (SHN_ABS) symbol run-time calculation [BZ #19818]Maciej W. Rozycki2018-04-045-2/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Do not relocate absolute symbols by the base address. Such symbols have SHN_ABS as the section index and their value is not supposed to be affected by relocation as per the ELF gABI[1]: "SHN_ABS The symbol has an absolute value that will not change because of relocation." The reason for our non-conformance here seems to be an old SysV linker bug causing symbols like _DYNAMIC to be incorrectly emitted as absolute symbols[2]. However in a previous discussion it was pointed that this is seriously flawed by preventing the lone purpose of the existence of absolute symbols from being used[3]: "On the contrary, the only interpretation that makes sense to me is that it will not change because of relocation at link time or at load time. Absolute symbols, from the days of the earliest linking loaders, have been used to represent addresses that are outside the address space of the module (e.g., memory-mapped addresses or kernel gateway pages). They've even been used to represent true symbolic constants (e.g., system entry point numbers, sizes, version numbers). There's no other way to represent a true absolute symbol, while the meaning you seek is easily represented by giving the symbol a non-negative st_shndx value." and we ought to stop supporting our current broken interpretation. Update processing for dladdr(3) and dladdr1(3) so that SHN_ABS symbols are ignored, because under the corrected interpretation they do not represent addresses within a mapped file and therefore are not supposed to be considered. References: [1] "System V Application Binary Interface - DRAFT - 19 October 2010", The SCO Group, Section "Symbol Table", <http://www.sco.com/developers/gabi/2012-12-31/ch4.symtab.html> [2] Alan Modra, "Absolute symbols" <https://sourceware.org/ml/binutils/2012-05/msg00019.html> [3] Cary Coutant, "Re: Absolute symbols" <https://sourceware.org/ml/binutils/2012-05/msg00020.html> [BZ #19818] * sysdeps/generic/ldsodefs.h (SYMBOL_ADDRESS): Handle SHN_ABS symbols. * elf/dl-addr.c (determine_info): Ignore SHN_ABS symbols. * elf/tst-absolute-sym.c: New file. * elf/tst-absolute-sym-lib.c: New file. * elf/tst-absolute-sym-lib.lds: New file. * elf/Makefile (tests): Add `tst-absolute-sym'. (modules-names): Add `tst-absolute-sym-lib'. (LDLIBS-tst-absolute-sym-lib.so): New variable. ($(objpfx)tst-absolute-sym-lib.so): New dependency. ($(objpfx)tst-absolute-sym): New dependency.
* elf: Unify symbol address run-time calculation [BZ #19818]Maciej W. Rozycki2018-04-043-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Wrap symbol address run-time calculation into a macro and use it throughout, replacing inline calculations. There are a couple of variants, most of them different in a functionally insignificant way. Most calculations are right following RESOLVE_MAP, at which point either the map or the symbol returned can be checked for validity as the macro sets either both or neither. In some places both the symbol and the map has to be checked however. My initial implementation therefore always checked both, however that resulted in code larger by as much as 0.3%, as many places know from elsewhere that no check is needed. I have decided the size growth was unacceptable. Having looked closer I realized that it's the map that is the culprit. Therefore I have modified LOOKUP_VALUE_ADDRESS to accept an additional boolean argument telling it to access the map without checking it for validity. This in turn has brought quite nice results, with new code actually being smaller for i686, and MIPS o32, n32 and little-endian n64 targets, unchanged in size for x86-64 and, unusually, marginally larger for big-endian MIPS n64, as follows: i686: text data bss dec hex filename 152255 4052 192 156499 26353 ld-2.27.9000-base.so 152159 4052 192 156403 262f3 ld-2.27.9000-elf-symbol-value.so MIPS/o32/el: text data bss dec hex filename 142906 4396 260 147562 2406a ld-2.27.9000-base.so 142890 4396 260 147546 2405a ld-2.27.9000-elf-symbol-value.so MIPS/n32/el: text data bss dec hex filename 142267 4404 260 146931 23df3 ld-2.27.9000-base.so 142171 4404 260 146835 23d93 ld-2.27.9000-elf-symbol-value.so MIPS/n64/el: text data bss dec hex filename 149835 7376 408 157619 267b3 ld-2.27.9000-base.so 149787 7376 408 157571 26783 ld-2.27.9000-elf-symbol-value.so MIPS/o32/eb: text data bss dec hex filename 142870 4396 260 147526 24046 ld-2.27.9000-base.so 142854 4396 260 147510 24036 ld-2.27.9000-elf-symbol-value.so MIPS/n32/eb: text data bss dec hex filename 142019 4404 260 146683 23cfb ld-2.27.9000-base.so 141923 4404 260 146587 23c9b ld-2.27.9000-elf-symbol-value.so MIPS/n64/eb: text data bss dec hex filename 149763 7376 408 157547 2676b ld-2.27.9000-base.so 149779 7376 408 157563 2677b ld-2.27.9000-elf-symbol-value.so x86-64: text data bss dec hex filename 148462 6452 400 155314 25eb2 ld-2.27.9000-base.so 148462 6452 400 155314 25eb2 ld-2.27.9000-elf-symbol-value.so [BZ #19818] * sysdeps/generic/ldsodefs.h (LOOKUP_VALUE_ADDRESS): Add `set' parameter. (SYMBOL_ADDRESS): New macro. [!ELF_FUNCTION_PTR_IS_SPECIAL] (DL_SYMBOL_ADDRESS): Use SYMBOL_ADDRESS for symbol address calculation. * elf/dl-runtime.c (_dl_fixup): Likewise. (_dl_profile_fixup): Likewise. * elf/dl-symaddr.c (_dl_symbol_address): Likewise. * elf/rtld.c (dl_main): Likewise. * sysdeps/aarch64/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/arm/dl-machine.h (elf_machine_rel): Likewise. (elf_machine_rela): Likewise. * sysdeps/hppa/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/hppa/dl-symaddr.c (_dl_symbol_address): Likewise. * sysdeps/i386/dl-machine.h (elf_machine_rel): Likewise. (elf_machine_rela): Likewise. * sysdeps/ia64/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/m68k/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/microblaze/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/mips/dl-machine.h (ELF_MACHINE_BEFORE_RTLD_RELOC): Likewise. (elf_machine_reloc): Likewise. (elf_machine_got_rel): Likewise. * sysdeps/mips/dl-trampoline.c (__dl_runtime_resolve): Likewise. * sysdeps/nios2/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/powerpc/powerpc64/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/riscv/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/s390/s390-32/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/s390/s390-64/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/sparc/sparc32/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/tile/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/x86_64/dl-machine.h (elf_machine_rela): Likewise. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* RISC-V: add remaining relocationsAndreas Schwab2018-03-261-12/+56
|
* Add $(tests-execstack-$(have-z-execstack)) after defined [BZ #22998]H.J. Lu2018-03-241-1/+2
| | | | | | | | | | When $(tests-execstack-$(have-z-execstack)) is added to tests before it is defined, it is empty. This patch adds it to tests after it is defined. [BZ #22998] * elf/Makefile (tests): Add $(tests-execstack-$(have-z-execstack)) after it is defined.
* Add SHT_X86_64_UNWIND to elf.h (bug 20079).Joseph Myers2018-03-191-0/+3
| | | | | | | | | | As requested in bug 20079, this patch adds SHT_X86_64_UNWIND (a standard value from the x86_64 ABI) to elf.h. Tested for x86_64. [BZ #20079] * elf/elf.h (SHT_X86_64_UNWIND): New macro.
* hurd: add gscope supportSamuel Thibault2018-03-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * elf/dl-support.c [!THREAD_GSCOPE_IN_TCB] (_dl_thread_gscope_count): Define variable. * sysdeps/generic/ldsodefs.h [!THREAD_GSCOPE_IN_TCB] (struct rtld_global): Add _dl_thread_gscope_count member. * sysdeps/mach/hurd/tls.h: Include <atomic.h>. [!defined __ASSEMBLER__] (THREAD_GSCOPE_GLOBAL, THREAD_GSCOPE_SET_FLAG, THREAD_GSCOPE_RESET_FLAG, THREAD_GSCOPE_WAIT): Define macros. * sysdeps/generic/tls.h: Document THREAD_GSCOPE_IN_TCB. * sysdeps/aarch64/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/alpha/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/arm/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/hppa/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/i386/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/ia64/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/m68k/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/microblaze/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/mips/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/nios2/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/powerpc/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/riscv/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/s390/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/sh/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/sparc/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/tile/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1. * sysdeps/x86_64/nptl/tls.h: Define THREAD_GSCOPE_IN_TCB to 1.
* ldconfig: Sync temporary files to disk before renaming them [BZ #20890]Florian Weimer2018-02-211-3/+7
| | | | | | | If the system crashes before the file data has been written to disk, the file system recovery upon the next mount may restore a partially rewritten temporary file under the non-temporary (final) name (after the rename operation).
* elf: Remove ad-hoc restrictions on dlopen callers [BZ #22787]Florian Weimer2018-02-215-105/+1
| | | | | | | | | | | | | | | | | | | | | | This looks like a post-exploitation hardening measure: If an attacker is able to redirect execution flow, they could use that to load a DSO which contains additional code (or perhaps make the stack executable). However, the checks are not in the correct place to be effective: If they are performed before the critical operation, an attacker with sufficient control over execution flow could simply jump directly to the code which performs the operation, bypassing the check. The check would have to be executed unconditionally after the operation and terminate the process in case a caller violation was detected. Furthermore, in _dl_check_caller, there was a fallback reading global writable data (GL(dl_rtld_map).l_map_start and GL(dl_rtld_map).l_text_end), which could conceivably be targeted by an attacker to disable the check, too. Other critical functions (such as system) remain completely unprotected, so the value of these additional checks does not appear that large. Therefore this commit removes this functionality.
* Add elf.h NT_* macros from Linux 4.15 (bug 14890).Joseph Myers2018-02-061-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Linux 4.15 adds NT_S390_RI_CB to linux/elf.h (and NT_ARM_SVE, which we already have in glibc). This shows up that various other ELF note values from linux/elf.h are missing from glibc's elf.h. This patch adds the missing values that are relevant to glibc architectures. As elf.h is a general description of the ELF format, not necessarily limited to glibc configurations, there's an argument for having the remaining NT_* values that Linux uses for non-glibc architectures in glibc's elf.h as well, but this patch does not add them. Adding the NT_PRFPREG name is bug 14890. That bug also requests making the NT_FPREGSET name obsolete. Given that elf.h is not just for Linux but can describe ELF for other operating systems, I don't think that a change of name in the Linux kernel is sufficient justification for declaring the other name obsolete; there can be multiple names for the same note value, even with incompatible semantics, if those reflect variants of the ELF format in actual use. For example, FreeBSD appears still to have the name NT_FPREGSET <https://github.com/freebsd/freebsd/blob/master/sys/sys/elf_common.h> (note: I haven't checked whether the FreeBSD kernel actually generates such notes or whether this is actually an other-OS definition present in FreeBSD's header). [BZ #14890] * elf/elf.h (NT_PRFPREG): New macro. (NT_S390_VXRS_LOW): Likewise. (NT_S390_VXRS_HIGH): Likewise. (NT_S390_GS_CB): Likewise. (NT_S390_GS_BC): Likewise. (NT_S390_RI_CB): Likewise.
* Use ADDRIDX with DT_GNU_HASHH.J. Lu2018-02-053-10/+4
| | | | | | | | | | The only differences in ld.so are line numbers for asserts. Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> * elf/dl-addr.c (determine_info): Use ADDRIDX with DT_GNU_HASH. * elf/dl-lookup.c (_dl_setup_hash): Likewise. * elf/get-dynamic-info.h (elf_get_dynamic_info): Likewise.
* Add DT_SYMTAB_SHNDX from gABIH.J. Lu2018-02-051-1/+2
| | | | | * elf/elf.h (DT_SYMTAB_SHNDX): New. Set to 34. (DT_NUM): Updated to 35.
* Add support for the RISC-V-specific ELF flagsPalmer Dabbelt2018-01-252-0/+14
| | | | | | | | | | | | | | | | | | | | The RISC-V port defines ELF flags that enforce compatibility between various objects. This adds the shared support necessary for these flags. 2018-01-25 Palmer Dabbelt <palmer@sifive.com> * elf/cache.c (print_entry): Add FLAG_RISCV_FLOAT_ABI_SOFT and FLAG_RISCV_FLOAT_ABI_DOUBLE. * elf/elf.h (EF_RISCV_RVC): New define. (EF_RISCV_FLOAT_ABI): Likewise. (EF_RISCV_FLOAT_ABI_SOFT): Likewise. (EF_RISCV_FLOAT_ABI_SINGLE): Likewise. (EF_RISCV_FLOAT_ABI_DOUBLE): Likewise. (EF_RISCV_FLOAT_ABI_QUAD): Likewise. * sysdeps/generic/ldconfig.h (FLAG_RISCV_FLOAT_ABI_SOFT): New define. (FLAG_RISCV_FLOAT_ABI_DOUBLE): Likewise.
* Add NT_ARM_SVE to elf.hAlan Hayward2018-01-151-0/+2
| | | | | | This definition is for AArch64 SVE registers in elf core dumps. * elf/elf.h (NT_ARM_SVE): Define.
* Synchronize DF_1_* flags with binutils (Bug 22707)Carlos O'Donell2018-01-131-0/+2
| | | | | | | | | | This patch synchronizes DF_1_* flags with binutils and ensures that all DF_1_* flags defined in binutil's include/elf/common.h are also defined glibc's elf/elf.h. This is a user visible change since elf/elf.h is installed by default as /usr/include/elf.h. Signed-off-by: Carlos O'Donell <carlos@redhat.com>
* Add RISC-V dynamic relocations to elf.hPalmer Dabbelt2018-01-061-0/+14
| | | | | | | | | | | | | | | | | | | These relocations can appear in shared objects on RISC-V ELF systems. 2018-01-06 Palmer Dabbelt <palmer@sifive.com> * elf/elf.h (R_RISCV_NONE): New define. (R_RISCV_32): Likewise. (R_RISCV_64): Likewise. (R_RISCV_RELATIVE): Likewise. (R_RISCV_COPY): Likewise. (R_RISCV_JUMP_SLOT): Likewise. (R_RISCV_TLS_DTPMOD32): Likewise. (R_RISCV_TLS_DTPMOD64): Likewise. (R_RISCV_TLS_DTPREL32): Likewise. (R_RISCV_TLS_DTPREL64): Likewise. (R_RISCV_TLS_TPREL32): Likewise. (R_RISCV_TLS_TPREL64): Likewise.
* elf: Support dlvsym within libc.soFlorian Weimer2018-01-047-6/+303
| | | | | | | | | | This commit adds a new _dl_open_hook entry for dlvsym and implements the function using the existing dl_lookup_symbol_x function supplied by the dynamic loader. A new hook variable, _dl_open_hook2, is introduced, which should make this change suitable for backporting: For old statically linked binaries, __libc_dlvsym will always return NULL.
* elf: check for rpath emptiness before making a copy of itDmitry V. Levin2018-01-011-10/+8
| | | | | * elf/dl-load.c (decompose_rpath): Check for rpath emptiness before making a copy of it.
* Update copyright dates not handled by scripts/update-copyrights.Joseph Myers2018-01-015-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I've updated copyright dates in glibc for 2018. This is the patch for the changes not generated by scripts/update-copyrights and subsequent build / regeneration of generated files. Please remember to include 2018 in the dates for any new files added in future (which means updating any existing uncommitted patches you have that add new files to use the new copyright dates in them). * NEWS: Update copyright dates. * catgets/gencat.c (print_version): Likewise. * csu/version.c (banner): Likewise. * debug/catchsegv.sh: Likewise. * debug/pcprofiledump.c (print_version): Likewise. * debug/xtrace.sh (do_version): Likewise. * elf/ldconfig.c (print_version): Likewise. * elf/ldd.bash.in: Likewise. * elf/pldd.c (print_version): Likewise. * elf/sotruss.sh: Likewise. * elf/sprof.c (print_version): Likewise. * iconv/iconv_prog.c (print_version): Likewise. * iconv/iconvconfig.c (print_version): Likewise. * locale/programs/locale.c (print_version): Likewise. * locale/programs/localedef.c (print_version): Likewise. * login/programs/pt_chown.c (print_version): Likewise. * malloc/memusage.sh (do_version): Likewise. * malloc/memusagestat.c (print_version): Likewise. * malloc/mtrace.pl: Likewise. * manual/libc.texinfo: Likewise. * nptl/version.c (banner): Likewise. * nscd/nscd.c (print_version): Likewise. * nss/getent.c (print_version): Likewise. * nss/makedb.c (print_version): Likewise. * posix/getconf.c (main): Likewise. * scripts/test-installation.pl: Likewise. * sysdeps/unix/sysv/linux/lddlibc4.c (main): Likewise.
* Update copyright dates with scripts/update-copyrights.Joseph Myers2018-01-01139-139/+139
| | | | | | | * All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
* elf: Check for empty tokens before dynamic string token expansion [BZ #22625]Aurelien Jarno2017-12-301-16/+33
| | | | | | | | | | | | | | | | | | | | | | | | | The fillin_rpath function in elf/dl-load.c loops over each RPATH or RUNPATH tokens and interprets empty tokens as the current directory ("./"). In practice the check for empty token is done *after* the dynamic string token expansion. The expansion process can return an empty string for the $ORIGIN token if __libc_enable_secure is set or if the path of the binary can not be determined (/proc not mounted). Fix that by moving the check for empty tokens before the dynamic string token expansion. In addition, check for NULL pointer or empty strings return by expand_dynamic_string_token. The above changes highlighted a bug in decompose_rpath, an empty array is represented by the first element being NULL at the fillin_rpath level, but by using a -1 pointer in decompose_rpath and other functions. Changelog: [BZ #22625] * elf/dl-load.c (fillin_rpath): Check for empty tokens before dynamic string token expansion. Check for NULL pointer or empty string possibly returned by expand_dynamic_string_token. (decompose_rpath): Check for empty path after dynamic string token expansion.
* elf: remove redundant is_path argumentDmitry V. Levin2017-12-273-22/+18
| | | | | | | | | | | is_path argument is no longer used and could be safely removed. * elf/dl-dst.h (DL_DST_COUNT): Remove is_path argument, all callers updated. * elf/dl-load.c (is_dst, _dl_dst_count, _dl_dst_substitute, expand_dynamic_string_token): Likewise. * sysdeps/generic/ldsodefs.h (_dl_dst_count, _dl_dst_substitute): Remove is_path argument.
* elf: remove redundant code from is_dstDmitry V. Levin2017-12-271-5/+3
| | | | | | | | | | | | | | | | | is_dst is called either by _dl_dst_count or by _dl_dst_substitute. _dl_dst_count is called by DL_DST_COUNT only. DL_DST_COUNT is called either by expand_dst with is_path == 0 or by expand_dynamic_string_token. _dl_dst_substitute is called either from expand_dst with is_path == 0 or from expand_dynamic_string_token. The latter function is called either from _dl_map_object with is_path == 0 or from fillin_rpath with is_path == 1 and name containing no ':'. In any case (is_path && name[i] == ':') is always false and all code depending on it can be safely removed. * elf/dl-load.c (is_dst): Remove checks that is_path is set and name contains ':', and all code depending on these checks.