segfault with pthread_cancel() and PTHREAD_STACK_MIN on armv7

Michael Weiser michael@weiser.dinsnail.net
Fri Feb 10 19:24:00 GMT 2017


Hi,

I run Gentoo Linux on Cubieboard2s (armv7v, le and be) with the
distribution's glibc-2.23. The whole system recompiled itself without
problems using gcc-6.3.0. This gcc is hardened, i.e. configured amongst
others with --enable-default-ssp.

Now I've run into a peculiar problem with pthreads, manifesting itself
in ntpd segfaulting upon startup. Turns out for very specific reasons
they spawn a thread doing an endless loop of sleep(10)'s and cancel
that. Also, they set the thread's stack size to PTHREAD_STACK_MIN.
(rationale and code can be seen here:
https://github.com/ntp-project/ntp/blob/stable/ntpd/ntpd.c#L252)

After isolating the code into the attached testcase I found that
increasing the thread's stack size by 6640 bytes or eliminating
pthread_cancel() altogehter both make the segfault go away.

The same testcase runs fine on an otherwise identical x86_64 install of
Gentoo compiled with the same kind of hardened gcc-6.3.0.

So I guess my question is: Is pthread_cancel() supposed to work with a
stack size of PTHREAD_STACK_MIN on every platform?

What might be causing my platform to require 6640 bytes more stack to
succeed?
-- 
Thanks,
Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pthread-cancel-stack.c
Type: text/x-c
Size: 966 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-help/attachments/20170210/adbc6c95/attachment.bin>


More information about the Libc-help mailing list