]> git.ipfire.org Git - thirdparty/glibc.git/commit
elf: Handle ld.so with LOAD segment gaps in _dl_find_object (bug 31943)
authorFlorian Weimer <fweimer@redhat.com>
Fri, 1 Aug 2025 10:19:49 +0000 (12:19 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 1 Aug 2025 17:28:30 +0000 (19:28 +0200)
commit513629b14d43bffd83985ffb9cf10e5599e649d2
tree7a1bf0e1165ee2cafddd965b5acd23f2a67ed3e1
parentf48de98bce78119096c531ae08272b41d6382d01
elf: Handle ld.so with LOAD segment gaps in _dl_find_object (bug 31943)

Detect if ld.so not contiguous and handle that case in _dl_find_object.
Set l_find_object_processed even for initially loaded link maps,
otherwise dlopen of an initially loaded object adds it to
_dlfo_loaded_mappings (where maps are expected to be contiguous),
in addition to _dlfo_nodelete_mappings.

Test elf/tst-link-map-contiguous-ldso iterates over the loader
image, reading every word to make sure memory is actually mapped.
It only does that if the l_contiguous flag is set for the link map.
Otherwise, it finds gaps with mmap and checks that _dl_find_object
does not return the ld.so mapping for them.

The test elf/tst-link-map-contiguous-main does the same thing for
the libc.so shared object.  This only works if the kernel loaded
the main program because the glibc dynamic loader may fill
the gaps with PROT_NONE mappings in some cases, making it contiguous,
but accesses to individual words may still fault.

Test elf/tst-link-map-contiguous-libc is again slightly different
because the dynamic loader always fills the gaps with PROT_NONE
mappings, so a different form of probing has to be used.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 20681be149b9eb1b6c1f4246bf4bd801221c86cd)
NEWS
elf/Makefile
elf/dl-find_object.c
elf/dl-find_object.h
elf/rtld.c
elf/tst-link-map-contiguous-ldso.c [new file with mode: 0644]
elf/tst-link-map-contiguous-libc.c [new file with mode: 0644]
elf/tst-link-map-contiguous-main.c [new file with mode: 0644]