mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "Zhang, Huilin (Rebecca) (CN)" <Rebecca.Zhang.CN@windriver.com>
To: Rich Felker <dalias@libc.org>, Markus Wichmann <nullplan@gmx.net>
Cc: "musl@lists.openwall.com" <musl@lists.openwall.com>,
	"Deng, Wenbin (CN)" <Wenbin.Deng.CN@windriver.com>
Subject: RE: [PATCH] __libc_exit_fini forgets to do pthread_mutex_unlock
Date: Thu, 3 Jul 2025 01:44:16 +0000	[thread overview]
Message-ID: <LV3PR11MB87430C87BEB322FE62892595DD43A@LV3PR11MB8743.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20250702143321.GI1827@brightrain.aerifal.cx>

Hello, Rich, Markus,

Thanks for your explanation. 

Yes, if we change "exit" to "_exit", the test case could exit normally.

OK, we accept it is really a deliberate omission.

Thanks,
Rebecca


-----Original Message-----
From: Rich Felker <dalias@libc.org> 
Sent: Wednesday, July 2, 2025 10:33 PM
To: Markus Wichmann <nullplan@gmx.net>
Cc: musl@lists.openwall.com; Zhang, Huilin (Rebecca) (CN) <Rebecca.Zhang.CN@windriver.com>; Deng, Wenbin (CN) <Wenbin.Deng.CN@windriver.com>
Subject: Re: [musl] [PATCH] __libc_exit_fini forgets to do pthread_mutex_unlock

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

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@windriver.com:
> > From: Rebecca Zhang <rebecca.zhang.cn@windriver.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


      reply	other threads:[~2025-07-03  1:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-02  2:28 [PATCH] __libc_exit_fini forgets to do pthread_mutex_unlock rebecca.zhang.cn
2025-07-02  4:30 ` Markus Wichmann
2025-07-02  6:06   ` [musl] " Zhang, Huilin (Rebecca) (CN)
2025-07-02  6:20     ` Deng, Wenbin (CN)
2025-07-02 14:18     ` Rich Felker
2025-07-02 14:33   ` Rich Felker
2025-07-03  1:44     ` Zhang, Huilin (Rebecca) (CN) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=LV3PR11MB87430C87BEB322FE62892595DD43A@LV3PR11MB8743.namprd11.prod.outlook.com \
    --to=rebecca.zhang.cn@windriver.com \
    --cc=Wenbin.Deng.CN@windriver.com \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=nullplan@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).