1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

elf: Initialize GLRO (dl_read_only_area) after static dlopen (bug 33139)

The _dl_read_only_area function in the uninitialized ld.so after
static dlopen is not able to find anything.  Instead, we need to
redirect to the code from the statically linked main program.

Fixes commit d60fffe28a46b2a41fc308c1804ff02375d27408 ("debug:
Improve '%n' fortify detection (BZ 30932)").

Reviewed-by: Adhemerval Zanella Netto  <adhemerval.zanella@linaro.org>
This commit is contained in:
Florian Weimer
2025-07-18 19:58:59 +02:00
parent 3a9c1497e3
commit 01196393c2
4 changed files with 15 additions and 1 deletions

View File

@@ -184,12 +184,19 @@ CPPFLAGS-tst-chk-cancel.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
CFLAGS-tst-sprintf-fortify-rdonly.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2 CFLAGS-tst-sprintf-fortify-rdonly.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
CFLAGS-tst-sprintf-fortify-rdonly-mod.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2 CFLAGS-tst-sprintf-fortify-rdonly-mod.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
CFLAGS-tst-sprintf-fortify-rdonly-dlopen.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2 CFLAGS-tst-sprintf-fortify-rdonly-dlopen.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
CFLAGS-tst-sprintf-fortify-rdonly-static.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
CFLAGS-tst-fortify-syslog.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2 CFLAGS-tst-fortify-syslog.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
CFLAGS-tst-fortify-wide.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2 CFLAGS-tst-fortify-wide.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
$(objpfx)tst-sprintf-fortify-rdonly: $(objpfx)tst-sprintf-fortify-rdonly-mod.so $(objpfx)tst-sprintf-fortify-rdonly: $(objpfx)tst-sprintf-fortify-rdonly-mod.so
$(objpfx)tst-sprintf-fortify-rdonly.out: \ $(objpfx)tst-sprintf-fortify-rdonly.out: \
$(objpfx)tst-sprintf-fortify-rdonly-dlopen.so $(objpfx)tst-sprintf-fortify-rdonly-dlopen.so
$(objpfx)tst-sprintf-fortify-rdonly-static: \
$(objpfx)tst-sprintf-fortify-rdonly-dlopen.o
$(objpfx)tst-sprintf-fortify-rdonly-static.out: \
$(objpfx)tst-sprintf-fortify-rdonly-dlopen.so
tst-sprintf-fortify-rdonly-static-ENV = \
LD_LIBRARY_PATH=$(objpfx):$(common-objpfx):$(common-objpfx)/elf
# _FORTIFY_SOURCE tests. # _FORTIFY_SOURCE tests.
# Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and
@@ -328,9 +335,14 @@ tests = \
tst-longjmp_chk3 \ tst-longjmp_chk3 \
tst-realpath-chk \ tst-realpath-chk \
tst-sprintf-fortify-rdonly \ tst-sprintf-fortify-rdonly \
tst-sprintf-fortify-rdonly-static \
tst-sprintf-fortify-unchecked \ tst-sprintf-fortify-unchecked \
# tests # tests
tests-static = \
tst-sprintf-fortify-rdonly-static \
# tests-static
tests-time64 += \ tests-time64 += \
$(tests-all-time64-chk) \ $(tests-all-time64-chk) \
# tests-time64 # tests-time64

View File

@@ -0,0 +1 @@
#include "tst-sprintf-fortify-rdonly.c"

View File

@@ -371,7 +371,6 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
._dl_error_free = _dl_error_free, ._dl_error_free = _dl_error_free,
._dl_tls_get_addr_soft = _dl_tls_get_addr_soft, ._dl_tls_get_addr_soft = _dl_tls_get_addr_soft,
._dl_libc_freeres = __rtld_libc_freeres, ._dl_libc_freeres = __rtld_libc_freeres,
._dl_readonly_area = _dl_readonly_area,
}; };
/* If we would use strong_alias here the compiler would see a /* If we would use strong_alias here the compiler would see a
non-hidden definition. This would undo the effect of the previous non-hidden definition. This would undo the effect of the previous
@@ -458,6 +457,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
/* Do not use an initializer for these members because it would /* Do not use an initializer for these members because it would
interfere with __rtld_static_init. */ interfere with __rtld_static_init. */
GLRO (dl_find_object) = &_dl_find_object; GLRO (dl_find_object) = &_dl_find_object;
GLRO (dl_readonly_area) = &_dl_readonly_area;
/* If it hasn't happen yet record the startup time. */ /* If it hasn't happen yet record the startup time. */
rtld_timer_start (&start_time); rtld_timer_start (&start_time);

View File

@@ -79,6 +79,7 @@ __rtld_static_init (struct link_map *map)
attribute_hidden; attribute_hidden;
dl->_dl_tls_static_size = _dl_tls_static_size; dl->_dl_tls_static_size = _dl_tls_static_size;
dl->_dl_find_object = _dl_find_object; dl->_dl_find_object = _dl_find_object;
dl->_dl_readonly_area = _dl_readonly_area;
__rtld_static_init_arch (map, dl); __rtld_static_init_arch (map, dl);
} }