mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Li Yu <marvin.tms@huawei.com>
Cc: "musl@lists.openwall.com" <musl@lists.openwall.com>,
	helitao <helitao@huawei.com>,
	"Huangqiang (H)" <h.huangqiang@huawei.com>,
	Jinyongming <jinyongming@huawei.com>,
	leijitang <leijitang@huawei.com>,
	"liuyutao (C)" <liuyutao2@huawei.com>,
	"Threefifteen Wang(Kunfeng)"
	<threefifteen.wangkunfeng@huawei.com>,
	"Wudilong (Michael)" <wudilong@huawei.com>
Subject: Re: Re: [proposal] Add detection of thread ID in pthread-related interfaces
Date: Tue, 11 Jun 2019 12:15:44 -0400	[thread overview]
Message-ID: <20190611161544.GE1506@brightrain.aerifal.cx> (raw)
In-Reply-To: <2019061123563340760322@huawei.com>

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


  reply	other threads:[~2019-06-11 16:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11 11:36 pengyuanhong
2019-06-11 13:57 ` Szabolcs Nagy
2019-06-11 14:36   ` Rich Felker
2019-06-11 15:58     ` Li Yu
2019-06-11 16:15       ` Rich Felker [this message]
2019-06-11 16:09 ` 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=20190611161544.GE1506@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=h.huangqiang@huawei.com \
    --cc=helitao@huawei.com \
    --cc=jinyongming@huawei.com \
    --cc=leijitang@huawei.com \
    --cc=liuyutao2@huawei.com \
    --cc=marvin.tms@huawei.com \
    --cc=musl@lists.openwall.com \
    --cc=threefifteen.wangkunfeng@huawei.com \
    --cc=wudilong@huawei.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).