mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Alexey Izbyshev <izbyshev@ispras.ru>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] mq_notify: fix close/recv race on failure path
Date: Sat, 11 Feb 2023 12:59:49 -0500	[thread overview]
Message-ID: <20230211175948.GK4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <2da3840a9345c0a810e9d93ab4f6bca7@ispras.ru>

On Sat, Feb 11, 2023 at 08:50:15PM +0300, Alexey Izbyshev wrote:
> On 2023-02-11 20:13, Markus Wichmann wrote:
> >On Sat, Feb 11, 2023 at 10:06:03AM -0500, Rich Felker wrote:
> >>--- a/src/thread/pthread_detach.c
> >>+++ b/src/thread/pthread_detach.c
> >>@@ -5,8 +5,12 @@ static int __pthread_detach(pthread_t t)
> >> {
> >> 	/* If the cas fails, detach state is either already-detached
> >> 	 * or exiting/exited, and pthread_join will trap or cleanup. */
> >>-	if (a_cas(&t->detach_state, DT_JOINABLE, DT_DETACHED) !=
> >>DT_JOINABLE)
> >>+	if (a_cas(&t->detach_state, DT_JOINABLE, DT_DETACHED) !=
> >>DT_JOINABLE) {
> >>+		int cs;
> >>+		__pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
> >> 		return __pthread_join(t, 0);
> >                ^^^^^^ I think you forgot to rework this.
> >>+		__pthread_setcancelstate(cs, 0);
> >>+	}
> >> 	return 0;
> >> }
> >>
> >
> >I see no other obvious missteps, though.
> >
> Same here, apart from this and misspelled "pthred_detach" in the
> commit message, the patches look good to me.
> 
> Regarding the POSIX requirement to run sigev_notify_function in the
> context of a detached thread, while it's possible to observe the
> wrong detachstate for a short while via pthread_getattr_np after
> these patches, I'm not sure there is a standard way to do that. Even
> if it exists, this minor issue may be not worth caring about.

Would this just be if the notification callback executes before
mq_notify returns in the parent? I suppose we could have the newly
created thread do the work of making the syscall, handling the error
case, detaching itself on success and and reporting back to the
mq_notify function whether it succeeded or failed via the
semaphore/args structure. Thoughts on that?

Rich


  reply	other threads:[~2023-02-11 18:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 10:46 Alexey Izbyshev
2022-12-14  2:26 ` Rich Felker
2022-12-14  6:49   ` Alexey Izbyshev
2023-02-10 16:29     ` Rich Felker
2023-02-11 14:45       ` Alexey Izbyshev
2023-02-11 14:52         ` Rich Felker
2023-02-11 15:13           ` Alexey Izbyshev
2023-02-11 15:06         ` Rich Felker
2023-02-11 17:13           ` Markus Wichmann
2023-02-11 17:46             ` Rich Felker
2023-02-11 17:50             ` Alexey Izbyshev
2023-02-11 17:59               ` Rich Felker [this message]
2023-02-11 18:08                 ` Alexey Izbyshev
2023-02-11 18:35                   ` Rich Felker
2023-02-11 19:28                     ` Alexey Izbyshev
2023-02-11 19:49                       ` Rich Felker
2023-02-11 20:14                         ` Alexey Izbyshev
2023-02-12  0:32                           ` Rich Felker
2023-02-12 18:23                             ` Alexey Izbyshev
2023-02-12 19:35                               ` Alexey Izbyshev
2023-02-12 20:04                                 ` Rich Felker

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=20230211175948.GK4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=izbyshev@ispras.ru \
    --cc=musl@lists.openwall.com \
    /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).