From: Franck Bui-Huu <vagabon.xyz@gmail.com>
To: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips <linux-mips@linux-mips.org>
Subject: [RFC] User stack pointer randomisation
Date: Thu, 19 Jul 2007 09:10:23 +0200 [thread overview]
Message-ID: <469F0E5F.4050005@innova-card.com> (raw)
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'm surely missing something
obvious and that's the reason this patch is a RFC.
I tested it and it works fine so far.
Please try to have a look,
Franck
arch/mips/kernel/process.c | 13 +++++++++++++
include/asm-mips/system.h | 2 +-
2 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 6bdfb5a..4f411fa 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -25,6 +25,7 @@
#include <linux/init.h>
#include <linux/completion.h>
#include <linux/kallsyms.h>
+#include <linux/random.h>
#include <asm/bootinfo.h>
#include <asm/cpu.h>
@@ -460,3 +461,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 at least.
+ */
+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 & ~7;
+}
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
next reply other threads:[~2007-07-19 7:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-19 7:10 Franck Bui-Huu [this message]
2007-07-19 9:43 ` [RFC] User stack pointer randomisation Nigel Stephens
2007-07-19 11:36 ` Franck Bui-Huu
2007-07-19 11:14 ` Ralf Baechle
2007-07-19 11:47 ` Franck Bui-Huu
2007-07-19 12:01 ` Ralf Baechle
2007-07-19 12:19 ` Franck Bui-Huu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=469F0E5F.4050005@innova-card.com \
--to=vagabon.xyz@gmail.com \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox