summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@infradead.org>2005-03-04 17:25:13 -0800
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-03-04 17:25:13 -0800
commitccc875c1d2fe18b50020d501f1005ef46fc55fed (patch)
treec537ca25c29dc7eff4eb9d96d4aab41041fffb37
parentc518b108234a2418fb65a09e6219202eda316d6c (diff)
[PATCH] Randomisation: stack randomisation
The patch below replaces the existing 8Kb randomisation of the userspace stack pointer (which is currently only done for Hyperthreaded P-IVs) with a more general randomisation over a 64Kb range. 64Kb is not a lot, but it's a start and once the dust settles we can increase this value to a more agressive value. Signed-off-by: Arjan van de Ven <arjan@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--arch/i386/kernel/process.c7
-rw-r--r--arch/x86_64/kernel/process.c8
-rw-r--r--fs/binfmt_elf.c11
-rw-r--r--fs/exec.c3
-rw-r--r--include/asm-alpha/system.h2
-rw-r--r--include/asm-arm/system.h2
-rw-r--r--include/asm-arm26/system.h2
-rw-r--r--include/asm-cris/system.h2
-rw-r--r--include/asm-frv/system.h2
-rw-r--r--include/asm-h8300/system.h2
-rw-r--r--include/asm-i386/system.h2
-rw-r--r--include/asm-ia64/system.h3
-rw-r--r--include/asm-m32r/system.h2
-rw-r--r--include/asm-m68k/system.h2
-rw-r--r--include/asm-m68knommu/system.h1
-rw-r--r--include/asm-mips/system.h2
-rw-r--r--include/asm-parisc/system.h2
-rw-r--r--include/asm-ppc/system.h2
-rw-r--r--include/asm-ppc64/system.h2
-rw-r--r--include/asm-s390/system.h2
-rw-r--r--include/asm-sh/system.h2
-rw-r--r--include/asm-sh64/system.h2
-rw-r--r--include/asm-sparc/system.h2
-rw-r--r--include/asm-sparc64/system.h2
-rw-r--r--include/asm-v850/system.h2
-rw-r--r--include/asm-x86_64/system.h2
26 files changed, 63 insertions, 10 deletions
diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
index 28b0d7bf0a84..5bdb839b2bb6 100644
--- a/arch/i386/kernel/process.c
+++ b/arch/i386/kernel/process.c
@@ -36,6 +36,7 @@
#include <linux/module.h>
#include <linux/kallsyms.h>
#include <linux/ptrace.h>
+#include <linux/random.h>
#include <asm/uaccess.h>
#include <asm/pgtable.h>
@@ -828,3 +829,9 @@ asmlinkage int sys_get_thread_area(struct user_desc __user *u_info)
return 0;
}
+unsigned long arch_align_stack(unsigned long sp)
+{
+ if (randomize_va_space)
+ sp -= get_random_int() % 8192;
+ return sp & ~0xf;
+}
diff --git a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c
index 3a3522b9c885..0282960ddc91 100644
--- a/arch/x86_64/kernel/process.c
+++ b/arch/x86_64/kernel/process.c
@@ -33,6 +33,7 @@
#include <linux/irq.h>
#include <linux/ptrace.h>
#include <linux/utsname.h>
+#include <linux/random.h>
#include <asm/uaccess.h>
#include <asm/pgtable.h>
@@ -749,3 +750,10 @@ int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
return 1;
}
+
+unsigned long arch_align_stack(unsigned long sp)
+{
+ if (randomize_va_space)
+ sp -= get_random_int() % 8192;
+ return sp & ~0xf;
+}
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 1740bac44917..91ad281f851d 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -165,21 +165,14 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr * exec,
if (k_platform) {
size_t len = strlen(k_platform) + 1;
-#ifdef CONFIG_X86_HT
/*
* In some cases (e.g. Hyper-Threading), we want to avoid L1
* evictions by the processes running on the same package. One
* thing we can do is to shuffle the initial stack for them.
- *
- * The conditionals here are unneeded, but kept in to make the
- * code behaviour the same as pre change unless we have
- * hyperthreaded processors. This should be cleaned up
- * before 2.6
*/
- if (smp_num_siblings > 1)
- STACK_ALLOC(p, ((current->pid % 64) << 7));
-#endif
+ p = arch_align_stack(p);
+
u_platform = (elf_addr_t __user *)STACK_ALLOC(p, len);
if (__copy_to_user(u_platform, k_platform, len))
return -EFAULT;
diff --git a/fs/exec.c b/fs/exec.c
index 694e3c141012..6e505b1b3db6 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -400,7 +400,8 @@ int setup_arg_pages(struct linux_binprm *bprm,
while (i < MAX_ARG_PAGES)
bprm->page[i++] = NULL;
#else
- stack_base = stack_top - MAX_ARG_PAGES * PAGE_SIZE;
+ stack_base = arch_align_stack(STACK_TOP - MAX_ARG_PAGES*PAGE_SIZE);
+ stack_base = PAGE_ALIGN(stack_base);
bprm->p += stack_base;
mm->arg_start = bprm->p;
arg_size = stack_top - (PAGE_MASK & (unsigned long) mm->arg_start);
diff --git a/include/asm-alpha/system.h b/include/asm-alpha/system.h
index bba276c50b15..c08ce970ff8c 100644
--- a/include/asm-alpha/system.h
+++ b/include/asm-alpha/system.h
@@ -621,4 +621,6 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
#endif /* __ASSEMBLY__ */
+#define arch_align_stack(x) (x)
+
#endif
diff --git a/include/asm-arm/system.h b/include/asm-arm/system.h
index 77d0dcf0b713..b5731290b4e5 100644
--- a/include/asm-arm/system.h
+++ b/include/asm-arm/system.h
@@ -383,6 +383,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
#endif /* __ASSEMBLY__ */
+#define arch_align_stack(x) (x)
+
#endif /* __KERNEL__ */
#endif
diff --git a/include/asm-arm26/system.h b/include/asm-arm26/system.h
index 6361b6c71f8c..f23fac1938f3 100644
--- a/include/asm-arm26/system.h
+++ b/include/asm-arm26/system.h
@@ -245,6 +245,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
#endif /* __ASSEMBLY__ */
+#define arch_align_stack(x) (x)
+
#endif /* __KERNEL__ */
#endif
diff --git a/include/asm-cris/system.h b/include/asm-cris/system.h
index f9cf80262574..e06739806d4e 100644
--- a/include/asm-cris/system.h
+++ b/include/asm-cris/system.h
@@ -69,4 +69,6 @@ extern inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz
return x;
}
+#define arch_align_stack(x) (x)
+
#endif
diff --git a/include/asm-frv/system.h b/include/asm-frv/system.h
index 29cfa21ec2fe..d2aea70a5f64 100644
--- a/include/asm-frv/system.h
+++ b/include/asm-frv/system.h
@@ -123,4 +123,6 @@ do { \
extern void die_if_kernel(const char *, ...) __attribute__((format(printf, 1, 2)));
extern void free_initmem(void);
+#define arch_align_stack(x) (x)
+
#endif /* _ASM_SYSTEM_H */
diff --git a/include/asm-h8300/system.h b/include/asm-h8300/system.h
index b91dae2a90c3..dfe96c7121cf 100644
--- a/include/asm-h8300/system.h
+++ b/include/asm-h8300/system.h
@@ -144,4 +144,6 @@ static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz
asm("jmp @@0"); \
})
+#define arch_align_stack(x) (x)
+
#endif /* _H8300_SYSTEM_H */
diff --git a/include/asm-i386/system.h b/include/asm-i386/system.h
index c705fa77b138..6f74d4c44a0e 100644
--- a/include/asm-i386/system.h
+++ b/include/asm-i386/system.h
@@ -468,4 +468,6 @@ void enable_hlt(void);
extern int es7000_plat;
void cpu_idle_wait(void);
+extern unsigned long arch_align_stack(unsigned long sp);
+
#endif
diff --git a/include/asm-ia64/system.h b/include/asm-ia64/system.h
index f28b920e9089..6f516e76d1f0 100644
--- a/include/asm-ia64/system.h
+++ b/include/asm-ia64/system.h
@@ -285,6 +285,9 @@ do { \
#define ia64_platform_is(x) (strcmp(x, platform_name) == 0)
void cpu_idle_wait(void);
+
+#define arch_align_stack(x) (x)
+
#endif /* __KERNEL__ */
#endif /* __ASSEMBLY__ */
diff --git a/include/asm-m32r/system.h b/include/asm-m32r/system.h
index 5828af7d4122..73348c3f858b 100644
--- a/include/asm-m32r/system.h
+++ b/include/asm-m32r/system.h
@@ -294,4 +294,6 @@ static __inline__ unsigned long __xchg(unsigned long x, volatile void * ptr,
#define set_mb(var, value) do { xchg(&var, value); } while (0)
#define set_wmb(var, value) do { var = value; wmb(); } while (0)
+#define arch_align_stack(x) (x)
+
#endif /* _ASM_M32R_SYSTEM_H */
diff --git a/include/asm-m68k/system.h b/include/asm-m68k/system.h
index f0f36fca11bb..64d3481df74c 100644
--- a/include/asm-m68k/system.h
+++ b/include/asm-m68k/system.h
@@ -194,6 +194,8 @@ static inline unsigned long __cmpxchg(volatile void *p, unsigned long old,
(unsigned long)(n),sizeof(*(ptr))))
#endif
+#define arch_align_stack(x) (x)
+
#endif /* __KERNEL__ */
#endif /* _M68K_SYSTEM_H */
diff --git a/include/asm-m68knommu/system.h b/include/asm-m68knommu/system.h
index ce3f0b0226df..c341b66c147b 100644
--- a/include/asm-m68knommu/system.h
+++ b/include/asm-m68knommu/system.h
@@ -281,5 +281,6 @@ cmpxchg(volatile int *p, int old, int new)
})
#endif
#endif
+#define arch_align_stack(x) (x)
#endif /* _M68KNOMMU_SYSTEM_H */
diff --git a/include/asm-mips/system.h b/include/asm-mips/system.h
index a421cdb1e0da..888fd8908467 100644
--- a/include/asm-mips/system.h
+++ b/include/asm-mips/system.h
@@ -433,4 +433,6 @@ do { \
#define finish_arch_switch(rq, prev) spin_unlock_irq(&(prev)->switch_lock)
#define task_running(rq, p) ((rq)->curr == (p) || spin_is_locked(&(p)->switch_lock))
+#define arch_align_stack(x) (x)
+
#endif /* _ASM_SYSTEM_H */
diff --git a/include/asm-parisc/system.h b/include/asm-parisc/system.h
index 8aecb9e93fc0..d91428ed57d6 100644
--- a/include/asm-parisc/system.h
+++ b/include/asm-parisc/system.h
@@ -205,4 +205,6 @@ extern spinlock_t pa_tlb_lock;
#endif
+#define arch_align_stack(x) (x)
+
#endif
diff --git a/include/asm-ppc/system.h b/include/asm-ppc/system.h
index 5cff9a0fd84b..25050b76db44 100644
--- a/include/asm-ppc/system.h
+++ b/include/asm-ppc/system.h
@@ -201,5 +201,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
(unsigned long)_n_, sizeof(*(ptr))); \
})
+#define arch_align_stack(x) (x)
+
#endif /* __KERNEL__ */
#endif /* __PPC_SYSTEM_H */
diff --git a/include/asm-ppc64/system.h b/include/asm-ppc64/system.h
index 6785e69e8b9e..98d120ca8a91 100644
--- a/include/asm-ppc64/system.h
+++ b/include/asm-ppc64/system.h
@@ -300,5 +300,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
*/
#define NET_IP_ALIGN 0
+#define arch_align_stack(x) (x)
+
#endif /* __KERNEL__ */
#endif
diff --git a/include/asm-s390/system.h b/include/asm-s390/system.h
index 8565a8aee735..037b8d16e435 100644
--- a/include/asm-s390/system.h
+++ b/include/asm-s390/system.h
@@ -461,6 +461,8 @@ extern void (*_machine_restart)(char *command);
extern void (*_machine_halt)(void);
extern void (*_machine_power_off)(void);
+#define arch_align_stack(x) (x)
+
#endif /* __KERNEL__ */
#endif
diff --git a/include/asm-sh/system.h b/include/asm-sh/system.h
index 5e67caf8885e..28a3c2d8bcd7 100644
--- a/include/asm-sh/system.h
+++ b/include/asm-sh/system.h
@@ -259,4 +259,6 @@ static __inline__ unsigned long __xchg(unsigned long x, volatile void * ptr, int
void disable_hlt(void);
void enable_hlt(void);
+#define arch_align_stack(x) (x)
+
#endif
diff --git a/include/asm-sh64/system.h b/include/asm-sh64/system.h
index 8b3a6f9e62fb..8aaabc92f9fb 100644
--- a/include/asm-sh64/system.h
+++ b/include/asm-sh64/system.h
@@ -191,4 +191,6 @@ extern void print_seg(char *file,int line);
#define PL() printk("@ <%s,%s:%d>\n",__FILE__,__FUNCTION__,__LINE__)
+#define arch_align_stack(x) (x)
+
#endif /* __ASM_SH64_SYSTEM_H */
diff --git a/include/asm-sparc/system.h b/include/asm-sparc/system.h
index a8e77ad1ea46..80cf20cfaee1 100644
--- a/include/asm-sparc/system.h
+++ b/include/asm-sparc/system.h
@@ -257,4 +257,6 @@ extern void die_if_kernel(char *str, struct pt_regs *regs) __attribute__ ((noret
#endif /* __ASSEMBLY__ */
+#define arch_align_stack(x) (x)
+
#endif /* !(__SPARC_SYSTEM_H) */
diff --git a/include/asm-sparc64/system.h b/include/asm-sparc64/system.h
index ef77358abf24..e8ba9d5277e1 100644
--- a/include/asm-sparc64/system.h
+++ b/include/asm-sparc64/system.h
@@ -341,4 +341,6 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
#endif /* !(__ASSEMBLY__) */
+#define arch_align_stack(x) (x)
+
#endif /* !(__SPARC64_SYSTEM_H) */
diff --git a/include/asm-v850/system.h b/include/asm-v850/system.h
index 072a997dc5a9..20f4c738c04e 100644
--- a/include/asm-v850/system.h
+++ b/include/asm-v850/system.h
@@ -108,4 +108,6 @@ extern inline unsigned long __xchg (unsigned long with,
return tmp;
}
+#define arch_align_stack(x) (x)
+
#endif /* __V850_SYSTEM_H__ */
diff --git a/include/asm-x86_64/system.h b/include/asm-x86_64/system.h
index c1710933828f..76165736e43a 100644
--- a/include/asm-x86_64/system.h
+++ b/include/asm-x86_64/system.h
@@ -338,4 +338,6 @@ void enable_hlt(void);
#define HAVE_EAT_KEY
void eat_key(void);
+extern unsigned long arch_align_stack(unsigned long sp);
+
#endif