]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Initialize GLRO (dl_read_only_area) after static dlopen (bug 33139)
authorFlorian Weimer <fweimer@redhat.com>
Fri, 18 Jul 2025 17:58:59 +0000 (19:58 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 18 Jul 2025 17:58:59 +0000 (19:58 +0200)
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>
debug/Makefile
debug/tst-sprintf-fortify-rdonly-static.c [new file with mode: 0644]
elf/rtld.c
elf/rtld_static_init.c

index 13f638e344ec9198f29d1b06ad8323c16860f74a..919bf91c428db6fb51fd499fbcfb599364a2cc9e 100644 (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-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 (file)
index 0000000..ca5bbd5
--- /dev/null
@@ -0,0 +1 @@
+#include "tst-sprintf-fortify-rdonly.c"
index f889f01b4a4b4abadb01081782725b16d58ebf03..493f9696ea64d6fe2eeed8846d38b6e3c85e4bd3 100644 (file)
@@ -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);
index 642379076bb870d5f26e47a2062b73e0c7377dc3..9c56180f88c5317fee09aee2cdc4ca3aaa2dd3e3 100644 (file)
@@ -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);
 }