Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 11 Jun 2019 12:09:31 -0400
From: Rich Felker <dalias@...c.org>
To: pengyuanhong <pengyuanhong@...wei.com>
Cc: "musl@...ts.openwall.com" <musl@...ts.openwall.com>,
	helitao <helitao@...wei.com>,
	"Huangqiang (H)" <h.huangqiang@...wei.com>,
	Jinyongming <jinyongming@...wei.com>,
	leijitang <leijitang@...wei.com>,
	"liuyutao (C)" <liuyutao2@...wei.com>,
	"Liyu (Marvin, Euler Dept)" <marvin.tms@...wei.com>,
	"Threefifteen Wang(Kunfeng)" <threefifteen.wangkunfeng@...wei.com>,
	"Wudilong (Michael)" <wudilong@...wei.com>
Subject: Re: [proposal] Add detection of thread ID in pthread-related
 interfaces

On Tue, Jun 11, 2019 at 11:36:59AM +0000, pengyuanhong wrote:
> Hello,
> 
> 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
> put all threads in a list or hash table, and update this list or table every
> time a thread is created or exits.

This description of why glibc returns ESRCH is incorrect; it has
nothing to do with keeping a list, which would require >O(1) lookup
and global synchronization on each operation referring to a thread id.
Rather, they just don't free exited threads, but keep the memory
cached to reuse for future calls to pthread_create with a marker that
it's not currently live. This allows trivial detection and reporting
that the id is not currently valid, but also encourages rapid reuse of
the same ids that were just freed, making use-after-free bugs with
pthread_t's much more dangerous.

Rich

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.