![]() |
|
Message-ID: <20250527190349.GQ1827@brightrain.aerifal.cx> Date: Tue, 27 May 2025 15:03:49 -0400 From: Rich Felker <dalias@...c.org> To: Markus Wichmann <nullplan@....net> Cc: musl@...ts.openwall.com Subject: Re: Deadlock in dynamic linker? On Tue, May 27, 2025 at 06:59:12PM +0200, Markus Wichmann wrote: > Am Tue, May 27, 2025 at 11:20:07AM -0400 schrieb Rich Felker: > > On Sat, May 24, 2025 at 07:45:45AM +0200, Markus Wichmann wrote: > > > I'm thinking something like this: Thread A initializes liba.so. liba.so > > > has initializers and finalizers, so thread A adds liba.so to the fini > > > list before calling the initializers. The liba initializer calls > > > dlopen("libb.so"). libb.so also has initializers. > > > > > > While thread A is not holding the init_fini_lock, thread B calls exit(). > > > That progresses until __libc_exit_fini() sets shutting_down to 1. Then > > > it tries to destroy all the libraries, but the loop stops when it comes > > > to liba. > > > > > > liba.so has a ctor_visitor, namely thread A, so thread B cannot advance. > > > Thread A meanwhile is hanging in the infinite wait loop trying to > > > initialize libb.so. The situation cannot change, and the process hangs > > > indefinitely. > > > > I see. In particular you're assuming the dlopen of libb happened after > > the exit started. > > > > I had completely neglected to look at the global ldso lock, actually. > But looking at it again, I am actually assuming that the dlopen() is > *starting* before the __libc_exit_fini() (so that thread B hangs waiting > for the lock), but that thread B then overtakes thread A between the > latter's release of the global lock and the taking of the init_fini_lock. > > This does mean that taking the init_fini_lock before releasing the > global lock would entirely prevent the issue. Not sure if that's > acceptable, though. No, it wouldn't, because the lock is released every time a condwait is done, and exit can start during any of those condwaits. Rich
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.