From d0bfc2b738314b89c64fa349b9a0dbd8a8d5fef6 Mon Sep 17 00:00:00 2001 From: Shawn Webb Date: Sun, 25 Jun 2017 22:54:56 -0400 Subject: [PATCH] Revert "HBSD: Randomize top of per-thread stacks" This reverts commit b7b19ffccfb139fc731dca94655b3531a50c61ca. The per-thread stack randomization needs more thought. It's likely that this implementation is being too aggressive. Signed-off-by: Shawn Webb (cherry picked from commit 5d741f44acf944a48dd14390fec663b42f962e96) (cherry picked from commit 233c617c4908a4249a70af89dcbea31575f0dc87) --- lib/libthr/thread/thr_init.c | 15 +-------------- lib/libthr/thread/thr_private.h | 12 ------------ 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index 4660627ef86..2f62619ce07 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -439,7 +439,6 @@ init_private(void) size_t len; int mib[2]; char *env, *env_bigstack, *env_splitstack; - unsigned int npages; _thr_umutex_init(&_mutex_static_lock); _thr_umutex_init(&_cond_static_lock); @@ -478,6 +477,7 @@ init_private(void) sysctlbyname("kern.smp.cpus", &_thr_is_smp, &len, NULL, 0); _thr_is_smp = (_thr_is_smp > 1); _thr_page_size = getpagesize(); + _thr_guard_default = (2 * 1024 * 1024); _pthread_attr_default.guardsize_attr = _thr_guard_default; _pthread_attr_default.stacksize_attr = _thr_stack_default; env = getenv("LIBPTHREAD_SPINLOOPS"); @@ -490,19 +490,6 @@ init_private(void) if (env) _thr_queuefifo = atoi(env); TAILQ_INIT(&_thr_atfork_list); - /* - * Initialize the random-sized stack guard - * conservatively. - */ - mib[0] = CTL_KERN; - mib[1] = KERN_ARND; - len = sizeof(npages); - npages = 0; - sysctl(mib, 2, &npages, &len, NULL, 0); - npages %= GUARD_MAX_PAGES; - if (npages < GUARD_MIN_PAGES) - npages = GUARD_DEFAULT_SIZE; - _thr_guard_default = npages * PAGE_SIZE; } init_once = 1; } diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index 78a74a32256..e61ee99dcb7 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -101,18 +101,6 @@ TAILQ_HEAD(mutex_queue, pthread_mutex); #define THR_ASSERT(cond, msg) #endif -#ifndef GUARD_DEFAULT_SIZE -#define GUARD_DEFAULT_SIZE 512 -#endif - -#ifndef GUARD_MIN_PAGES -#define GUARD_MIN_PAGES 256 -#endif - -#ifndef GUARD_MAX_PAGES -#define GUARD_MAX_PAGES 1024 -#endif - #ifdef PIC # define STATIC_LIB_REQUIRE(name) #else