[haiku-commits] haiku: hrev46101 - src/system/kernel/arch/x86/64 src/system/kernel/arch/x86/32 headers/posix

  • From: pdziepak@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 21 Sep 2013 21:57:29 +0200 (CEST)

hrev46101 adds 1 changeset to branch 'master'
old head: 18ad64f2272bb01767870a2f05f7a94065769418
new head: afaa6ed4b37c519afd3f593509fd490082d7b8d2
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=afaa6ed+%5E18ad64f

----------------------------------------------------------------------------

afaa6ed: 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.

                                    [ Pawel Dziepak <pdziepak@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev46101
Commit:      afaa6ed4b37c519afd3f593509fd490082d7b8d2
URL:         http://cgit.haiku-os.org/haiku/commit/?id=afaa6ed
Author:      Pawel Dziepak <pdziepak@xxxxxxxxxxx>
Date:        Sat Sep 21 19:52:13 2013 UTC

----------------------------------------------------------------------------

3 files changed, 23 insertions(+), 21 deletions(-)
headers/posix/signal.h                   |  2 +-
src/system/kernel/arch/x86/32/thread.cpp | 21 +++++++++++----------
src/system/kernel/arch/x86/64/thread.cpp | 21 +++++++++++----------

----------------------------------------------------------------------------

diff --git a/headers/posix/signal.h b/headers/posix/signal.h
index 7415cfe..d56cf2e 100644
--- a/headers/posix/signal.h
+++ b/headers/posix/signal.h
@@ -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 */
diff --git a/src/system/kernel/arch/x86/32/thread.cpp 
b/src/system/kernel/arch/x86/32/thread.cpp
index 66465c2..7bed6a0 100644
--- a/src/system/kernel/arch/x86/32/thread.cpp
+++ b/src/system/kernel/arch/x86/32/thread.cpp
@@ -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
diff --git a/src/system/kernel/arch/x86/64/thread.cpp 
b/src/system/kernel/arch/x86/64/thread.cpp
index e1a337f..59db502 100644
--- a/src/system/kernel/arch/x86/64/thread.cpp
+++ b/src/system/kernel/arch/x86/64/thread.cpp
@@ -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


Other related posts:

  • » [haiku-commits] haiku: hrev46101 - src/system/kernel/arch/x86/64 src/system/kernel/arch/x86/32 headers/posix - pdziepak