LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: akpm@linux-foundation.org
Cc: "Kees Cook" <keescook@chromium.org>,
linux-kernel@vger.kernel.org,
"Hector Marco-Gisbert" <hecmargi@upv.es>,
"Ismael Ripoll" <iripoll@upv.es>,
"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>,
"Min-Hua Chen" <orca.chen@gmail.com>,
"Dan McGee" <dpmcgee@gmail.com>,
"Yann Droneaud" <ydroneaud@opteya.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>,
"Jan-Simon Möller" <dl9pf@gmx.de>,
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
Subject: [PATCH v3 06/10] s390: standardize mmap_rnd() usage
Date: Tue, 3 Mar 2015 18:10:21 -0800 [thread overview]
Message-ID: <1425435025-30284-7-git-send-email-keescook@chromium.org> (raw)
In-Reply-To: <1425435025-30284-1-git-send-email-keescook@chromium.org>
In preparation for splitting out ET_DYN ASLR, this refactors the use of
mmap_rnd() to be used similarly to arm and x86, and extracts the checking
of PF_RANDOMIZE.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
arch/s390/mm/mmap.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
index 179a2c20b01f..db57078075c5 100644
--- a/arch/s390/mm/mmap.c
+++ b/arch/s390/mm/mmap.c
@@ -62,20 +62,18 @@ static inline int mmap_is_legacy(void)
static unsigned long mmap_rnd(void)
{
- if (!(current->flags & PF_RANDOMIZE))
- return 0;
if (is_32bit_task())
return (get_random_int() & 0x7ff) << PAGE_SHIFT;
else
return (get_random_int() & mmap_rnd_mask) << PAGE_SHIFT;
}
-static unsigned long mmap_base_legacy(void)
+static unsigned long mmap_base_legacy(unsigned long rnd)
{
- return TASK_UNMAPPED_BASE + mmap_rnd();
+ return TASK_UNMAPPED_BASE + rnd;
}
-static inline unsigned long mmap_base(void)
+static inline unsigned long mmap_base(unsigned long rnd)
{
unsigned long gap = rlimit(RLIMIT_STACK);
@@ -84,7 +82,7 @@ static inline unsigned long mmap_base(void)
else if (gap > MAX_GAP)
gap = MAX_GAP;
gap &= PAGE_MASK;
- return STACK_TOP - stack_maxrandom_size() - mmap_rnd() - gap;
+ return STACK_TOP - stack_maxrandom_size() - rnd - gap;
}
unsigned long
@@ -187,7 +185,11 @@ unsigned long randomize_et_dyn(void)
if (!is_32bit_task())
/* Align to 4GB */
base &= ~((1UL << 32) - 1);
- return base + mmap_rnd();
+
+ if (current->flags & PF_RANDOMIZE)
+ base += mmap_rnd();
+
+ return base;
}
#ifndef CONFIG_64BIT
@@ -198,15 +200,20 @@ unsigned long randomize_et_dyn(void)
*/
void arch_pick_mmap_layout(struct mm_struct *mm)
{
+ unsigned long random_factor = 0UL;
+
+ if (current->flags & PF_RANDOMIZE)
+ random_factor = mmap_rnd();
+
/*
* Fall back to the standard layout if the personality
* bit is set, or if the expected stack growth is unlimited:
*/
if (mmap_is_legacy()) {
- mm->mmap_base = mmap_base_legacy();
+ mm->mmap_base = mmap_base_legacy(random_factor);
mm->get_unmapped_area = arch_get_unmapped_area;
} else {
- mm->mmap_base = mmap_base();
+ mm->mmap_base = mmap_base(random_factor);
mm->get_unmapped_area = arch_get_unmapped_area_topdown;
}
}
@@ -273,15 +280,20 @@ s390_get_unmapped_area_topdown(struct file *filp, const unsigned long addr,
*/
void arch_pick_mmap_layout(struct mm_struct *mm)
{
+ unsigned long random_factor = 0UL;
+
+ if (current->flags & PF_RANDOMIZE)
+ random_factor = mmap_rnd();
+
/*
* Fall back to the standard layout if the personality
* bit is set, or if the expected stack growth is unlimited:
*/
if (mmap_is_legacy()) {
- mm->mmap_base = mmap_base_legacy();
+ mm->mmap_base = mmap_base_legacy(random_factor);
mm->get_unmapped_area = s390_get_unmapped_area;
} else {
- mm->mmap_base = mmap_base();
+ mm->mmap_base = mmap_base(random_factor);
mm->get_unmapped_area = s390_get_unmapped_area_topdown;
}
}
--
1.9.1
next prev parent reply other threads:[~2015-03-04 2:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-04 2:10 [PATCH v3 0/10] split ET_DYN ASLR from mmap ASLR Kees Cook
2015-03-04 2:10 ` [PATCH v3 01/10] arm: factor out mmap ASLR into mmap_rnd Kees Cook
2015-03-04 2:10 ` [PATCH v3 02/10] x86: standardize mmap_rnd() usage Kees Cook
2015-03-04 2:10 ` [PATCH v3 03/10] arm64: " Kees Cook
2015-03-04 2:10 ` [PATCH v3 04/10] mips: extract logic for mmap_rnd() Kees Cook
2015-03-04 2:10 ` [PATCH v3 05/10] powerpc: standardize mmap_rnd() usage Kees Cook
2015-03-04 2:10 ` Kees Cook [this message]
2015-03-04 2:10 ` [PATCH v3 07/10] mm: expose arch_mmap_rnd when available Kees Cook
2015-03-04 2:10 ` [PATCH v3 08/10] s390: redefine randomize_et_dyn for ELF_ET_DYN_BASE Kees Cook
2015-03-04 2:10 ` [PATCH v3 09/10] mm: split ET_DYN ASLR from mmap ASLR Kees Cook
2015-03-04 2:10 ` [PATCH v3 10/10] mm: fold arch_randomize_brk into ARCH_HAS_ELF_RANDOMIZE Kees Cook
2015-03-09 16:19 ` [PATCH v3 0/10] split ET_DYN ASLR from mmap ASLR Russell King - ARM Linux
2015-03-09 18:06 ` Kees Cook
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=1425435025-30284-7-git-send-email-keescook@chromium.org \
--to=keescook@chromium.org \
--cc=a.ryabinin@samsung.com \
--cc=achandran@mvista.com \
--cc=akpm@linux-foundation.org \
--cc=alex@alex-smith.me.uk \
--cc=behanw@converseincode.com \
--cc=ben@decadent.org.uk \
--cc=benh@kernel.crashing.org \
--cc=catalin.marinas@arm.com \
--cc=dave.long@linaro.org \
--cc=dl9pf@gmx.de \
--cc=dpmcgee@gmail.com \
--cc=hecmargi@upv.es \
--cc=heiko.carstens@de.ibm.com \
--cc=holzheu@linux.vnet.ibm.com \
--cc=iripoll@upv.es \
--cc=jeffbailey@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux390@de.ibm.com \
--cc=linux@arm.linux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=luto@amacapital.net \
--cc=markos.chandras@imgtec.com \
--cc=mpe@ellerman.id.au \
--cc=oleg@redhat.com \
--cc=orca.chen@gmail.com \
--cc=paul.burton@imgtec.com \
--cc=paulus@samba.org \
--cc=ralf@linux-mips.org \
--cc=schwidefsky@de.ibm.com \
--cc=viro@zeniv.linux.org.uk \
--cc=vvijayan@mvista.com \
--cc=will.deacon@arm.com \
--cc=x86@kernel.org \
--cc=ydroneaud@opteya.com \
--subject='Re: [PATCH v3 06/10] s390: standardize mmap_rnd() usage' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).