aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHector Marco-Gisbert <hecmargi@upv.es>2016-03-10 14:51:00 -0500
committerIngo Molnar <mingo@kernel.org>2016-03-11 03:53:19 -0500
commit8b8addf891de8a00e4d39fc32f93f7c5eb8feceb (patch)
tree4834a77394970f74cc7f4bb99e589f0edd9648b0
parentcfa52c0cfa4d727aa3e457bf29aeff296c528a08 (diff)
x86/mm/32: Enable full randomization on i386 and X86_32
Currently on i386 and on X86_64 when emulating X86_32 in legacy mode, only the stack and the executable are randomized but not other mmapped files (libraries, vDSO, etc.). This patch enables randomization for the libraries, vDSO and mmap requests on i386 and in X86_32 in legacy mode. By default on i386 there are 8 bits for the randomization of the libraries, vDSO and mmaps which only uses 1MB of VA. This patch preserves the original randomness, using 1MB of VA out of 3GB or 4GB. We think that 1MB out of 3GB is not a big cost for having the ASLR. The first obvious security benefit is that all objects are randomized (not only the stack and the executable) in legacy mode which highly increases the ASLR effectiveness, otherwise the attackers may use these non-randomized areas. But also sensitive setuid/setgid applications are more secure because currently, attackers can disable the randomization of these applications by setting the ulimit stack to "unlimited". This is a very old and widely known trick to disable the ASLR in i386 which has been allowed for too long. Another trick used to disable the ASLR was to set the ADDR_NO_RANDOMIZE personality flag, but fortunately this doesn't work on setuid/setgid applications because there is security checks which clear Security-relevant flags. This patch always randomizes the mmap_legacy_base address, removing the possibility to disable the ASLR by setting the stack to "unlimited". Signed-off-by: Hector Marco-Gisbert <hecmargi@upv.es> Acked-by: Ismael Ripoll Ripoll <iripoll@upv.es> Acked-by: Kees Cook <keescook@chromium.org> Acked-by: Arjan van de Ven <arjan@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: akpm@linux-foundation.org Cc: kees Cook <keescook@chromium.org> Link: http://lkml.kernel.org/r/1457639460-5242-1-git-send-email-hecmargi@upv.es Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/mm/mmap.c14
1 files changed, 1 insertions, 13 deletions
diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
index 96bd1e2bffaf..389939f74dd5 100644
--- a/arch/x86/mm/mmap.c
+++ b/arch/x86/mm/mmap.c
@@ -94,18 +94,6 @@ static unsigned long mmap_base(unsigned long rnd)
94} 94}
95 95
96/* 96/*
97 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
98 * does, but not when emulating X86_32
99 */
100static unsigned long mmap_legacy_base(unsigned long rnd)
101{
102 if (mmap_is_ia32())
103 return TASK_UNMAPPED_BASE;
104 else
105 return TASK_UNMAPPED_BASE + rnd;
106}
107
108/*
109 * This function, called very early during the creation of a new 97 * This function, called very early during the creation of a new
110 * process VM image, sets up which VM layout function to use: 98 * process VM image, sets up which VM layout function to use:
111 */ 99 */
@@ -116,7 +104,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
116 if (current->flags & PF_RANDOMIZE) 104 if (current->flags & PF_RANDOMIZE)
117 random_factor = arch_mmap_rnd(); 105 random_factor = arch_mmap_rnd();
118 106
119 mm->mmap_legacy_base = mmap_legacy_base(random_factor); 107 mm->mmap_legacy_base = TASK_UNMAPPED_BASE + random_factor;
120 108
121 if (mmap_is_legacy()) { 109 if (mmap_is_legacy()) {
122 mm->mmap_base = mm->mmap_legacy_base; 110 mm->mmap_base = mm->mmap_legacy_base;