aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2025-07-18 19:58:59 +0200
committerFlorian Weimer <fweimer@redhat.com>2025-07-18 19:58:59 +0200
commit01196393c257c59f63e0e14fa1bfe8d2a699bf2d (patch)
treebc1f67965bd3ed98c245b1ecec6838e1357289dc
parent3a9c1497e320d77b2453ee88d7d6b40e162e85d4 (diff)
downloadglibc-01196393c257c59f63e0e14fa1bfe8d2a699bf2d.zip
glibc-01196393c257c59f63e0e14fa1bfe8d2a699bf2d.tar.gz
glibc-01196393c257c59f63e0e14fa1bfe8d2a699bf2d.tar.bz2
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>
-rw-r--r--debug/Makefile12
-rw-r--r--debug/tst-sprintf-fortify-rdonly-static.c1
-rw-r--r--elf/rtld.c2
-rw-r--r--elf/rtld_static_init.c1
4 files changed, 15 insertions, 1 deletions
diff --git a/debug/Makefile b/debug/Makefile
index 13f638e..919bf91 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -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-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-static.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
$(objpfx)tst-sprintf-fortify-rdonly: $(objpfx)tst-sprintf-fortify-rdonly-mod.so
$(objpfx)tst-sprintf-fortify-rdonly.out: \
$(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.
# Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and
@@ -328,9 +335,14 @@ tests = \
tst-longjmp_chk3 \
tst-realpath-chk \
tst-sprintf-fortify-rdonly \
+ tst-sprintf-fortify-rdonly-static \
tst-sprintf-fortify-unchecked \
# tests
+tests-static = \
+ tst-sprintf-fortify-rdonly-static \
+ # tests-static
+
tests-time64 += \
$(tests-all-time64-chk) \
# tests-time64
diff --git a/debug/tst-sprintf-fortify-rdonly-static.c b/debug/tst-sprintf-fortify-rdonly-static.c
new file mode 100644
index 0000000..ca5bbd5
--- /dev/null
+++ b/debug/tst-sprintf-fortify-rdonly-static.c
@@ -0,0 +1 @@
+#include "tst-sprintf-fortify-rdonly.c"
diff --git a/elf/rtld.c b/elf/rtld.c
index f889f01..493f969 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -371,7 +371,6 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
._dl_error_free = _dl_error_free,
._dl_tls_get_addr_soft = _dl_tls_get_addr_soft,
._dl_libc_freeres = __rtld_libc_freeres,
- ._dl_readonly_area = _dl_readonly_area,
};
/* If we would use strong_alias here the compiler would see a
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
interfere with __rtld_static_init. */
GLRO (dl_find_object) = &_dl_find_object;
+ GLRO (dl_readonly_area) = &_dl_readonly_area;
/* If it hasn't happen yet record the startup time. */
rtld_timer_start (&start_time);
diff --git a/elf/rtld_static_init.c b/elf/rtld_static_init.c
index 6423790..9c56180 100644
--- a/elf/rtld_static_init.c
+++ b/elf/rtld_static_init.c
@@ -79,6 +79,7 @@ __rtld_static_init (struct link_map *map)
attribute_hidden;
dl->_dl_tls_static_size = _dl_tls_static_size;
dl->_dl_find_object = _dl_find_object;
+ dl->_dl_readonly_area = _dl_readonly_area;
__rtld_static_init_arch (map, dl);
}