linux-mips
[Top] [All Lists]

[PATCH 1/5] arm: factor out mmap ASLR into mmap_rnd

To: akpm@linux-foundation.org
Subject: [PATCH 1/5] arm: factor out mmap ASLR into mmap_rnd
From: Kees Cook <keescook@chromium.org>
Date: Thu, 26 Feb 2015 19:07:10 -0800
Cc: Kees Cook <keescook@chromium.org>, Russell King <linux@arm.linux.org.uk>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will.deacon@arm.com>, Ralf Baechle <ralf@linux-mips.org>, Benjamin Herrenschmidt <benh@kernel.crashing.org>, Paul Mackerras <paulus@samba.org>, Michael Ellerman <mpe@ellerman.id.au>, Martin Schwidefsky <schwidefsky@de.ibm.com>, Heiko Carstens <heiko.carstens@de.ibm.com>, linux390@de.ibm.com, x86@kernel.org, Alexander Viro <viro@zeniv.linux.org.uk>, Oleg Nesterov <oleg@redhat.com>, Andy Lutomirski <luto@amacapital.net>, "David A. Long" <dave.long@linaro.org>, Andrey Ryabinin <a.ryabinin@samsung.com>, Arun Chandran <achandran@mvista.com>, Yann Droneaud <ydroneaud@opteya.com>, Min-Hua Chen <orca.chen@gmail.com>, Paul Burton <paul.burton@imgtec.com>, Alex Smith <alex@alex-smith.me.uk>, Markos Chandras <markos.chandras@imgtec.com>, Vineeth Vijayan <vvijayan@mvista.com>, Jeff Bailey <jeffbailey@google.com>, Michael Holzheu <holzheu@linux.vnet.ibm.com>, Ben Hutchings <ben@decadent.org.uk>, Behan Webster <behanw@converseincode.com>, Ismael Ripoll <iripoll@upv.es>, Hector Marco-Gisbert <hecmargi@upv.es>, Jan-Simon Möller <dl9pf@gmx.de>, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org
In-reply-to: <1425006434-3106-1-git-send-email-keescook@chromium.org>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1425006434-3106-1-git-send-email-keescook@chromium.org>
Sender: linux-mips-bounce@linux-mips.org
Move logic for mmap ASLR into separate function.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 arch/arm/mm/mmap.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
index 5e85ed371364..0f8bc158f2c6 100644
--- a/arch/arm/mm/mmap.c
+++ b/arch/arm/mm/mmap.c
@@ -169,14 +169,21 @@ arch_get_unmapped_area_topdown(struct file *filp, const 
unsigned long addr0,
        return addr;
 }
 
-void arch_pick_mmap_layout(struct mm_struct *mm)
+static unsigned long mmap_rnd(void)
 {
-       unsigned long random_factor = 0UL;
+       unsigned long rnd = 0UL;
 
        /* 8 bits of randomness in 20 address space bits */
        if ((current->flags & PF_RANDOMIZE) &&
            !(current->personality & ADDR_NO_RANDOMIZE))
-               random_factor = (get_random_int() % (1 << 8)) << PAGE_SHIFT;
+               rnd = (get_random_int() % (1 << 8)) << PAGE_SHIFT;
+
+       return rnd;
+}
+
+void arch_pick_mmap_layout(struct mm_struct *mm)
+{
+       unsigned long random_factor = mmap_rnd();
 
        if (mmap_is_legacy()) {
                mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
-- 
1.9.1


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