Release 4.14 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 task_size_32bit(void)
{
return IA32_PAGE_OFFSET;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 10 | 90.91% | 1 | 50.00% |
Kirill A. Shutemov | 1 | 9.09% | 1 | 50.00% |
Total | 11 | 100.00% | 2 | 100.00% |
unsigned long task_size_64bit(int full_addr_space)
{
return full_addr_space ? TASK_SIZE_MAX : DEFAULT_MAP_WINDOW;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 9 | 56.25% | 1 | 33.33% |
Kirill A. Shutemov | 7 | 43.75% | 2 | 66.67% |
Total | 16 | 100.00% | 3 | 100.00% |
static unsigned long stack_maxrandom_size(unsigned long task_size)
{
unsigned long max = 0;
if (current->flags & PF_RANDOMIZE) {
max = (-1UL) & __STACK_RND_MASK(task_size == task_size_32bit());
max <<= PAGE_SHIFT;
}
return max;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Michal Hocko | 33 | 67.35% | 1 | 25.00% |
Dmitry Safonov | 12 | 24.49% | 1 | 25.00% |
Hector Marco-Gisbert | 3 | 6.12% | 1 | 25.00% |
Kirill A. Shutemov | 1 | 2.04% | 1 | 25.00% |
Total | 49 | 100.00% | 4 | 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;
return sysctl_legacy_va_layout;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jiri Kosina | 22 | 100.00% | 1 | 100.00% |
Total | 22 | 100.00% | 1 | 100.00% |
static unsigned long arch_rnd(unsigned int rndbits)
{
if (!(current->flags & PF_RANDOMIZE))
return 0;
return (get_random_long() & ((1UL << rndbits) - 1)) << PAGE_SHIFT;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Oleg Nesterov | 14 | 32.56% | 1 | 16.67% |
Harvey Harrison | 10 | 23.26% | 1 | 16.67% |
Daniel Cashman | 9 | 20.93% | 2 | 33.33% |
Dmitry Safonov | 7 | 16.28% | 1 | 16.67% |
Andi Kleen | 3 | 6.98% | 1 | 16.67% |
Total | 43 | 100.00% | 6 | 100.00% |
unsigned long arch_mmap_rnd(void)
{
return arch_rnd(mmap_is_ia32() ? mmap32_rnd_bits : mmap64_rnd_bits);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 19 | 100.00% | 1 | 100.00% |
Total | 19 | 100.00% | 1 | 100.00% |
static unsigned long mmap_base(unsigned long rnd, unsigned long task_size)
{
unsigned long gap = rlimit(RLIMIT_STACK);
unsigned long pad = stack_maxrandom_size(task_size) + stack_guard_gap;
unsigned long gap_min, gap_max;
/* Values close to RLIM_INFINITY can overflow. */
if (gap + pad > gap)
gap += pad;
/*
* Top of mmap area (just below the process stack).
* Leave an at least ~128 MB hole with possible stack randomization.
*/
gap_min = SIZE_128M;
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 |
Harvey Harrison | 31 | 31.00% | 1 | 14.29% |
Dmitry Safonov | 30 | 30.00% | 1 | 14.29% |
Rik Van Riel | 24 | 24.00% | 1 | 14.29% |
Andi Kleen | 4 | 4.00% | 1 | 14.29% |
Kees Cook | 4 | 4.00% | 1 | 14.29% |
Jiri Kosina | 4 | 4.00% | 1 | 14.29% |
Jiri Slaby | 3 | 3.00% | 1 | 14.29% |
Total | 100 | 100.00% | 7 | 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), task_size_64bit(0));
#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), task_size_32bit());
#endif
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Safonov | 49 | 62.82% | 2 | 28.57% |
Jiri Kosina | 13 | 16.67% | 1 | 14.29% |
Kees Cook | 6 | 7.69% | 1 | 14.29% |
Andi Kleen | 5 | 6.41% | 1 | 14.29% |
Kirill A. Shutemov | 5 | 6.41% | 2 | 28.57% |
Total | 78 | 100.00% | 7 | 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 | 283 | 50.45% | 4 | 16.67% |
Harvey Harrison | 45 | 8.02% | 1 | 4.17% |
Jiri Kosina | 44 | 7.84% | 1 | 4.17% |
Kirill A. Shutemov | 40 | 7.13% | 3 | 12.50% |
Michal Hocko | 36 | 6.42% | 1 | 4.17% |
Rik Van Riel | 24 | 4.28% | 1 | 4.17% |
Andi Kleen | 21 | 3.74% | 1 | 4.17% |
Kees Cook | 17 | 3.03% | 1 | 4.17% |
Oleg Nesterov | 14 | 2.50% | 1 | 4.17% |
Borislav Petkov | 12 | 2.14% | 1 | 4.17% |
Daniel Cashman | 9 | 1.60% | 2 | 8.33% |
Ingo Molnar | 5 | 0.89% | 3 | 12.50% |
Radu Caragea | 4 | 0.71% | 1 | 4.17% |
Hector Marco-Gisbert | 3 | 0.53% | 1 | 4.17% |
Jiri Slaby | 3 | 0.53% | 1 | 4.17% |
Jan-Simon Möller | 1 | 0.18% | 1 | 4.17% |
Total | 561 | 100.00% | 24 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.