From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32197 invoked from network); 30 Jun 2020 19:29:15 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 30 Jun 2020 19:29:15 -0000 Received: (qmail 5295 invoked by uid 550); 30 Jun 2020 19:29:07 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 5276 invoked from network); 30 Jun 2020 19:29:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samersoff.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=x+BZ7bwlZDOMXh9Ta6t6BvzD5R+eDrAiKjik5uiIfvA=; b=dCI9ZQ65ok55a9Kz+y/WX1edOZ 46L36pj04qqt5tHlFHVNZfQN3iH9B6CnP2v6/wPvCTMDZRVz+LoZZNlHC4xkLs9qQFzLdxlosZF9q mjgCG+SVKk47yt+5Pt/b/hjx85QFcmPueWLlVvwAoWgx8JPjxP/Y+SGvNcRQ6eYb3WCg=; To: musl@lists.openwall.com, Hydro Flask Cc: Markus Wichmann References: <0217b8838100175725993b0ed0114ee7@thelig.ht> <20200630044323.GD6430@brightrain.aerifal.cx> <20200630092644.GE6430@brightrain.aerifal.cx> <20200630145851.GD13001@voyager> <275470aa6820d420339929a1fe409d89@yqxmail.com> From: Dmitry Samersoff Message-ID: <477cc243-b950-3363-e9f4-4c8a203b6bea@samersoff.net> Date: Tue, 30 Jun 2020 22:28:50 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <275470aa6820d420339929a1fe409d89@yqxmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-As: dms X-SpamProbe: GOOD 0.0000591 357d73cc86887ee5f00c9fe58a5ccef6 Subject: Re: [musl] Potential deadlock in pthread_kill() Hello all, Does it make sense to trylock and immediately return ESRCH if pthread_kill is already in progress? -Dmitry On 30.06.2020 19:28, Hydro Flask wrote: > On 2020-06-30 07:58, Markus Wichmann wrote: >> On Tue, Jun 30, 2020 at 05:26:46AM -0400, Rich Felker wrote: >>> On Mon, Jun 29, 2020 at 11:19:39PM -0700, Hydro Flask wrote: >>> > >>> > Just to be clear, this doesn't only occur when calling >>> > pthread_kill() and using pthread_self() as the target, it can be any >>> > target thread, as long as it's the same target thread is used in the >>> > signal handler and in the synchronous context. >>> >>> How so? If the target is different, the rest of the pthread_kill, >>> including the unlock, will proceed concurrently with the signal >>> handler. However you may be able to construct mutual-signaling >>> deadlock cases. >>> >> >> Thread A calls pthread_kill(thread_c, ...). Thread B calls >> (concurrently) pthread_kill(thread_a, ...). Thread B's signal arrives >> while thread A holds the killlock. Signal handler calls >> pthread_kill(thread_c, ...). > > You can trigger it much more simply than that. Doesn't require multiple > threads: > > 1. pthread_kill(th) > 2. LOCK(killlock) > 3. > 4. signal handler: pthread_kill(th) > 5. signal handler: LOCK(killlock) > > In the preceding example "th" can be any pthread_t value, the only > requirement is that it's the same pthread_t in both the synchronous and > signal handler context.