]> git.ipfire.org Git - thirdparty/glibc.git/commit
elf: Handle ld.so with LOAD segment gaps in _dl_find_object (bug 31943) release/2.35/master
authorFlorian Weimer <fweimer@redhat.com>
Fri, 1 Aug 2025 10:19:49 +0000 (12:19 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 14 Aug 2025 08:22:30 +0000 (10:22 +0200)
commitc97735cfde5c1c04fbee65b7f35bc66a23ad9102
tree013bf82b6c399252b322381d7fd0731fb051a090
parent96cc65a28a3342fe54b035bcd1b3a6ad80540921
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]