make pthread stacks non-executable
authorRich Felker <dalias@aerifal.cx>
Sat, 5 May 2012 02:51:59 +0000 (22:51 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 5 May 2012 02:51:59 +0000 (22:51 -0400)
this change is necessary or pthread_create will always fail on
security-hardened kernels. i considered first trying to make the stack
executable and simply retrying without execute permissions when the
first try fails, but (1) this would incur a serious performance
penalty on hardened systems, and (2) having the stack be executable is
just a bad idea from a security standpoint.

if there is real-world "GNU C" code that uses nested functions with
threads, and it can't be fixed, we'll have to consider other ways of
solving the problem, but for now this seems like the best fix.

src/thread/pthread_create.c

index c3b65ae..917be54 100644 (file)
@@ -104,7 +104,7 @@ int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(vo
                size = guard + ROUND(attr->_a_stacksize + DEFAULT_STACK_SIZE);
        }
        size += __pthread_tsd_size;
                size = guard + ROUND(attr->_a_stacksize + DEFAULT_STACK_SIZE);
        }
        size += __pthread_tsd_size;
-       map = mmap(0, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0);
+       map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
        if (map == MAP_FAILED) return EAGAIN;
        if (guard) mprotect(map, guard, PROT_NONE);
 
        if (map == MAP_FAILED) return EAGAIN;
        if (guard) mprotect(map, guard, PROT_NONE);