x86[_64]: Randomize initial stack pointer on alternative signal stacks

If the alternate signal stack is used randomize the initial stack
pointer in the same way it is randomized on "normal" thread stacks.
Also, update MINSIGSTKSZ value so that regardless of where the new
stack pointer points to there is at least 4k of stack left.
This commit is contained in:
Pawel Dziepak 2013-09-21 21:52:13 +02:00
parent 18ad64f227
commit afaa6ed4b3
3 changed files with 23 additions and 21 deletions

View File

@ -95,7 +95,7 @@ struct sigaction {
#define SS_ONSTACK 0x1
#define SS_DISABLE 0x2
#define MINSIGSTKSZ 4096
#define MINSIGSTKSZ 8192
#define SIGSTKSZ 16384
/* for signals using an alternate stack */

View File

@ -110,6 +110,15 @@ x86_set_tls_context(Thread *thread)
}
static addr_t
arch_randomize_stack_pointer(addr_t value)
{
STATIC_ASSERT(MAX_RANDOM_VALUE >= B_PAGE_SIZE - 1);
value -= random_value() & (B_PAGE_SIZE - 1);
return value & ~addr_t(0xf);
}
static uint8*
get_signal_stack(Thread* thread, struct iframe* frame, struct sigaction* action)
{
@ -119,7 +128,8 @@ get_signal_stack(Thread* thread, struct iframe* frame, struct sigaction* action)
&& (frame->user_sp < thread->signal_stack_base
|| frame->user_sp >= thread->signal_stack_base
+ thread->signal_stack_size)) {
return (uint8*)(thread->signal_stack_base + thread->signal_stack_size);
addr_t stackTop = thread->signal_stack_base + thread->signal_stack_size;
return (uint8*)arch_randomize_stack_pointer(stackTop);
}
return (uint8*)frame->user_sp;
@ -202,15 +212,6 @@ arch_thread_dump_info(void *info)
}
static addr_t
arch_randomize_stack_pointer(addr_t value)
{
STATIC_ASSERT(MAX_RANDOM_VALUE >= B_PAGE_SIZE - 1);
value -= random_value() & (B_PAGE_SIZE - 1);
return value & ~addr_t(0xf);
}
/*! Sets up initial thread context and enters user space
*/
status_t

View File

@ -95,6 +95,15 @@ x86_set_tls_context(Thread* thread)
}
static addr_t
arch_randomize_stack_pointer(addr_t value)
{
STATIC_ASSERT(MAX_RANDOM_VALUE >= B_PAGE_SIZE - 1);
value -= random_value() & (B_PAGE_SIZE - 1);
return value & ~addr_t(0xf);
}
static uint8*
get_signal_stack(Thread* thread, iframe* frame, struct sigaction* action)
{
@ -104,7 +113,8 @@ get_signal_stack(Thread* thread, iframe* frame, struct sigaction* action)
&& (frame->user_sp < thread->signal_stack_base
|| frame->user_sp >= thread->signal_stack_base
+ thread->signal_stack_size)) {
return (uint8*)(thread->signal_stack_base + thread->signal_stack_size);
addr_t stackTop = thread->signal_stack_base + thread->signal_stack_size;
return (uint8*)arch_randomize_stack_pointer(stackTop);
}
// We are going to use the stack that we are already on. We must not touch
@ -198,15 +208,6 @@ arch_thread_dump_info(void* info)
}
static addr_t
arch_randomize_stack_pointer(addr_t value)
{
STATIC_ASSERT(MAX_RANDOM_VALUE >= B_PAGE_SIZE - 1);
value -= random_value() & (B_PAGE_SIZE - 1);
return value & ~addr_t(0xf);
}
/*! Sets up initial thread context and enters user space
*/
status_t