| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp. |
|---|
| 3 | 4 | * <benh@kernel.crashing.org> |
|---|
| 4 | 5 | * Copyright (C) 2012 ARM Limited |
|---|
| 5 | 6 | * Copyright (C) 2015 Regents of the University of California |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License |
|---|
| 17 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 18 | 7 | */ |
|---|
| 19 | 8 | |
|---|
| 9 | +#include <linux/elf.h> |
|---|
| 20 | 10 | #include <linux/mm.h> |
|---|
| 21 | 11 | #include <linux/slab.h> |
|---|
| 22 | 12 | #include <linux/binfmts.h> |
|---|
| 23 | 13 | #include <linux/err.h> |
|---|
| 24 | | - |
|---|
| 14 | +#include <asm/page.h> |
|---|
| 15 | +#ifdef CONFIG_GENERIC_TIME_VSYSCALL |
|---|
| 16 | +#include <vdso/datapage.h> |
|---|
| 17 | +#else |
|---|
| 25 | 18 | #include <asm/vdso.h> |
|---|
| 19 | +#endif |
|---|
| 26 | 20 | |
|---|
| 27 | 21 | extern char vdso_start[], vdso_end[]; |
|---|
| 28 | 22 | |
|---|
| .. | .. |
|---|
| 54 | 48 | struct page *pg; |
|---|
| 55 | 49 | |
|---|
| 56 | 50 | pg = virt_to_page(vdso_start + (i << PAGE_SHIFT)); |
|---|
| 57 | | - ClearPageReserved(pg); |
|---|
| 58 | 51 | vdso_pagelist[i] = pg; |
|---|
| 59 | 52 | } |
|---|
| 60 | 53 | vdso_pagelist[i] = virt_to_page(vdso_data); |
|---|
| .. | .. |
|---|
| 72 | 65 | |
|---|
| 73 | 66 | vdso_len = (vdso_pages + 1) << PAGE_SHIFT; |
|---|
| 74 | 67 | |
|---|
| 75 | | - down_write(&mm->mmap_sem); |
|---|
| 68 | + if (mmap_write_lock_killable(mm)) |
|---|
| 69 | + return -EINTR; |
|---|
| 70 | + |
|---|
| 76 | 71 | vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0); |
|---|
| 77 | 72 | if (IS_ERR_VALUE(vdso_base)) { |
|---|
| 78 | 73 | ret = vdso_base; |
|---|
| .. | .. |
|---|
| 86 | 81 | */ |
|---|
| 87 | 82 | mm->context.vdso = (void *)vdso_base; |
|---|
| 88 | 83 | |
|---|
| 89 | | - ret = install_special_mapping(mm, vdso_base, vdso_len, |
|---|
| 84 | + ret = |
|---|
| 85 | + install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT, |
|---|
| 90 | 86 | (VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC), |
|---|
| 91 | 87 | vdso_pagelist); |
|---|
| 92 | 88 | |
|---|
| 89 | + if (unlikely(ret)) { |
|---|
| 90 | + mm->context.vdso = NULL; |
|---|
| 91 | + goto end; |
|---|
| 92 | + } |
|---|
| 93 | + |
|---|
| 94 | + vdso_base += (vdso_pages << PAGE_SHIFT); |
|---|
| 95 | + ret = install_special_mapping(mm, vdso_base, PAGE_SIZE, |
|---|
| 96 | + (VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]); |
|---|
| 97 | + |
|---|
| 93 | 98 | if (unlikely(ret)) |
|---|
| 94 | 99 | mm->context.vdso = NULL; |
|---|
| 95 | | - |
|---|
| 96 | 100 | end: |
|---|
| 97 | | - up_write(&mm->mmap_sem); |
|---|
| 101 | + mmap_write_unlock(mm); |
|---|
| 98 | 102 | return ret; |
|---|
| 99 | 103 | } |
|---|
| 100 | 104 | |
|---|
| .. | .. |
|---|
| 102 | 106 | { |
|---|
| 103 | 107 | if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso)) |
|---|
| 104 | 108 | return "[vdso]"; |
|---|
| 105 | | - return NULL; |
|---|
| 106 | | -} |
|---|
| 107 | | - |
|---|
| 108 | | -/* |
|---|
| 109 | | - * Function stubs to prevent linker errors when AT_SYSINFO_EHDR is defined |
|---|
| 110 | | - */ |
|---|
| 111 | | - |
|---|
| 112 | | -int in_gate_area_no_mm(unsigned long addr) |
|---|
| 113 | | -{ |
|---|
| 114 | | - return 0; |
|---|
| 115 | | -} |
|---|
| 116 | | - |
|---|
| 117 | | -int in_gate_area(struct mm_struct *mm, unsigned long addr) |
|---|
| 118 | | -{ |
|---|
| 119 | | - return 0; |
|---|
| 120 | | -} |
|---|
| 121 | | - |
|---|
| 122 | | -struct vm_area_struct *get_gate_vma(struct mm_struct *mm) |
|---|
| 123 | | -{ |
|---|
| 109 | + if (vma->vm_mm && (vma->vm_start == |
|---|
| 110 | + (long)vma->vm_mm->context.vdso + PAGE_SIZE)) |
|---|
| 111 | + return "[vdso_data]"; |
|---|
| 124 | 112 | return NULL; |
|---|
| 125 | 113 | } |
|---|