From patchwork Sun Feb 22 11:50:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Blanchard X-Patchwork-Id: 23532 X-Patchwork-Delegate: benh@kernel.crashing.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id A77D3DE757 for ; Sun, 22 Feb 2009 23:07:20 +1100 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org Received: by ozlabs.org (Postfix, from userid 1010) id 855ACDDDA9; Sun, 22 Feb 2009 23:01:37 +1100 (EST) Resent-From: anton@kryten Resent-Date: Sun, 22 Feb 2009 22:58:55 +1100 Resent-Message-ID: <20090222115855.GG12006@kryten> Resent-To: linuxppc-dev@ozlabs.org Message-Id: <20090222115332.404685001@samba.org> References: <20090222114957.213647384@samba.org> User-Agent: quilt/0.46-1 Date: Sun, 22 Feb 2009 22:50:03 +1100 From: Anton Blanchard To: linuxppc-dev@ozlabs.org Subject: [patch 06/10] powerpc: Randomise lower bits of stack address Content-Disposition: inline; filename=randomise_stack_lower.patch X-BeenThere: linuxppc-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Randomise the lower bits of the stack address. More randomisation is good for security but the scatter can also help with SMT threads that share an L1. A quick test case shows this working: int main() { int sp; printf("%x\n", (unsigned long)&sp & 4095); } before: 80 80 80 80 80 after: 610 490 300 6b0 d80 Signed-off-by: Anton Blanchard Index: linux-2.6/arch/powerpc/include/asm/system.h =================================================================== --- linux-2.6.orig/arch/powerpc/include/asm/system.h 2009-02-20 13:39:05.000000000 +1100 +++ linux-2.6/arch/powerpc/include/asm/system.h 2009-02-20 13:51:39.000000000 +1100 @@ -531,7 +531,7 @@ #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) #endif -#define arch_align_stack(x) (x) +extern unsigned long arch_align_stack(unsigned long sp); /* Used in very early kernel initialization. */ extern unsigned long reloc_offset(void); Index: linux-2.6/arch/powerpc/kernel/process.c =================================================================== --- linux-2.6.orig/arch/powerpc/kernel/process.c 2009-02-20 13:39:05.000000000 +1100 +++ linux-2.6/arch/powerpc/kernel/process.c 2009-02-20 13:51:39.000000000 +1100 @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include @@ -1122,3 +1124,10 @@ } #endif /* THREAD_SHIFT < PAGE_SHIFT */ + +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 & ~0xf; +}