Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2da3840a9345c0a810e9d93ab4f6bca7@ispras.ru>
Date: Sat, 11 Feb 2023 20:50:15 +0300
From: Alexey Izbyshev <izbyshev@...ras.ru>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] mq_notify: fix close/recv race on failure path

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.

Thanks,
Alexey

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.