[ccan] [PATCH 1/4] altstack: Increase signal stack size

David Gibson david at gibson.dropbear.id.au
Tue Feb 16 17:09:22 AEDT 2016


At present the altstack module uses a stack of size MINSIGSTKSZ for its
SIGSEGV handler.  Although MINSIGSTKSZ is defined to be large enough to
execute a signal handler, it doesn't guarantee that you can do anything
very much within it.

With certain libc versions, MINSIGSTKSZ is not enough to execute the
longjmp() used in altstack.  Specfically, with Ubuntu 12.04 (the default
install for Travis containers), the first time longjmp() is executed the
symbol must be resolved by the dynamic linker in a process which overruns
the MINSIGSTKSZ sized stack.  That then corrupts local variables in
altstack() itself causing a number of subsequent failures.

This patch addresses the problem by changing from MINSIGSTKSZ to SIGSTKSZ
which is supposed to cover "the usual requirements for an alternate signal
stack".

Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 ccan/altstack/altstack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ccan/altstack/altstack.c b/ccan/altstack/altstack.c
index 67f457b..640344d 100644
--- a/ccan/altstack/altstack.c
+++ b/ccan/altstack/altstack.c
@@ -92,7 +92,7 @@ int altstack(rlim_t max, void *(*fn)(void *), void *arg, void **out)
 	undo++;
 
 	if (setjmp(jmp) == 0) {
-		unsigned char sigstk[MINSIGSTKSZ];
+		unsigned char sigstk[SIGSTKSZ];
 		stack_t ss = { .ss_sp = sigstk, .ss_size = sizeof(sigstk) };
 		struct sigaction sa = { .sa_handler = segvjmp, .sa_flags = SA_NODEFER|SA_RESETHAND|SA_ONSTACK };
 
-- 
2.5.0



More information about the ccan mailing list