This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] BZ #14831: Segfault in _dl_profile_fixup with IRELATIVE andLD_AUDIT


Hi,

If libm.so has IRELATIVE relocations, audit will segfault when
executables are linked with libm.so.  This patch skips audit if
l_reloc_result is NULL.  Tested on x32, ia32 and x86-64.  OK for
master and 2.16 branch?

Targets which define ELF_MACHINE_RUNTIME_FIXUP_ARGS must find a way
to pass ELF_MACHINE_RUNTIME_FIXUP_ARGS from _dl_fixup/_dl_profile_fixup
to _dl_runtime_fixup.

Thanks.


H.J.
---
 elf/Makefile     |  6 +++++-
 elf/dl-runtime.c | 26 ++++++++++++++++++++++++--
 elf/tst-audit8.c |  1 +
 4 files changed, 43 insertions(+), 3 deletions(-)
 create mode 100644 ChangeLog.hjl
 create mode 100644 elf/tst-audit8.c

2012-11-12  H.J. Lu  <hongjiu.lu@intel.com>

	[BZ #14831]
	* elf/Makefile (tests): Add tst-audit8.
	($(objpfx)tst-audit8): Also depend on $(common-objpfx)math/libm.so.
	($(objpfx)tst-audit8.out): New target.
	(tst-audit8-ENV): New variable.
	* elf/dl-runtime.c (_dl_fixup): Renamed to ...
	(_dl_runtime_fixup): This.  Make it static and always inline.
	(_dl_fixup): New function.  Use _dl_runtime_fixup.
	(_dl_profile_fixup): Call _dl_runtime_fixup to skip audit if
	l_reloc_result is NULL.
	* elf/tst-audit8.c: New file.

diff --git a/elf/Makefile b/elf/Makefile
index c2f0e20..7e5c9c8 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -142,7 +142,7 @@ tests += loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
 	 tst-dlmodcount tst-dlopenrpath tst-deep1 \
 	 tst-dlmopen1 tst-dlmopen2 tst-dlmopen3 \
 	 unload3 unload4 unload5 unload6 unload7 unload8 tst-global1 order2 \
-	 tst-audit1 tst-audit2 \
+	 tst-audit1 tst-audit2 tst-audit8 \
 	 tst-stackguard1 tst-addr1 tst-thrlock \
 	 tst-unique1 tst-unique2 tst-unique3 tst-unique4 \
 	 tst-initorder tst-initorder2 tst-relsort1
@@ -1020,6 +1020,10 @@ $(objpfx)tst-audit7: $(objpfx)tst-auditmod7a.so
 $(objpfx)tst-audit7.out: $(objpfx)tst-auditmod7b.so
 tst-audit7-ENV = LD_AUDIT=$(objpfx)tst-auditmod7b.so
 
+$(objpfx)tst-audit8: $(common-objpfx)math/libm.so
+$(objpfx)tst-audit8.out: $(objpfx)tst-auditmod1.so
+tst-audit8-ENV = LD_AUDIT=$(objpfx)tst-auditmod1.so
+
 $(objpfx)tst-global1: $(libdl)
 $(objpfx)tst-global1.out: $(objpfx)testobj6.so $(objpfx)testobj2.so
 
diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c
index 2e02a21..7704027 100644
--- a/elf/dl-runtime.c
+++ b/elf/dl-runtime.c
@@ -57,9 +57,10 @@
    function.  */
 
 #ifndef ELF_MACHINE_NO_PLT
+static inline
 DL_FIXUP_VALUE_TYPE
-__attribute ((noinline)) ARCH_FIXUP_ATTRIBUTE
-_dl_fixup (
+__attribute ((always_inline)) ARCH_FIXUP_ATTRIBUTE
+_dl_runtime_fixup (
 # ifdef ELF_MACHINE_RUNTIME_FIXUP_ARGS
 	   ELF_MACHINE_RUNTIME_FIXUP_ARGS,
 # endif
@@ -150,6 +151,19 @@ _dl_fixup (
 
   return elf_machine_fixup_plt (l, result, reloc, rel_addr, value);
 }
+
+DL_FIXUP_VALUE_TYPE
+__attribute ((noinline)) ARCH_FIXUP_ATTRIBUTE
+_dl_fixup (
+# ifdef ELF_MACHINE_RUNTIME_FIXUP_ARGS
+	   ELF_MACHINE_RUNTIME_FIXUP_ARGS,
+# endif
+	   /* GKM FIXME: Fix trampoline to pass bounds so we can do
+	      without the `__unbounded' qualifier.  */
+	   struct link_map *__unbounded l, ElfW(Word) reloc_arg)
+{
+  return _dl_runtime_fixup (l, reloc_arg);
+}
 #endif
 
 #if !defined PROF && !defined ELF_MACHINE_NO_PLT && !__BOUNDED_POINTERS__
@@ -164,6 +178,14 @@ _dl_profile_fixup (
 {
   void (*mcount_fct) (ElfW(Addr), ElfW(Addr)) = INTUSE(_dl_mcount);
 
+  if (l->l_reloc_result == NULL)
+    {
+      /* Skip audit if l_reloc_result is NULL which happens with
+	 IRELATIVE relocations in other DSOs, like libm.so.  */ 
+      *framesizep = -1;
+      return _dl_runtime_fixup (l, reloc_arg);
+    }
+
   /* This is the address in the array where we store the result of previous
      relocations.  */
   struct reloc_result *reloc_result = &l->l_reloc_result[reloc_index];
diff --git a/elf/tst-audit8.c b/elf/tst-audit8.c
new file mode 100644
index 0000000..63656b4
--- /dev/null
+++ b/elf/tst-audit8.c
@@ -0,0 +1 @@
+#include "../io/pwd.c"
-- 
1.7.11.7


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]