mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Cc: helitao <helitao@huawei.com>,
	"Huangqiang (H)" <h.huangqiang@huawei.com>,
	Jinyongming <jinyongming@huawei.com>,
	leijitang <leijitang@huawei.com>,
	"liuyutao (C)" <liuyutao2@huawei.com>,
	"Liyu (Marvin, Euler Dept)" <marvin.tms@huawei.com>,
	"Threefifteen Wang(Kunfeng)"
	<threefifteen.wangkunfeng@huawei.com>,
	"Wudilong (Michael)" <wudilong@huawei.com>
Subject: Re: [proposal] Add detection of thread ID in pthread-related interfaces
Date: Tue, 11 Jun 2019 15:57:42 +0200	[thread overview]
Message-ID: <20190611135741.GY16415@port70.net> (raw)
In-Reply-To: <4CF320752F2B99449115298D4A06B22F34E3DD31@dggemm509-mbx.china.huawei.com>

* pengyuanhong <pengyuanhong@huawei.com> [2019-06-11 11:36:59 +0000]:
> I find that all pthread-related interfaces directly access the input
> parameter `pthread_t` without any check. If I pass an invalid thread ID
> (e.g. an exited thread ID) to these interfaces, then segment fault
> happens.
> 
> Both glibc and freebsd can do simple detection of thread ID(pthread_t)
> passed by user and return ESRCH when no thread can be found. They

that's a historical bug in posix: it required ESRCH
which is not possible when the thread id is reused,
so all such requirments were removed in posix 2008
https://collaboration.opengroup.org/austin/interps/documents/14366/AI-142.txt

passing invalid id is simply undefined now, an
implementation may still detect the condition and
then posix recommends ESRCH in the rationale
presumably for backward compatibility:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html

but since applications must not rely on ESRCH,
it has questionable value: the obvious safe and
secure handling of ub is guaranteed immediate
crash: the api contract got violated, the
application is misbehaving so there is no reason
to believe returning an error will make it
non-misbehave.

the only way forward is to fix the broken
application code, the runtime and tooling can
only help by providing better diagnostics
about what went wrong.

> put all threads in a list or hash table, and update this list or table every
> time a thread is created or exits.
> 
> >From the user's point of view, segment fault is unbearable and is not
> *         recoverable in most cases. Instead, returning an error of ESRCH
> *         seems more acceptable.


  reply	other threads:[~2019-06-11 13:57 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 [this message]
2019-06-11 14:36   ` Rich Felker
2019-06-11 15:58     ` Li Yu
2019-06-11 16:15       ` Rich Felker
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=20190611135741.GY16415@port70.net \
    --to=nsz@port70.net \
    --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).