Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 14 Jan 2016 17:41:15 -0500
From: Rich Felker <>
Subject: Re: dlopen deadlock

On Wed, Jan 13, 2016 at 12:09:37PM +0100, Szabolcs Nagy wrote:
> This bug i reported against glibc also affects musl:
> in case of musl it's not the global load lock, but the
> init_fini_lock that causes the problem.

The deadlock happens when a ctor makes a thread that calls dlopen and
does not return until the new thread's dlopen returns, right?

> the multi-threadedness detection is also problematic in
> do_init_fini:
> 	need_locking = has_threads
> 	if (need_locking)
> 		lock(init_fini_lock)
> 	for all deps
> 		run_ctors(dep)
> 		if (!need_locking && has_threads)
> 			need_locking = 1
> 			lock(init_fini_lock)
> 	if (need_locking)
> 		unlock(init_fini_lock)
> checking for threads after ctors are run is too late if
> the ctors may start new threads that can dlopen libs with
> common deps with the currently loaded lib.

The logic seems unnecessary now that there's no lazy/optional thread
pointer initialization (originally it was a problem because
pthread_mutex_lock with a recursive mutex needed to access TLS for the
owner tid, but TLS might not have been initialized when the ctors ran)
but I don't immediately see how it's harmful. The only state the lock
protects is p->constructed and the fini chain (fini_head,
p->fini_next) which are all used before the ctors run. The need for
locking is re-evaluated after the ctors run.

> one solution i can think of is to have an init_fini_lock
> for each dso, then the deadlock only happens if a ctor
> tries to dlopen its own lib (directly or indirectly)
> which is nonsense (the library depends on itself being
> loaded)

The lock has to protect the fini chain linked list (used to control
order of dtors) so I don't think having it be per-dso is a


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.