Commit Graph

343 Commits

Author SHA1 Message Date
Matthew Fortune d6f373d21b Add a hook to enable load-time inspection of program headers
This hook can be used to perform additional compatibility checks
between shared libraries by inspecting custom program header
information.

	* elf/dl-machine-reject-phdr.h: New file.
	* elf/dl-load.c: #include that.
	(open_verify): Call elf_machine_reject_phdr_p and ignore the file
	if that returned true.
2014-10-31 22:19:23 +00:00
Carlos O'Donell cc00cecef5 elf/dl-load.c: Use __strdup.
During a refactoring pass several repeated blocks of code in dl-load.c
were turned into a call to a local function named local_strdup.  There
is no need for local_strdup, and the routines should instead call
__strdup.  This change does just that.  We call the internal symbol
__strdup because calling strdup is unsafe.  The user might be
using a standard that doesn't include strdup and may have defined this
symbol in their application. During a static link we might reference
the user defined symbol and crash if it doesn't implement a standards
conforming strdup. The resulting code is simpler to understand, and
makes it easier to debug.

No regressions on x86_64.

2014-10-28  Carlos O'Donell  <carlos@redhat.com>

	* dl-load.c (local_strdup): Remove.
	(expand_dynamic_string_token): Use __strdup.
	(decompose_rpath): Likewise.
	(_dl_map_object): Likewise.
2014-10-28 19:46:15 -04:00
Joseph Myers 6bc6bd3b10 Don't use INTVARDEF/INTUSE with __libc_enable_secure (bug 14132).
Continuing the removal of the obsolete INTDEF / INTVARDEF / INTUSE
mechanism, this patch replaces its use for __libc_enable_secure with
the use of rtld_hidden_data_def and rtld_hidden_proto.

Tested for x86_64 that installed stripped shared libraries are
unchanged by the patch.

	[BZ #14132]
	* elf/dl-sysdep.c (__libc_enable_secure): Use rtld_hidden_data_def
	instead of INTVARDEF.
	(_dl_sysdep_start): Do not use INTUSE with __libc_enable_secure.
	* sysdeps/mach/hurd/dl-sysdep.c (__libc_enable_secure): Use
	rtld_hidden_data_def instead of INTVARDEF.
	(_dl_sysdep_start): Do not use INTUSE with __libc_enable_secure.
	* elf/dl-deps.c (expand_dst): Likewise.
	* elf/dl-load.c (_dl_dst_count): Likewise.
	(_dl_dst_substitute): Likewise.
	(decompose_rpath): Likewise.
	(_dl_init_paths): Likewise.
	(open_path): Likewise.
	(_dl_map_object): Likewise.
	* elf/rtld.c (dl_main): Likewise.
	(process_dl_audit): Likewise.
	(process_envvars): Likewise.
	* include/unistd.h [IS_IN_rtld] (__libc_enable_secure_internal):
	Remove declaration.
	(__libc_enable_secure): Use rtld_hidden_proto.
2014-10-10 11:13:11 +00:00
Kostya Serebryany b8c80a7e0d remove nested functions from elf/dl-load.c 2014-10-09 11:15:24 -07:00
Andreas Schwab 774f928582 Remove second argument from TLS_INIT_TP macro 2014-05-27 14:48:46 +02:00
Roland McGrath fcccd51286 Factor mmap/munmap of PT_LOAD segments out of _dl_map_object_from_fd et al. 2014-04-03 10:47:14 -07:00
Paul Pluzhnikov 277ae3f186 2014-03-27 Paul Pluzhnikov <ppluzhnikov@google.com>
* elf/dl-load.c: Finish conversion of __builtin_expect into
	__glibc_{un}likely.
2014-03-27 11:50:42 -07:00
Paul Pluzhnikov 1b26b855b4 2014-03-26 Paul Pluzhnikov <ppluzhnikov@google.com>
* elf/dl-load.c: Convert __builtin_expect into __glibc_{un}likely.
2014-03-26 15:37:07 -07:00
Paul Pluzhnikov a42faf59d6 Fix BZ #16634.
An application that erroneously tries to repeatedly dlopen("a.out", ...)
may hit assertion failure:

  Inconsistency detected by ld.so: dl-tls.c: 474: _dl_allocate_tls_init:
  Assertion `listp != ((void *)0)' failed!

dlopen() actually fails with  "./a.out: cannot dynamically load executable",
but it does so after incrementing dl_tls_max_dtv_idx.

Once we run out of TLS_SLOTINFO_SURPLUS (62), we exit with above assertion
failure.

2014-03-24  Paul Pluzhnikov  <ppluzhnikov@google.com>

	[BZ #16634]

	* elf/dl-load.c (open_verify): Add mode parameter.
        Error early when ET_EXEC and mode does not have __RTLD_OPENEXEC.
        (open_path): Change from boolean 'secure' to complete flag 'mode'
        (_dl_map_object): Adjust.
	* elf/Makefile (tests): Add tst-dlopen-aout.
	* elf/tst-dlopen-aout.c: New test.
2014-03-24 10:58:26 -07:00
Paul Pluzhnikov 798212a013 2014-03-12 Paul Pluzhnikov <ppluzhnikov@google.com>
[BZ #16381]

	* elf/Makefile (tests): Add tst-pie2.
        (tests-pie): Add tst-pie2.
	* elf/tst-pie2.c: New file.
	* elf/dl-load.c (_dl_map_object_from_fd): Assert correct l_type
	for ET_EXEC.
	* elf/rtld.c (map_doit): Load executable as lt_executable.
	(dl_main): Likewise.
2014-03-12 15:58:39 -07:00
Ondřej Bílka a1ffb40e32 Use glibc_likely instead __builtin_expect. 2014-02-10 15:07:12 +01:00
Maciej W. Rozycki 0d23a5c1b1 [BZ #16046] Static dlopen correction fallout fixes.
Fixes to address issues from BZ #15022 resolution, as follows:

* TLS updates to csu/libc-tls.c -- we now have a proper main map, so
  there's no longer a need to create a separate fake one to keep TLS
  structures,

* random updates to elf/dl-close.c -- LM_ID_BASE is now a valid name
  space ID for static executables as well, so assert that we don't
  unload the main map.  Similarly dl_nns isn't supposed to be 0 for
  static executables anymore,

* actual BZ #16046 fix to elf/dl-iteratephdr.c -- the dl_iterate_phdr
  special function for static executables isn't needed anymore, provided
  that l_phdr and l_phnum members of the main map have been properly
  initialized (done in _dl_non_dynamic_init in elf/dl-support.c now),

* ld.so.cache loader update to elf/dl-load.c --
  GL(dl_ns)[LM_ID_BASE]._ns_loaded is now always initialized in static
  executables so can become the fallback loader map to check for
  DF_1_NODEFLIB, provided that the l_flags_1 member of the main map has
  been properly initialized (done in elf/dl-support.c now); this also
  ensures previous semantics elsewhere in elf/dl-load.c,

* matching updates to elf/dl-support.c -- to complement the two fixes
  above.
2014-01-31 17:51:31 +00:00
Brooks Moses 9f236c496a Obvious comment typo fix ("openened") in elf/dl-load.c. 2014-01-08 18:46:53 -08:00
Allan McRae d4697bc93d Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
Ondřej Bílka 2a939a7e6d Return fixed version of breaking of RPATH when $ORIGIN contains colons 2013-12-02 14:53:14 +01:00
Ondřej Bílka 246a7c1bc2 Revert b75891075b 2013-11-18 23:42:58 +01:00
Ondřej Bílka b75891075b Fix breaking of RPATH when $ORIGIN contains colons. Fixes bug 10253
We first expanded origin and then split string by colons. This
misbehaves when $ORIGIN contain colon so we first split string, then
expand $ORIGIN.
2013-11-18 19:59:46 +01:00
Ondřej Bílka c0c3f78afb Fix typos. 2013-08-21 19:48:48 +02:00
Pierre Ynard 0432680e8c Test for mprotect failure in dl-load.c (bug 12492). 2013-06-28 21:43:42 +00:00
Maciej W. Rozycki f91f1c0fb8 [BZ #15022] Correct global-scope dlopen issues in static executables.
This change creates a link map in static executables to serve as the
global search list for dlopen.  It fixes a problem with the inability
to access the global symbol object and a crash on an attempt to map a
DSO into the global scope.  Some code that has become dead after the
addition of this link map is removed too and test cases are provided.
2013-06-28 16:22:20 +01:00
Siddhesh Poyarekar b937534868 Avoid crashing in LD_DEBUG when program name is unavailable
Resolves: #15465

The program name may be unavailable if the user application tampers
with argc and argv[].  Some parts of the dynamic linker caters for
this while others don't, so this patch consolidates the check and
fallback into a single macro and updates all users.
2013-05-29 21:34:12 +05:30
Andreas Schwab 273cdee86d Fix invalid free of memory allocated during rtld init 2013-04-11 09:22:05 +02:00
Joseph Myers 568035b787 Update copyright notices with scripts/update-copyrights. 2013-01-02 19:05:09 +00:00
H.J. Lu c515fb5148 Cast to __intptr_t before casting pointer to int64 2012-11-26 16:45:36 -08:00
Chris Metcalf 47cc1490e0 Invoke DL_AFTER_LOAD if defined
This hook is useful for any arch-specific functionality that
should be done on loaded objects.  For the tile architecture,
the hook is already provided (though we switch to using the new
macro name with this commit) and implements a simulator notifier
so that the simulator can load Elf symbols to match the object
and generate better error messages for PC's.

Also, remove a spurious definition of DL_UNMAP in dl-runtime.c
2012-10-30 14:16:18 -04:00
Siddhesh Poyarekar 88481c1638 Retry read in ld.so if the entire ELF header is not read in
[BZ #13601]

A read operation could return less than requested data for a number of
reasons.
2012-10-20 08:03:54 +05:30
Roland McGrath f57f805541 Clean up conditionalize of ld.so.cache support. 2012-10-03 16:13:14 -07:00
Roland McGrath 408223d403 Use ElfW(Off) rather than off_t for offsets within ELF files. 2012-10-02 16:02:56 -07:00
Roland McGrath 4b4f2771c2 Fix dl-load.c for [!_LIBC_REENTRANT] case. 2012-08-15 17:05:10 -07:00
Gary Benson 815e6fa3e0 Add SystemTap static probes to the runtime linker. [BZ #14298] 2012-07-27 14:03:20 +01:00
Siddhesh Poyarekar 73d65cc378 New ld.so argument --inhibit-ldcache to disable ld.so.cache lookup
It may sometimes be desirable to make the dynamic linker only pick up
libraries from the library path and rpath and not look at the
ld.so.cache that ldconfig generates. An example of such a use case is
the glibc testsuite where the dynamic linker must not be influenced by
any external paths or caches.

This change adds a new option --inhibit-ldcache that when used, tells
the dynamic linker to not use ld.so.cache even if it is available.
2012-04-11 00:13:52 +05:30
Paul Eggert 59ba27a63a Replace FSF snail mail address with URLs. 2012-02-09 23:18:22 +00:00
Marek Polacek fde56e5cc5 elf/dl-load.c: Avoid warning 2011-10-07 11:00:13 -04:00
Andreas Schwab 610f9ab43e Fix crash during error handling 2011-09-08 12:03:11 +02:00
Ulrich Drepper b49865be8e Use O_CLOEXEC when loading objects in ld.so 2011-09-08 00:00:01 -04:00
Ulrich Drepper c966526aa4 Fix memory leak in case of failed dlopen 2011-09-07 22:58:47 -04:00
Ulrich Drepper 07df30d995 Better check for last patch
Don't indicate that dependencies of dynamically loaded objects are
also dynamically loaded.
2011-08-12 13:32:10 -04:00
Ulrich Drepper 9ac533d31b Better debug information from ld.so
Differentiate between loading as a dependency and loading on request.
2011-08-12 13:20:11 -04:00
Ulrich Drepper 22836f52e3 Fix up testing for valid $ORIGIN use 2011-05-11 00:15:38 -04:00
Ulrich Drepper 47c3cd7a74 Allow $ORIGIN to reference trusted directoreis in SUID binaries. 2011-05-07 11:44:26 -04:00
Andreas Schwab 34fe483e12 Don't leave empty element in rpath when skipping an element 2011-04-09 14:55:26 -04:00
Ulrich Drepper 6a5ee1029b Fix loading first object along a path when tracing. 2011-03-06 00:01:50 -05:00
Andreas Schwab 4bff6e0175 Fix memory leak in dlopen with RTLD_NOLOAD. 2011-02-25 20:49:48 -05:00
Ryan S. Arnold 30950a5fd2 Make PowerPC64 default to nonexecutable stack 2010-12-19 22:49:01 -05:00
Andreas Krebbel f09677388a Fix concurrency problem between dl_open and dl_iterate_phdr 2010-10-26 00:23:14 -04:00
Andreas Schwab 8e9f92e9d5 Require suid bit on audit objects in privileged programs 2010-10-24 21:43:15 -04:00
Andreas Schwab bc5fb0374c Don't try to free rpath strings allocated during startup 2010-09-15 07:20:57 -07:00
Andreas Schwab 5a2a1d7504 Don't deadlock in __dl_iterate_phdr while (un)loading objects. 2010-05-03 08:08:28 -07:00
Ulrich Drepper 04f2902d9f Future safety in checking ELF header.
If we should use further fields in the e_ident array in the ELF header
of files we want zero to mean the default.  Enforce zero for now so
that non-optional features indicated by nonzero values are not go
unnoticed when using an old dynamic linker.
2010-03-18 13:15:27 -07:00
Ulrich Drepper d8c47894ca Extended ELF ABI version handling only for Linux.
If the OSABI is generic we should not allow the ABI version to be nonzero.
Move all the new functionality into Linux-specific files.
2010-03-16 23:34:59 -07:00