musl/ldso
Rich Felker a71b46cfd2 fix malloc state corruption when ldso rejects loading a second libc
commit c49d3c8ada added logic to detect
attempts to load libc.so via another name and instead redirect to the
existing libc, rather than loading two and producing dangerously
inconsistent state. however, the check for and unmapping of the
duplicate libc happened after reclaim_gaps was already called,
donating the slack space around the writable segment to malloc.
subsequent unmapping of the library then invalidated malloc's free
lists.

fix the issue by moving the call to reclaim_gaps out of map_library
into load_library, after the duplicate libc check but before the first
call to calloc, so that the gaps can still be used to satisfy the
allocation of struct dso. this change also eliminates the need for an
ugly hack (temporarily setting runtime=1) to avoid reclaim_gaps when
loading the main program via map_library, which happens when ldso is
invoked as a command.

only programs/libraries erroneously containing a DT_NEEDED reference
to libc.so via an absolute pathname or symlink were affected by this
issue.
2017-11-13 15:27:10 -05:00
..
dlstart.c fix regression in SH/FDPIC dynamic linker 2016-02-18 04:13:05 +00:00
dynlink.c fix malloc state corruption when ldso rejects loading a second libc 2017-11-13 15:27:10 -05:00