[4.1] e05e9f8 Use a separate segment for the sigaltstack

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Wed Sep 20 12:34:05 UTC 2017


commit e05e9f85d209ed9573ef4629991249b474523440
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Sep 4 19:55:10 2017 +0200

    Use a separate segment for the sigaltstack
    
    Having a stack on the heap just feels unclean, also this way we have a chance
    to get a red zone adjacent to the mapping just in case we manage to overflow
    the alt stack also.
    
    Ref: #2396

diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index 2477a5a..130790d 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -88,6 +88,7 @@ static struct vsb *child_panic = NULL;
 static double mgt_uptime_t0 = 0.;
 
 #ifdef HAVE_SIGALTSTACK
+#include <sys/mman.h>
 stack_t altstack;
 #endif
 
@@ -403,7 +404,10 @@ mgt_launch_child(struct cli *cli)
 			size_t sz = SIGSTKSZ + 4096;
 			if (sz < mgt_param.wthread_stacksize)
 				sz = mgt_param.wthread_stacksize;
-			altstack.ss_sp = malloc(sz);
+			altstack.ss_sp = mmap(NULL, sz,  PROT_READ | PROT_WRITE,
+					      MAP_PRIVATE | MAP_ANONYMOUS,
+					      -1, 0);
+			AN(altstack.ss_sp != MAP_FAILED);
 			AN(altstack.ss_sp);
 			altstack.ss_size = sz;
 			altstack.ss_flags = 0;


More information about the varnish-commit mailing list