freebsd-dev/libexec/rtld-elf
Konstantin Belousov b8fc1b23be If dlopen() is called for the dso that has been already loaded as a
dependency, then the dso never has its DAG initialized. Empty DAG
makes ref_dag() call in dlopen() a nop, and the dso refcount is off
by one.

Initialize the DAG on the first dlopen() call, using a boolean flag
to prevent double initialization.

From the PR (edited):
Assume we have a library liba.so, containing a function a(), and a
library libb.so, containing function b(). liba.so needs functionality
from libb.so, so liba.so links in libb.so.

An application doesn't know about the relation between these libraries,
but needs to call a() and b(). It dlopen()s liba.so and obtains a
pointer to a(), then it dlopen()s libb.so and obtains a pointer to b().

As soon as the application doesn't need a() anymore, it dlclose()s liba.so.

Expected result: the pointer to b() is still valid and can be called
Actual result: the pointer to b() has become invalid, even though the
application did not dlclose() the handle to libb.so. On calling b(), the
application crashes with a segmentation fault.

PR:	misc/151861
Based on patch by:	jh
Reviewed by:	kan
Tested by:	Arjan van Leeuwen <freebsd-maintainer opera com>
MFC after:	1 week
2010-11-03 09:23:08 +00:00
..
amd64 MFtbemd: 2010-08-23 22:24:11 +00:00
arm Only use the cache after the early stage of loading. This is 2010-05-18 08:55:23 +00:00
i386 MFtbemd: 2010-08-23 22:24:11 +00:00
ia64 Unbreak ia64. 2010-10-22 04:43:04 +00:00
mips Add parentheses around the argument 'x' used in the __bswapXX(x) macros. Revert 2010-08-11 02:28:39 +00:00
powerpc Fix two subtle problems in PPC32 RTLD. The first is a concurrency issue 2010-10-04 16:02:11 +00:00
powerpc64 Check for undefined weak symbols during PLT binding on powerpc64, and do 2010-09-12 17:04:51 +00:00
sparc64 Only use the cache after the early stage of loading. This is 2010-05-18 08:55:23 +00:00
debug.c Fix warnings on 64 bit platforms. 2003-06-19 16:09:18 +00:00
debug.h Use C99's varadic macro syntax instead of gcc's. 2006-03-28 18:26:47 +00:00
libmap.c Fix a malloc overrun in 32-bit compat libmap lookup code. 2006-01-31 06:08:28 +00:00
libmap.h Description from Dan: 2005-02-04 02:46:41 +00:00
Makefile Unbreak ia64. 2010-10-22 04:43:04 +00:00
malloc.c Use the newly provided aux vectors to get pagesize and osreldate information. 2010-08-17 09:05:39 +00:00
map_object.c In rtld's map_object(), use pread(..., 0) rather than read() to read the 2009-10-06 17:14:39 +00:00
rtld_lock.c Prefer <sys/param.h> to <machine/param.h> for the definition of 2009-04-20 10:35:50 +00:00
rtld_lock.h Provide custom simple allocator for rtld locks in libthr. The allocator 2008-12-02 11:58:31 +00:00
rtld_tls.h Add support for Thread Local Storage. 2004-08-03 08:51:00 +00:00
rtld.1 mdoc: drop redundant .Pp and .LP calls 2010-10-08 12:40:16 +00:00
rtld.c If dlopen() is called for the dso that has been already loaded as a 2010-11-03 09:23:08 +00:00
rtld.h If dlopen() is called for the dso that has been already loaded as a 2010-11-03 09:23:08 +00:00
Symbol.map Introduce implementation-private rtld interface _rtld_addr_phdr, which 2010-08-23 15:27:03 +00:00
xmalloc.c Add function prototypes. 2003-06-19 05:28:26 +00:00