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 #14683: Static dlopen abort on $ORIGIN


Hi,

Since statically linked apps include vDSO in link map now, static
dlopen aborts on $ORIGIN.  This patch checks if caller is really in
caller map if SHARED isn't defined.  Tested on x86-64 with expected
failure:

[hjl@gnu-tools-1 build-x86_64-linux]$ cat
/export/build/gnu/glibc-test/build-x86_64-linux/elf/tst-leaks1-static-mem

Memory not freed:
-----------------
           Address     Size     Caller
0x00000000018971d0     0x34  at 0x420128
[hjl@gnu-tools-1 build-x86_64-linux]$ 

due to

http://www.sourceware.org/bugzilla/show_bug.cgi?id=14681

OK to install?

Thanks.

H.J.
---
2012-10-07  H.J. Lu  <hongjiu.lu@intel.com>

	[BZ #14683]
	* elf/Makefile (tests-static): Add tst-leaks1-static.
	(tests): Also depend on $(objpfx)tst-leaks1-static-mem.
	($(objpfx)tst-leaks1-static): New rule.
	($(objpfx)tst-leaks1-static-mem): Likewise.
	(tst-leaks1-static-ENV): New macro.
	* elf/dl-open.c (dl_open_worker): Check for vDSO if SHARED
	isn't defined.
	* elf/tst-leaks1-static.c: New file.

diff --git a/elf/Makefile b/elf/Makefile
index e91c3b4..dde9409 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -119,7 +119,8 @@ tests = tst-tls1 tst-tls2 tst-tls9 tst-leaks1
 ifeq (yes,$(have-initfini-array))
 tests += tst-array1 tst-array2 tst-array3 tst-array4 tst-array5
 endif
-tests-static = tst-tls1-static tst-tls2-static tst-stackguard1-static
+tests-static = tst-tls1-static tst-tls2-static tst-stackguard1-static \
+	       tst-leaks1-static
 ifeq (yes,$(build-shared))
 tests-static += tst-tls9-static
 tst-tls9-static-ENV = \
@@ -161,7 +162,8 @@ endif
 endif
 endif
 ifeq ($(cross-compiling),no)
-tests: $(objpfx)tst-leaks1-mem $(objpfx)noload-mem
+tests: $(objpfx)tst-leaks1-mem $(objpfx)tst-leaks1-static-mem \
+       $(objpfx)noload-mem
 endif
 tlsmod17a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 tlsmod18a-suffixes = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
@@ -1051,7 +1053,12 @@ $(objpfx)tst-leaks1: $(libdl)
 $(objpfx)tst-leaks1-mem: $(objpfx)tst-leaks1.out
 	$(common-objpfx)malloc/mtrace $(objpfx)tst-leaks1.mtrace > $@
 
+$(objpfx)tst-leaks1-static: $(common-objpfx)dlfcn/libdl.a
+$(objpfx)tst-leaks1-static-mem: $(objpfx)tst-leaks1-static.out
+	$(common-objpfx)malloc/mtrace $(objpfx)tst-leaks1-static.mtrace > $@
+
 tst-leaks1-ENV = MALLOC_TRACE=$(objpfx)tst-leaks1.mtrace
+tst-leaks1-static-ENV = MALLOC_TRACE=$(objpfx)tst-leaks1-static.mtrace
 
 $(objpfx)tst-addr1: $(libdl)
 
diff --git a/elf/dl-open.c b/elf/dl-open.c
index 5149e57..ed7d76e 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -206,6 +206,14 @@ dl_open_worker (void *a)
 	      goto found_caller;
 	    }
 
+#ifndef SHARED
+	  /* In statically linked apps there might be only vDSO.  */
+	  if (call_map
+	      && (caller_dlopen < (const void *) call_map->l_map_start
+		  || caller_dlopen >= (const void *) call_map->l_map_end))
+	    call_map = NULL;
+#endif
+
     found_caller:
       if (args->nsid == __LM_ID_CALLER)
 	{
diff --git a/elf/tst-leaks1-static.c b/elf/tst-leaks1-static.c
new file mode 100644
index 0000000..b956d66
--- /dev/null
+++ b/elf/tst-leaks1-static.c
@@ -0,0 +1 @@
+#include "tst-leaks1.c"


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