This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] posix_spawn: use a larger min stack for -fstack-check [BZ #21253]
- From: Florian Weimer <fweimer at redhat dot com>
- To: Mike Frysinger <vapier at gentoo dot org>, libc-alpha at sourceware dot org
- Cc: adhemerval dot zanella at linaro dot org
- Date: Thu, 16 Mar 2017 09:17:16 +0100
- Subject: Re: [PATCH] posix_spawn: use a larger min stack for -fstack-check [BZ #21253]
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3957280467
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3957280467
- References: <20170316073012.22763-1-vapier@gentoo.org>
On 03/16/2017 08:30 AM, Mike Frysinger wrote:
When glibc is built with -fstack-check, trying to use posix_spawn can
lead to segfaults due to gcc internally probing stack memory too far.
The new spawn API will allocate a minimum of 1 page, but the stack
checking logic might probe a couple of pages. When it tries to walk
them, everything falls apart.
The gcc internal docs [1] state the default interval checking is one
page. Which means we need two pages (the current one, and the next
probed). No target currently defines it larger.
GCC miscomputes the offsets in some cases, so I would not rely on this.
Would it be possible compile the functions involved without
-fstack-check instead?
/* Add a slack area for child's stack. */
size_t argv_size = (argc * sizeof (void *)) + 512;
- size_t stack_size = ALIGN_UP (argv_size, GLRO(dl_pagesize));
+ /* We need at least a few pages in case the compiler's stack checking is
+ enabled. In some configs, it is known to use at least 24KiB. */
+ size_t stack_size = ALIGN_UP (argv_size, 32 * 1024);
64 KiB pages are common, so this reduces the stack size in many cases.
Thanks,
Florian