From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14226 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Re: [proposal] Add detection of thread ID in pthread-related interfaces Date: Tue, 11 Jun 2019 12:15:44 -0400 Message-ID: <20190611161544.GE1506@brightrain.aerifal.cx> References: <4CF320752F2B99449115298D4A06B22F34E3DD31@dggemm509-mbx.china.huawei.com> <20190611135741.GY16415@port70.net> <20190611143624.GA1506@brightrain.aerifal.cx> <2019061123563340760322@huawei.com> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="114808"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) Cc: "musl@lists.openwall.com" , helitao , "Huangqiang (H)" , Jinyongming , leijitang , "liuyutao (C)" , "Threefifteen Wang(Kunfeng)" , "Wudilong (Michael)" To: Li Yu Original-X-From: musl-return-14242-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jun 11 18:18:14 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hajTR-000Tjg-FX for gllmg-musl@m.gmane.org; Tue, 11 Jun 2019 18:18:13 +0200 Original-Received: (qmail 17504 invoked by uid 550); 11 Jun 2019 16:18:11 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 17486 invoked from network); 11 Jun 2019 16:18:11 -0000 Content-Disposition: inline In-Reply-To: <2019061123563340760322@huawei.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14226 Archived-At: On Tue, Jun 11, 2019 at 11:58:00PM +0800, Li Yu wrote: > > Thanks for your quick and detailed replies first. > > As our copy of POSIX 2003.1™-2017, it said such texts in RATIONALE section of pthread_cancel() feature, > > 'If an implementation detects use of a thread ID after the end of its lifetime, it is recommended > that the function should fail and report an [ESRCH] error. ' > > I think that it may be a recommended bebhavior in recent revison of POSIX spec. > > Another side, in real use cases, many applications are wrote under a > major libc implementation first, instead of be wrote according to > POSIX spec texts, so I personally think that compatiblity of libc > implementation is important than POSIX spec texts, always. In fact, > we don't have too many widely usable UNIX variants now. If it was written to glibc and relies on this behavior, you have an extremely dangerous use-after-free bug that was not caught. Under slightly different usage patterns, you could very well end up not getting an error, but instead cancelling, sending a signal to, detaching, or joining an unrelated thread that was created later. This has all of the cascading fault problems inherent in use-after-free, fd-use-after-close, etc. By crashing immediately, musl has alerted you to the issue and ensured that it gets fixed before something blows up in production. I've advocated a lot on this issue, and glibc has also adopted this convention based on text I wrote: https://sourceware.org/glibc/wiki/Style_and_Conventions#Invalid_pointers > Last,  I think that features of various libc implementations are > different is easy to understand and accept, however, someone are > crash for same feature is not welcome :) If we wanted to use musl as > a core libc in a open system to support various even third-party > closed-sources applications, the every new crash after porting new > system is not a good news. so, it seem that eveny such open system > need to maintain a in-house patch set to provide better robustness. You're looking at this backwards. You've gained the ability to immediately catch your dangerous bugs before you ship them rather than having them only show up when a particular race is hit. Rich