2019-05-28 11:10:17 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2007-07-21 09:10:01 -06:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Andi Kleen, SUSE Labs.
|
2014-09-23 11:50:57 -06:00
|
|
|
*
|
|
|
|
* This contains most of the x86 vDSO kernel-side code.
|
2007-07-21 09:10:01 -06:00
|
|
|
*/
|
|
|
|
#include <linux/mm.h>
|
2007-07-29 16:36:13 -06:00
|
|
|
#include <linux/err.h>
|
2007-07-21 09:10:01 -06:00
|
|
|
#include <linux/sched.h>
|
2017-02-08 10:51:37 -07:00
|
|
|
#include <linux/sched/task_stack.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2007-07-21 09:10:01 -06:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/random.h>
|
2009-04-12 09:07:25 -06:00
|
|
|
#include <linux/elf.h>
|
2014-09-23 11:50:52 -06:00
|
|
|
#include <linux/cpu.h>
|
2016-06-28 05:35:38 -06:00
|
|
|
#include <linux/ptrace.h>
|
2015-12-10 20:20:21 -07:00
|
|
|
#include <asm/pvclock.h>
|
2007-07-21 09:10:01 -06:00
|
|
|
#include <asm/vgtod.h>
|
|
|
|
#include <asm/proto.h>
|
2008-01-30 05:30:41 -07:00
|
|
|
#include <asm/vdso.h>
|
2014-09-23 11:50:57 -06:00
|
|
|
#include <asm/vvar.h>
|
2011-07-21 13:47:10 -06:00
|
|
|
#include <asm/page.h>
|
2014-09-23 11:50:52 -06:00
|
|
|
#include <asm/desc.h>
|
2016-01-26 14:12:04 -07:00
|
|
|
#include <asm/cpufeature.h>
|
2017-03-03 06:21:42 -07:00
|
|
|
#include <asm/mshyperv.h>
|
2007-07-21 09:10:01 -06:00
|
|
|
|
2014-03-17 16:22:08 -06:00
|
|
|
#if defined(CONFIG_X86_64)
|
2014-05-05 13:19:32 -06:00
|
|
|
unsigned int __read_mostly vdso64_enabled = 1;
|
2014-03-17 16:22:08 -06:00
|
|
|
#endif
|
2012-02-19 12:38:06 -07:00
|
|
|
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-05 13:19:34 -06:00
|
|
|
void __init init_vdso_image(const struct vdso_image *image)
|
2012-02-19 12:38:06 -07:00
|
|
|
{
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-05 13:19:34 -06:00
|
|
|
BUG_ON(image->size % PAGE_SIZE != 0);
|
2012-02-19 12:38:06 -07:00
|
|
|
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-05 13:19:34 -06:00
|
|
|
apply_alternatives((struct alt_instr *)(image->data + image->alt),
|
|
|
|
(struct alt_instr *)(image->data + image->alt +
|
|
|
|
image->alt_len));
|
2012-02-19 12:38:06 -07:00
|
|
|
}
|
2011-07-13 07:24:11 -06:00
|
|
|
|
2007-07-21 09:10:01 -06:00
|
|
|
struct linux_binprm;
|
|
|
|
|
2018-10-26 16:04:16 -06:00
|
|
|
static vm_fault_t vdso_fault(const struct vm_special_mapping *sm,
|
2015-12-29 21:12:22 -07:00
|
|
|
struct vm_area_struct *vma, struct vm_fault *vmf)
|
|
|
|
{
|
|
|
|
const struct vdso_image *image = vma->vm_mm->context.vdso_image;
|
|
|
|
|
|
|
|
if (!image || (vmf->pgoff << PAGE_SHIFT) >= image->size)
|
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
|
|
|
|
vmf->page = virt_to_page(image->data + (vmf->pgoff << PAGE_SHIFT));
|
|
|
|
get_page(vmf->page);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-28 05:35:38 -06:00
|
|
|
static void vdso_fix_landing(const struct vdso_image *image,
|
|
|
|
struct vm_area_struct *new_vma)
|
|
|
|
{
|
|
|
|
#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
|
|
|
|
if (in_ia32_syscall() && image == &vdso_image_32) {
|
|
|
|
struct pt_regs *regs = current_pt_regs();
|
|
|
|
unsigned long vdso_land = image->sym_int80_landing_pad;
|
|
|
|
unsigned long old_land_addr = vdso_land +
|
|
|
|
(unsigned long)current->mm->context.vdso;
|
|
|
|
|
|
|
|
/* Fixing userspace landing - look at do_fast_syscall_32 */
|
|
|
|
if (regs->ip == old_land_addr)
|
|
|
|
regs->ip = new_vma->vm_start + vdso_land;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vdso_mremap(const struct vm_special_mapping *sm,
|
|
|
|
struct vm_area_struct *new_vma)
|
|
|
|
{
|
|
|
|
unsigned long new_size = new_vma->vm_end - new_vma->vm_start;
|
|
|
|
const struct vdso_image *image = current->mm->context.vdso_image;
|
|
|
|
|
|
|
|
if (image->size != new_size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
vdso_fix_landing(image, new_vma);
|
|
|
|
current->mm->context.vdso = (void __user *)new_vma->vm_start;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-12-29 21:12:22 -07:00
|
|
|
|
2018-10-26 16:04:16 -06:00
|
|
|
static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
|
2015-12-29 21:12:23 -07:00
|
|
|
struct vm_area_struct *vma, struct vm_fault *vmf)
|
|
|
|
{
|
|
|
|
const struct vdso_image *image = vma->vm_mm->context.vdso_image;
|
|
|
|
long sym_offset;
|
|
|
|
|
|
|
|
if (!image)
|
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
|
|
|
|
sym_offset = (long)(vmf->pgoff << PAGE_SHIFT) +
|
|
|
|
image->sym_vvar_start;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity check: a symbol offset of zero means that the page
|
|
|
|
* does not exist for this vdso image, not that the page is at
|
|
|
|
* offset zero relative to the text mapping. This should be
|
|
|
|
* impossible here, because sym_offset should only be zero for
|
|
|
|
* the page past the end of the vvar mapping.
|
|
|
|
*/
|
|
|
|
if (sym_offset == 0)
|
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
|
|
|
|
if (sym_offset == image->sym_vvar_page) {
|
2018-10-26 16:04:16 -06:00
|
|
|
return vmf_insert_pfn(vma, vmf->address,
|
|
|
|
__pa_symbol(&__vvar_page) >> PAGE_SHIFT);
|
2015-12-29 21:12:23 -07:00
|
|
|
} else if (sym_offset == image->sym_pvclock_page) {
|
|
|
|
struct pvclock_vsyscall_time_info *pvti =
|
2017-11-08 10:19:55 -07:00
|
|
|
pvclock_get_pvti_cpu0_va();
|
2015-12-29 21:12:24 -07:00
|
|
|
if (pvti && vclock_was_used(VCLOCK_PVCLOCK)) {
|
2018-10-26 16:04:16 -06:00
|
|
|
return vmf_insert_pfn_prot(vma, vmf->address,
|
|
|
|
__pa(pvti) >> PAGE_SHIFT,
|
|
|
|
pgprot_decrypted(vma->vm_page_prot));
|
2015-12-29 21:12:23 -07:00
|
|
|
}
|
2017-03-03 06:21:42 -07:00
|
|
|
} else if (sym_offset == image->sym_hvclock_page) {
|
|
|
|
struct ms_hyperv_tsc_page *tsc_pg = hv_get_tsc_page();
|
|
|
|
|
|
|
|
if (tsc_pg && vclock_was_used(VCLOCK_HVCLOCK))
|
2018-10-26 16:04:16 -06:00
|
|
|
return vmf_insert_pfn(vma, vmf->address,
|
|
|
|
vmalloc_to_pfn(tsc_pg));
|
2015-12-29 21:12:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
|
2016-09-05 07:33:05 -06:00
|
|
|
static const struct vm_special_mapping vdso_mapping = {
|
|
|
|
.name = "[vdso]",
|
|
|
|
.fault = vdso_fault,
|
|
|
|
.mremap = vdso_mremap,
|
|
|
|
};
|
|
|
|
static const struct vm_special_mapping vvar_mapping = {
|
|
|
|
.name = "[vvar]",
|
|
|
|
.fault = vvar_fault,
|
|
|
|
};
|
|
|
|
|
2016-09-05 07:33:04 -06:00
|
|
|
/*
|
|
|
|
* Add vdso and vvar mappings to current process.
|
|
|
|
* @image - blob to map
|
|
|
|
* @addr - request a specific address (zero to map at free addr)
|
|
|
|
*/
|
|
|
|
static int map_vdso(const struct vdso_image *image, unsigned long addr)
|
2007-07-21 09:10:01 -06:00
|
|
|
{
|
|
|
|
struct mm_struct *mm = current->mm;
|
2014-05-05 13:19:35 -06:00
|
|
|
struct vm_area_struct *vma;
|
2016-09-05 07:33:04 -06:00
|
|
|
unsigned long text_start;
|
2014-05-05 13:19:35 -06:00
|
|
|
int ret = 0;
|
2016-06-28 05:35:38 -06:00
|
|
|
|
2016-05-23 17:25:54 -06:00
|
|
|
if (down_write_killable(&mm->mmap_sem))
|
|
|
|
return -EINTR;
|
2014-05-05 13:19:35 -06:00
|
|
|
|
2014-07-10 19:13:15 -06:00
|
|
|
addr = get_unmapped_area(NULL, addr,
|
|
|
|
image->size - image->sym_vvar_start, 0, 0);
|
2007-07-21 09:10:01 -06:00
|
|
|
if (IS_ERR_VALUE(addr)) {
|
|
|
|
ret = addr;
|
|
|
|
goto up_fail;
|
|
|
|
}
|
|
|
|
|
2014-07-10 19:13:15 -06:00
|
|
|
text_start = addr - image->sym_vvar_start;
|
2009-06-05 06:04:51 -06:00
|
|
|
|
2014-05-05 13:19:35 -06:00
|
|
|
/*
|
|
|
|
* MAYWRITE to allow gdb to COW and set breakpoints
|
|
|
|
*/
|
2014-05-19 16:58:33 -06:00
|
|
|
vma = _install_special_mapping(mm,
|
2014-07-10 19:13:15 -06:00
|
|
|
text_start,
|
2014-05-19 16:58:33 -06:00
|
|
|
image->size,
|
|
|
|
VM_READ|VM_EXEC|
|
|
|
|
VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
|
2016-06-28 05:35:38 -06:00
|
|
|
&vdso_mapping);
|
2014-05-05 13:19:35 -06:00
|
|
|
|
2014-05-19 16:58:33 -06:00
|
|
|
if (IS_ERR(vma)) {
|
|
|
|
ret = PTR_ERR(vma);
|
2014-05-05 13:19:35 -06:00
|
|
|
goto up_fail;
|
2014-05-19 16:58:33 -06:00
|
|
|
}
|
2014-05-05 13:19:35 -06:00
|
|
|
|
|
|
|
vma = _install_special_mapping(mm,
|
2014-07-10 19:13:15 -06:00
|
|
|
addr,
|
|
|
|
-image->sym_vvar_start,
|
2015-12-29 21:12:23 -07:00
|
|
|
VM_READ|VM_MAYREAD|VM_IO|VM_DONTDUMP|
|
|
|
|
VM_PFNMAP,
|
2014-05-19 16:58:33 -06:00
|
|
|
&vvar_mapping);
|
2014-05-05 13:19:35 -06:00
|
|
|
|
|
|
|
if (IS_ERR(vma)) {
|
|
|
|
ret = PTR_ERR(vma);
|
2017-02-24 15:58:22 -07:00
|
|
|
do_munmap(mm, text_start, image->size, NULL);
|
2016-10-27 08:15:16 -06:00
|
|
|
} else {
|
|
|
|
current->mm->context.vdso = (void __user *)text_start;
|
|
|
|
current->mm->context.vdso_image = image;
|
2009-06-05 06:04:51 -06:00
|
|
|
}
|
2007-07-21 09:10:01 -06:00
|
|
|
|
|
|
|
up_fail:
|
|
|
|
up_write(&mm->mmap_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-09-15 00:56:21 -06:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
/*
|
|
|
|
* Put the vdso above the (randomized) stack with another randomized
|
|
|
|
* offset. This way there is no hole in the middle of address space.
|
|
|
|
* To save memory make sure it is still in the same PTE as the stack
|
|
|
|
* top. This doesn't give that many random bits.
|
|
|
|
*
|
|
|
|
* Note that this algorithm is imperfect: the distribution of the vdso
|
|
|
|
* start address within a PMD is biased toward the end.
|
|
|
|
*
|
|
|
|
* Only used for the 64-bit and x32 vdsos.
|
|
|
|
*/
|
|
|
|
static unsigned long vdso_addr(unsigned long start, unsigned len)
|
|
|
|
{
|
|
|
|
unsigned long addr, end;
|
|
|
|
unsigned offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Round up the start address. It can start out unaligned as a result
|
|
|
|
* of stack start randomization.
|
|
|
|
*/
|
|
|
|
start = PAGE_ALIGN(start);
|
|
|
|
|
|
|
|
/* Round the lowest possible end address up to a PMD boundary. */
|
|
|
|
end = (start + len + PMD_SIZE - 1) & PMD_MASK;
|
|
|
|
if (end >= TASK_SIZE_MAX)
|
|
|
|
end = TASK_SIZE_MAX;
|
|
|
|
end -= len;
|
|
|
|
|
|
|
|
if (end > start) {
|
|
|
|
offset = get_random_int() % (((end - start) >> PAGE_SHIFT) + 1);
|
|
|
|
addr = start + (offset << PAGE_SHIFT);
|
|
|
|
} else {
|
|
|
|
addr = start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Forcibly align the final address in case we have a hardware
|
|
|
|
* issue that requires alignment for performance reasons.
|
|
|
|
*/
|
|
|
|
addr = align_vdso_addr(addr);
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2016-09-05 07:33:04 -06:00
|
|
|
static int map_vdso_randomized(const struct vdso_image *image)
|
|
|
|
{
|
2016-09-15 00:56:21 -06:00
|
|
|
unsigned long addr = vdso_addr(current->mm->start_stack, image->size-image->sym_vvar_start);
|
|
|
|
|
2016-09-05 07:33:04 -06:00
|
|
|
return map_vdso(image, addr);
|
|
|
|
}
|
2016-09-15 00:56:21 -06:00
|
|
|
#endif
|
2016-09-05 07:33:04 -06:00
|
|
|
|
2016-09-05 07:33:05 -06:00
|
|
|
int map_vdso_once(const struct vdso_image *image, unsigned long addr)
|
|
|
|
{
|
|
|
|
struct mm_struct *mm = current->mm;
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
|
|
|
|
down_write(&mm->mmap_sem);
|
|
|
|
/*
|
|
|
|
* Check if we have already mapped vdso blob - fail to prevent
|
|
|
|
* abusing from userspace install_speciall_mapping, which may
|
|
|
|
* not do accounting and rlimit right.
|
|
|
|
* We could search vma near context.vdso, but it's a slowpath,
|
2018-12-03 02:47:34 -07:00
|
|
|
* so let's explicitly check all VMAs to be completely sure.
|
2016-09-05 07:33:05 -06:00
|
|
|
*/
|
|
|
|
for (vma = mm->mmap; vma; vma = vma->vm_next) {
|
|
|
|
if (vma_is_special_mapping(vma, &vdso_mapping) ||
|
|
|
|
vma_is_special_mapping(vma, &vvar_mapping)) {
|
|
|
|
up_write(&mm->mmap_sem);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
up_write(&mm->mmap_sem);
|
|
|
|
|
|
|
|
return map_vdso(image, addr);
|
|
|
|
}
|
|
|
|
|
2015-06-22 05:55:15 -06:00
|
|
|
#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
|
2014-05-05 13:19:35 -06:00
|
|
|
static int load_vdso32(void)
|
|
|
|
{
|
|
|
|
if (vdso32_enabled != 1) /* Other values all mean "disabled" */
|
|
|
|
return 0;
|
|
|
|
|
2016-09-05 07:33:04 -06:00
|
|
|
return map_vdso(&vdso_image_32, 0);
|
2014-05-05 13:19:35 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
2012-02-19 12:38:06 -07:00
|
|
|
int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
|
|
|
{
|
2014-05-05 13:19:35 -06:00
|
|
|
if (!vdso64_enabled)
|
|
|
|
return 0;
|
|
|
|
|
2016-09-05 07:33:04 -06:00
|
|
|
return map_vdso_randomized(&vdso_image_64);
|
2012-02-19 12:38:06 -07:00
|
|
|
}
|
|
|
|
|
2014-05-05 13:19:35 -06:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
|
|
|
|
int uses_interp)
|
|
|
|
{
|
2012-02-19 12:38:06 -07:00
|
|
|
#ifdef CONFIG_X86_X32_ABI
|
2014-05-05 13:19:35 -06:00
|
|
|
if (test_thread_flag(TIF_X32)) {
|
|
|
|
if (!vdso64_enabled)
|
|
|
|
return 0;
|
2016-09-05 07:33:04 -06:00
|
|
|
return map_vdso_randomized(&vdso_image_x32);
|
2014-05-05 13:19:35 -06:00
|
|
|
}
|
|
|
|
#endif
|
2015-06-22 05:55:15 -06:00
|
|
|
#ifdef CONFIG_IA32_EMULATION
|
2014-05-05 13:19:35 -06:00
|
|
|
return load_vdso32();
|
2015-06-22 05:55:15 -06:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2014-05-05 13:19:35 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
2012-02-19 12:38:06 -07:00
|
|
|
{
|
2014-05-05 13:19:35 -06:00
|
|
|
return load_vdso32();
|
2012-02-19 12:38:06 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-05 13:19:35 -06:00
|
|
|
#ifdef CONFIG_X86_64
|
2007-07-21 09:10:01 -06:00
|
|
|
static __init int vdso_setup(char *s)
|
|
|
|
{
|
2014-05-05 13:19:32 -06:00
|
|
|
vdso64_enabled = simple_strtoul(s, NULL, 0);
|
2007-07-21 09:10:01 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
__setup("vdso=", vdso_setup);
|
2014-09-23 11:50:52 -06:00
|
|
|
|
2014-09-23 11:50:57 -06:00
|
|
|
static int __init init_vdso(void)
|
2014-09-23 11:50:52 -06:00
|
|
|
{
|
2014-09-23 11:50:57 -06:00
|
|
|
init_vdso_image(&vdso_image_64);
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_X32_ABI
|
|
|
|
init_vdso_image(&vdso_image_x32);
|
|
|
|
#endif
|
|
|
|
|
2018-09-18 17:08:59 -06:00
|
|
|
return 0;
|
2014-09-23 11:50:52 -06:00
|
|
|
}
|
2014-09-23 11:50:57 -06:00
|
|
|
subsys_initcall(init_vdso);
|
|
|
|
#endif /* CONFIG_X86_64 */
|