linux-mips
[Top] [All Lists]

[PATCH] User stack pointer randomisation

To: Ralf Baechle <ralf@linux-mips.org>
Subject: [PATCH] User stack pointer randomisation
From: Franck Bui-Huu <vagabon.xyz@gmail.com>
Date: Thu, 19 Jul 2007 14:04:21 +0200
Cc: nigel@mips.com, linux-mips <linux-mips@linux-mips.org>
Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:reply-to:user-agent:mime-version:to:cc:subject:x-enigmail-version:content-type:content-transfer-encoding:from; b=UKWo6bCz0EXUrlOTuHLpuSIZGBoqNI26CvpD2+D3acXxKmHDCYC4DjdFGQYaF1BokU33z+t1HlzMWnFR3OOs4ynDuOGjjQt388bFmDIboFUFD51zLgKbLpfKp1TMkB/37cTSwEEBIkuuvPEPf6gIao/YZKsYjlyV9pjGBTy03sM=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:reply-to:user-agent:mime-version:to:cc:subject:x-enigmail-version:content-type:content-transfer-encoding:from; b=F9zW5QnQlwR+gmHHYnEqtTZVNTwUXw8hhNnc019ocY3FF8bjA19/riZXxihedAxXOkEdudsdL2/5Kp9NOWwg4EBKoAbisUxdHZYXdR/UNojUD6X8quSq3YSrWgZbHukbtt7TfBQPFz/a9Xpx3FEYXZV26HpWCxl8UPPgvmlqevE=
Original-recipient: rfc822;linux-mips@linux-mips.org
Reply-to: franck.bui-huu@innova-card.com
Sender: linux-mips-bounce@linux-mips.org
User-agent: Thunderbird 1.5.0.4 (X11/20060614)
From: Franck Bui-Huu <fbuihuu@gmail.com>

This patch adds a page size range randomisation to the user
stack pointer.

Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>
---

  Hi Ralf,

 This is taken from the x86 architecture. I modified it a bit so the
 randomisation range is only a page size range. Since the top of the
 stack is already randomised, I don't see any point to make the range
 bigger as this is the case in x86 arch.

 I tested it and it works fine so far.

 Please try to have a look,

                Franck

 arch/mips/kernel/process.c |   14 ++++++++++++++
 include/asm-mips/system.h  |    2 +-
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 6bdfb5a..42a60b4 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -25,7 +25,9 @@
 #include <linux/init.h>
 #include <linux/completion.h>
 #include <linux/kallsyms.h>
+#include <linux/random.h>
 
+#include <asm/asm.h>
 #include <asm/bootinfo.h>
 #include <asm/cpu.h>
 #include <asm/dsp.h>
@@ -460,3 +462,15 @@ unsigned long get_wchan(struct task_struct *task)
 out:
        return pc;
 }
+
+/*
+ * Don't forget that the stack pointer must be aligned on a 8 bytes
+ * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
+ */
+unsigned long arch_align_stack(unsigned long sp)
+{
+       if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
+               sp -= get_random_int() & ~PAGE_MASK;
+
+       return sp & ALMASK;
+}
diff --git a/include/asm-mips/system.h b/include/asm-mips/system.h
index 2908870..0cfb6e1 100644
--- a/include/asm-mips/system.h
+++ b/include/asm-mips/system.h
@@ -355,6 +355,6 @@ extern int stop_a_enabled;
  */
 #define __ARCH_WANT_UNLOCKED_CTXSW
 
-#define arch_align_stack(x) (x)
+extern unsigned long arch_align_stack(unsigned long sp);
 
 #endif /* _ASM_SYSTEM_H */
-- 
1.5.2.2



<Prev in Thread] Current Thread [Next in Thread>