Release 4.12 arch/x86/mm/mmap.c
/*
* Flexible mmap layout support
*
* Based on code by Ingo Molnar and Andi Kleen, copyrighted
* as follows:
*
* Copyright 2003-2009 Red Hat Inc.
* All Rights Reserved.
* Copyright 2005 Andi Kleen, SUSE Labs.
* Copyright 2007 Jiri Kosina, SUSE Labs.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/personality.h>
#include <linux/mm.h>
#include <linux/random.h>
#include <linux/limits.h>
#include <linux/sched/signal.h>
#include <linux/sched/mm.h>
#include <linux/compat.h>
#include <asm/elf.h>
struct va_alignment __read_mostly va_align = {
.flags = -1,
};
unsigned long tasksize_32bit(void)
{
return IA32_PAGE_OFFSET;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 11 | 100.00% | 1 | 100.00% |
Total | 11 | 100.00% | 1 | 100.00% |
unsigned long tasksize_64bit(void)
{
return TASK_SIZE_MAX;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 11 | 100.00% | 1 | 100.00% |
Total | 11 | 100.00% | 1 | 100.00% |
static unsigned long stack_maxrandom_size(unsigned long task_size)
{
unsigned long max = 0;
if ((current->flags & PF_RANDOMIZE) &&
!(current->personality & ADDR_NO_RANDOMIZE)) {
max = (-1UL) & __STACK_RND_MASK(task_size == tasksize_32bit());
max <<= PAGE_SHIFT;
}
return max;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Michal Hocko | 44 | 73.33% | 1 | 33.33% |
Dmitry Safonov | 13 | 21.67% | 1 | 33.33% |
Hector Marco-Gisbert | 3 | 5.00% | 1 | 33.33% |
Total | 60 | 100.00% | 3 | 100.00% |
#ifdef CONFIG_COMPAT
# define mmap32_rnd_bits mmap_rnd_compat_bits
# define mmap64_rnd_bits mmap_rnd_bits
#else
# define mmap32_rnd_bits mmap_rnd_bits
# define mmap64_rnd_bits mmap_rnd_bits
#endif
#define SIZE_128M (128 * 1024 * 1024UL)
static int mmap_is_legacy(void)
{
if (current->personality & ADDR_COMPAT_LAYOUT)
return 1;
if (rlimit(RLIMIT_STACK) == RLIM_INFINITY)
return 1;
return sysctl_legacy_va_layout;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jiri Kosina | 31 | 91.18% | 1 | 50.00% |
Jiri Slaby | 3 | 8.82% | 1 | 50.00% |
Total | 34 | 100.00% | 2 | 100.00% |
static unsigned long arch_rnd(unsigned int rndbits)
{
return (get_random_long() & ((1UL << rndbits) - 1)) << PAGE_SHIFT;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Harvey Harrison | 10 | 34.48% | 1 | 20.00% |
Daniel Cashman | 9 | 31.03% | 2 | 40.00% |
Dmitry Safonov | 7 | 24.14% | 1 | 20.00% |
Andi Kleen | 3 | 10.34% | 1 | 20.00% |
Total | 29 | 100.00% | 5 | 100.00% |
unsigned long arch_mmap_rnd(void)
{
if (!(current->flags & PF_RANDOMIZE))
return 0;
return arch_rnd(mmap_is_ia32() ? mmap32_rnd_bits : mmap64_rnd_bits);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 33 | 100.00% | 2 | 100.00% |
Total | 33 | 100.00% | 2 | 100.00% |
static unsigned long mmap_base(unsigned long rnd, unsigned long task_size)
{
unsigned long gap = rlimit(RLIMIT_STACK);
unsigned long gap_min, gap_max;
/*
* Top of mmap area (just below the process stack).
* Leave an at least ~128 MB hole with possible stack randomization.
*/
gap_min = SIZE_128M + stack_maxrandom_size(task_size);
gap_max = (task_size / 6) * 5;
if (gap < gap_min)
gap = gap_min;
else if (gap > gap_max)
gap = gap_max;
return PAGE_ALIGN(task_size - gap - rnd);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 35 | 43.21% | 1 | 16.67% |
Harvey Harrison | 31 | 38.27% | 1 | 16.67% |
Andi Kleen | 4 | 4.94% | 1 | 16.67% |
Kees Cook | 4 | 4.94% | 1 | 16.67% |
Jiri Kosina | 4 | 4.94% | 1 | 16.67% |
Jiri Slaby | 3 | 3.70% | 1 | 16.67% |
Total | 81 | 100.00% | 6 | 100.00% |
static unsigned long mmap_legacy_base(unsigned long rnd,
unsigned long task_size)
{
return __TASK_UNMAPPED_BASE(task_size) + rnd;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 23 | 100.00% | 1 | 100.00% |
Total | 23 | 100.00% | 1 | 100.00% |
/*
* This function, called very early during the creation of a new
* process VM image, sets up which VM layout function to use:
*/
static void arch_pick_mmap_base(unsigned long *base, unsigned long *legacy_base,
unsigned long random_factor, unsigned long task_size)
{
*legacy_base = mmap_legacy_base(random_factor, task_size);
if (mmap_is_legacy())
*base = *legacy_base;
else
*base = mmap_base(random_factor, task_size);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 42 | 75.00% | 2 | 40.00% |
Kees Cook | 7 | 12.50% | 1 | 20.00% |
Radu Caragea | 4 | 7.14% | 1 | 20.00% |
Harvey Harrison | 3 | 5.36% | 1 | 20.00% |
Total | 56 | 100.00% | 5 | 100.00% |
void arch_pick_mmap_layout(struct mm_struct *mm)
{
if (mmap_is_legacy())
mm->get_unmapped_area = arch_get_unmapped_area;
else
mm->get_unmapped_area = arch_get_unmapped_area_topdown;
arch_pick_mmap_base(&mm->mmap_base, &mm->mmap_legacy_base,
arch_rnd(mmap64_rnd_bits), tasksize_64bit());
#ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
/*
* The mmap syscall mapping base decision depends solely on the
* syscall type (64-bit or compat). This applies for 64bit
* applications and 32bit applications. The 64bit syscall uses
* mmap_base, the compat syscall uses mmap_compat_base.
*/
arch_pick_mmap_base(&mm->mmap_compat_base, &mm->mmap_compat_legacy_base,
arch_rnd(mmap32_rnd_bits), tasksize_32bit());
#endif
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 52 | 68.42% | 2 | 40.00% |
Jiri Kosina | 13 | 17.11% | 1 | 20.00% |
Kees Cook | 6 | 7.89% | 1 | 20.00% |
Andi Kleen | 5 | 6.58% | 1 | 20.00% |
Total | 76 | 100.00% | 5 | 100.00% |
unsigned long get_mmap_base(int is_legacy)
{
struct mm_struct *mm = current->mm;
#ifdef CONFIG_HAVE_ARCH_COMPAT_MMAP_BASES
if (in_compat_syscall()) {
return is_legacy ? mm->mmap_compat_legacy_base
: mm->mmap_compat_base;
}
#endif
return is_legacy ? mm->mmap_legacy_base : mm->mmap_base;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 52 | 100.00% | 1 | 100.00% |
Total | 52 | 100.00% | 1 | 100.00% |
const char *arch_vma_name(struct vm_area_struct *vma)
{
if (vma->vm_flags & VM_MPX)
return "[mpx]";
return NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Kirill A. Shutemov | 26 | 100.00% | 1 | 100.00% |
Total | 26 | 100.00% | 1 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 309 | 55.38% | 4 | 20.00% |
Jiri Kosina | 53 | 9.50% | 1 | 5.00% |
Michal Hocko | 47 | 8.42% | 1 | 5.00% |
Harvey Harrison | 45 | 8.06% | 1 | 5.00% |
Kirill A. Shutemov | 26 | 4.66% | 1 | 5.00% |
Andi Kleen | 21 | 3.76% | 1 | 5.00% |
Kees Cook | 17 | 3.05% | 1 | 5.00% |
Borislav Petkov | 12 | 2.15% | 1 | 5.00% |
Daniel Cashman | 9 | 1.61% | 2 | 10.00% |
Jiri Slaby | 6 | 1.08% | 1 | 5.00% |
Ingo Molnar | 5 | 0.90% | 3 | 15.00% |
Radu Caragea | 4 | 0.72% | 1 | 5.00% |
Hector Marco-Gisbert | 3 | 0.54% | 1 | 5.00% |
Jan-Simon Möller | 1 | 0.18% | 1 | 5.00% |
Total | 558 | 100.00% | 20 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.