Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250702143321.GI1827@brightrain.aerifal.cx>
Date: Wed, 2 Jul 2025 10:33:21 -0400
From: Rich Felker <dalias@...c.org>
To: Markus Wichmann <nullplan@....net>
Cc: musl@...ts.openwall.com, rebecca.zhang.cn@...driver.com,
	wenbin.deng.cn@...driver.com
Subject: Re: [PATCH] __libc_exit_fini forgets to do
 pthread_mutex_unlock

On Wed, Jul 02, 2025 at 06:30:33AM +0200, Markus Wichmann wrote:
> Am Wed, Jul 02, 2025 at 10:28:54AM +0800 schrieb rebecca.zhang.cn@...driver.com:
> > From: Rebecca Zhang <rebecca.zhang.cn@...driver.com>
> > 
> > This commit fixes the issue that __libc_exit_fini only do
> > pthread_mutex_lock, but forget to do pthread_mutex_unlock.
> > ---
> >  ldso/dynlink.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/ldso/dynlink.c b/ldso/dynlink.c
> > index ceca3c9..7885675 100644
> > --- a/ldso/dynlink.c
> > +++ b/ldso/dynlink.c
> > @@ -1492,6 +1492,7 @@ void __libc_exit_fini()
> >  			fpaddr(p, dyn[DT_FINI])();
> >  #endif
> >  	}
> > +	pthread_mutex_unlock(&init_fini_lock);
> >  }
> >  
> >  void __ldso_atfork(int who)
> > -- 
> > 2.34.1
> > 
> I think that is a deliberate omision. __libc_exit_fini() is called on
> process exit. After it runs, it must not run again, and no new
> initializer must run at all. The process will exit very soon anyway. The
> only way to deadlock here is if a destructor calls exit(), which they
> aren't allowed to do.

It is very much deliberate that this lock is never released. Similarly
with a number of other locks they did not seem to notice that would
cause the same behavior even if this one was changed. The general
pattern is "a contractual requirement of exit is that all things of
category X have finished before the process terminates", and this
necessitates ensuring that no new "things of category X" can come into
existence once you're past the step where they're processed.

Other examples include flushing stdio (must not allow any new data to
become buffered after flush is complete) and processing atexit
handlers (must not allow a new handler to be registered after the loop
that runs them).

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.