From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12342 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] track pthread stack guard sizes Date: Tue, 9 Jan 2018 12:22:04 -0500 Message-ID: <20180109172204.GY1627@brightrain.aerifal.cx> References: <20180106044443.14260-1-nenolod@dereferenced.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1515518428 2578 195.159.176.226 (9 Jan 2018 17:20:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 9 Jan 2018 17:20:28 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12358-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jan 09 18:20:24 2018 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.84_2) (envelope-from ) id 1eYxZX-0000PF-Fw for gllmg-musl@m.gmane.org; Tue, 09 Jan 2018 18:20:23 +0100 Original-Received: (qmail 3142 invoked by uid 550); 9 Jan 2018 17:22:20 -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 2013 invoked from network); 9 Jan 2018 17:22:16 -0000 Content-Disposition: inline In-Reply-To: <20180106044443.14260-1-nenolod@dereferenced.org> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12342 Archived-At: On Sat, Jan 06, 2018 at 04:44:43AM +0000, William Pitcock wrote: > some applications (rustc) are dependent on pthread_getattr_np() providing the guard size. > --- > src/internal/pthread_impl.h | 1 + > src/thread/pthread_create.c | 1 + > src/thread/pthread_getattr_np.c | 1 + > 3 files changed, 3 insertions(+) > > diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h > index 56e19348..c2cafeaa 100644 > --- a/src/internal/pthread_impl.h > +++ b/src/internal/pthread_impl.h > @@ -48,6 +48,7 @@ struct pthread { > void *stdio_locks; > uintptr_t canary_at_end; > void **dtv_copy; > + size_t guard_size; > }; > > struct __timer { > diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c > index 6cbf85b3..0faad765 100644 > --- a/src/thread/pthread_create.c > +++ b/src/thread/pthread_create.c > @@ -265,6 +265,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att > new->map_size = size; > new->stack = stack; > new->stack_size = stack - stack_limit; > + new->guard_size = guard; > new->start = entry; > new->start_arg = arg; > new->self = new; > diff --git a/src/thread/pthread_getattr_np.c b/src/thread/pthread_getattr_np.c > index ae26a5ab..29a209bd 100644 > --- a/src/thread/pthread_getattr_np.c > +++ b/src/thread/pthread_getattr_np.c > @@ -7,6 +7,7 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a) > { > *a = (pthread_attr_t){0}; > a->_a_detach = !!t->detached; > + a->_a_guardsize = t->guard_size; > if (t->stack) { > a->_a_stackaddr = (uintptr_t)t->stack; > a->_a_stacksize = t->stack_size; > -- > 2.15.0 I'm pretty sure there's another bug in this patch: the local variable guard is uninitialized where you use it if the application provided a stack and TLS was able to be allocated in the app-provided stack. The line guard = 0; above should probably just be moved down one line (and unindented one level). Does this sound right? Rich