|
@@ -26,16 +26,10 @@
|
|
|
#include <asm/vdso.h>
|
|
#include <asm/vdso.h>
|
|
|
#include <asm/proto.h>
|
|
#include <asm/proto.h>
|
|
|
|
|
|
|
|
-enum {
|
|
|
|
|
- VDSO_DISABLED = 0,
|
|
|
|
|
- VDSO_ENABLED = 1,
|
|
|
|
|
- VDSO_COMPAT = 2,
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
#ifdef CONFIG_COMPAT_VDSO
|
|
#ifdef CONFIG_COMPAT_VDSO
|
|
|
-#define VDSO_DEFAULT VDSO_COMPAT
|
|
|
|
|
|
|
+#define VDSO_DEFAULT 0
|
|
|
#else
|
|
#else
|
|
|
-#define VDSO_DEFAULT VDSO_ENABLED
|
|
|
|
|
|
|
+#define VDSO_DEFAULT 1
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
|
#ifdef CONFIG_X86_64
|
|
@@ -43,13 +37,6 @@ enum {
|
|
|
#define arch_setup_additional_pages syscall32_setup_pages
|
|
#define arch_setup_additional_pages syscall32_setup_pages
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
-/*
|
|
|
|
|
- * This is the difference between the prelinked addresses in the vDSO images
|
|
|
|
|
- * and the VDSO_HIGH_BASE address where CONFIG_COMPAT_VDSO places the vDSO
|
|
|
|
|
- * in the user address space.
|
|
|
|
|
- */
|
|
|
|
|
-#define VDSO_ADDR_ADJUST (VDSO_HIGH_BASE - (unsigned long)VDSO32_PRELINK)
|
|
|
|
|
-
|
|
|
|
|
/*
|
|
/*
|
|
|
* Should the kernel map a VDSO page into processes and pass its
|
|
* Should the kernel map a VDSO page into processes and pass its
|
|
|
* address down to glibc upon exec()?
|
|
* address down to glibc upon exec()?
|
|
@@ -60,6 +47,9 @@ static int __init vdso_setup(char *s)
|
|
|
{
|
|
{
|
|
|
vdso_enabled = simple_strtoul(s, NULL, 0);
|
|
vdso_enabled = simple_strtoul(s, NULL, 0);
|
|
|
|
|
|
|
|
|
|
+ if (vdso_enabled > 1)
|
|
|
|
|
+ pr_warn("vdso32 values other than 0 and 1 are no longer allowed; vdso disabled\n");
|
|
|
|
|
+
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -76,123 +66,6 @@ __setup_param("vdso=", vdso32_setup, vdso_setup, 0);
|
|
|
EXPORT_SYMBOL_GPL(vdso_enabled);
|
|
EXPORT_SYMBOL_GPL(vdso_enabled);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
-static __init void reloc_symtab(Elf32_Ehdr *ehdr,
|
|
|
|
|
- unsigned offset, unsigned size)
|
|
|
|
|
-{
|
|
|
|
|
- Elf32_Sym *sym = (void *)ehdr + offset;
|
|
|
|
|
- unsigned nsym = size / sizeof(*sym);
|
|
|
|
|
- unsigned i;
|
|
|
|
|
-
|
|
|
|
|
- for(i = 0; i < nsym; i++, sym++) {
|
|
|
|
|
- if (sym->st_shndx == SHN_UNDEF ||
|
|
|
|
|
- sym->st_shndx == SHN_ABS)
|
|
|
|
|
- continue; /* skip */
|
|
|
|
|
-
|
|
|
|
|
- if (sym->st_shndx > SHN_LORESERVE) {
|
|
|
|
|
- printk(KERN_INFO "VDSO: unexpected st_shndx %x\n",
|
|
|
|
|
- sym->st_shndx);
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- switch(ELF_ST_TYPE(sym->st_info)) {
|
|
|
|
|
- case STT_OBJECT:
|
|
|
|
|
- case STT_FUNC:
|
|
|
|
|
- case STT_SECTION:
|
|
|
|
|
- case STT_FILE:
|
|
|
|
|
- sym->st_value += VDSO_ADDR_ADJUST;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-static __init void reloc_dyn(Elf32_Ehdr *ehdr, unsigned offset)
|
|
|
|
|
-{
|
|
|
|
|
- Elf32_Dyn *dyn = (void *)ehdr + offset;
|
|
|
|
|
-
|
|
|
|
|
- for(; dyn->d_tag != DT_NULL; dyn++)
|
|
|
|
|
- switch(dyn->d_tag) {
|
|
|
|
|
- case DT_PLTGOT:
|
|
|
|
|
- case DT_HASH:
|
|
|
|
|
- case DT_STRTAB:
|
|
|
|
|
- case DT_SYMTAB:
|
|
|
|
|
- case DT_RELA:
|
|
|
|
|
- case DT_INIT:
|
|
|
|
|
- case DT_FINI:
|
|
|
|
|
- case DT_REL:
|
|
|
|
|
- case DT_DEBUG:
|
|
|
|
|
- case DT_JMPREL:
|
|
|
|
|
- case DT_VERSYM:
|
|
|
|
|
- case DT_VERDEF:
|
|
|
|
|
- case DT_VERNEED:
|
|
|
|
|
- case DT_ADDRRNGLO ... DT_ADDRRNGHI:
|
|
|
|
|
- /* definitely pointers needing relocation */
|
|
|
|
|
- dyn->d_un.d_ptr += VDSO_ADDR_ADJUST;
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
- case DT_ENCODING ... OLD_DT_LOOS-1:
|
|
|
|
|
- case DT_LOOS ... DT_HIOS-1:
|
|
|
|
|
- /* Tags above DT_ENCODING are pointers if
|
|
|
|
|
- they're even */
|
|
|
|
|
- if (dyn->d_tag >= DT_ENCODING &&
|
|
|
|
|
- (dyn->d_tag & 1) == 0)
|
|
|
|
|
- dyn->d_un.d_ptr += VDSO_ADDR_ADJUST;
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
- case DT_VERDEFNUM:
|
|
|
|
|
- case DT_VERNEEDNUM:
|
|
|
|
|
- case DT_FLAGS_1:
|
|
|
|
|
- case DT_RELACOUNT:
|
|
|
|
|
- case DT_RELCOUNT:
|
|
|
|
|
- case DT_VALRNGLO ... DT_VALRNGHI:
|
|
|
|
|
- /* definitely not pointers */
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
- case OLD_DT_LOOS ... DT_LOOS-1:
|
|
|
|
|
- case DT_HIOS ... DT_VALRNGLO-1:
|
|
|
|
|
- default:
|
|
|
|
|
- if (dyn->d_tag > DT_ENCODING)
|
|
|
|
|
- printk(KERN_INFO "VDSO: unexpected DT_tag %x\n",
|
|
|
|
|
- dyn->d_tag);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-static __init void relocate_vdso(Elf32_Ehdr *ehdr)
|
|
|
|
|
-{
|
|
|
|
|
- Elf32_Phdr *phdr;
|
|
|
|
|
- Elf32_Shdr *shdr;
|
|
|
|
|
- int i;
|
|
|
|
|
-
|
|
|
|
|
- BUG_ON(memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0 ||
|
|
|
|
|
- !elf_check_arch_ia32(ehdr) ||
|
|
|
|
|
- ehdr->e_type != ET_DYN);
|
|
|
|
|
-
|
|
|
|
|
- ehdr->e_entry += VDSO_ADDR_ADJUST;
|
|
|
|
|
-
|
|
|
|
|
- /* rebase phdrs */
|
|
|
|
|
- phdr = (void *)ehdr + ehdr->e_phoff;
|
|
|
|
|
- for (i = 0; i < ehdr->e_phnum; i++) {
|
|
|
|
|
- phdr[i].p_vaddr += VDSO_ADDR_ADJUST;
|
|
|
|
|
-
|
|
|
|
|
- /* relocate dynamic stuff */
|
|
|
|
|
- if (phdr[i].p_type == PT_DYNAMIC)
|
|
|
|
|
- reloc_dyn(ehdr, phdr[i].p_offset);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /* rebase sections */
|
|
|
|
|
- shdr = (void *)ehdr + ehdr->e_shoff;
|
|
|
|
|
- for(i = 0; i < ehdr->e_shnum; i++) {
|
|
|
|
|
- if (!(shdr[i].sh_flags & SHF_ALLOC))
|
|
|
|
|
- continue;
|
|
|
|
|
-
|
|
|
|
|
- shdr[i].sh_addr += VDSO_ADDR_ADJUST;
|
|
|
|
|
-
|
|
|
|
|
- if (shdr[i].sh_type == SHT_SYMTAB ||
|
|
|
|
|
- shdr[i].sh_type == SHT_DYNSYM)
|
|
|
|
|
- reloc_symtab(ehdr, shdr[i].sh_offset,
|
|
|
|
|
- shdr[i].sh_size);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
static struct page *vdso32_pages[1];
|
|
static struct page *vdso32_pages[1];
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
|
#ifdef CONFIG_X86_64
|
|
@@ -212,12 +85,6 @@ void syscall32_cpu_init(void)
|
|
|
wrmsrl(MSR_CSTAR, ia32_cstar_target);
|
|
wrmsrl(MSR_CSTAR, ia32_cstar_target);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#define compat_uses_vma 1
|
|
|
|
|
-
|
|
|
|
|
-static inline void map_compat_vdso(int map)
|
|
|
|
|
-{
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
#else /* CONFIG_X86_32 */
|
|
#else /* CONFIG_X86_32 */
|
|
|
|
|
|
|
|
#define vdso32_sysenter() (boot_cpu_has(X86_FEATURE_SEP))
|
|
#define vdso32_sysenter() (boot_cpu_has(X86_FEATURE_SEP))
|
|
@@ -241,37 +108,6 @@ void enable_sep_cpu(void)
|
|
|
put_cpu();
|
|
put_cpu();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static struct vm_area_struct gate_vma;
|
|
|
|
|
-
|
|
|
|
|
-static int __init gate_vma_init(void)
|
|
|
|
|
-{
|
|
|
|
|
- gate_vma.vm_mm = NULL;
|
|
|
|
|
- gate_vma.vm_start = FIXADDR_USER_START;
|
|
|
|
|
- gate_vma.vm_end = FIXADDR_USER_END;
|
|
|
|
|
- gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
|
|
|
|
|
- gate_vma.vm_page_prot = __P101;
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-#define compat_uses_vma 0
|
|
|
|
|
-
|
|
|
|
|
-static void map_compat_vdso(int map)
|
|
|
|
|
-{
|
|
|
|
|
- static int vdso_mapped;
|
|
|
|
|
-
|
|
|
|
|
- if (map == vdso_mapped)
|
|
|
|
|
- return;
|
|
|
|
|
-
|
|
|
|
|
- vdso_mapped = map;
|
|
|
|
|
-
|
|
|
|
|
- __set_fixmap(FIX_VDSO, page_to_pfn(vdso32_pages[0]) << PAGE_SHIFT,
|
|
|
|
|
- map ? PAGE_READONLY_EXEC : PAGE_NONE);
|
|
|
|
|
-
|
|
|
|
|
- /* flush stray tlbs */
|
|
|
|
|
- flush_tlb_all();
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
#endif /* CONFIG_X86_64 */
|
|
#endif /* CONFIG_X86_64 */
|
|
|
|
|
|
|
|
int __init sysenter_setup(void)
|
|
int __init sysenter_setup(void)
|
|
@@ -282,10 +118,6 @@ int __init sysenter_setup(void)
|
|
|
|
|
|
|
|
vdso32_pages[0] = virt_to_page(syscall_page);
|
|
vdso32_pages[0] = virt_to_page(syscall_page);
|
|
|
|
|
|
|
|
-#ifdef CONFIG_X86_32
|
|
|
|
|
- gate_vma_init();
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
if (vdso32_syscall()) {
|
|
if (vdso32_syscall()) {
|
|
|
vsyscall = &vdso32_syscall_start;
|
|
vsyscall = &vdso32_syscall_start;
|
|
|
vsyscall_len = &vdso32_syscall_end - &vdso32_syscall_start;
|
|
vsyscall_len = &vdso32_syscall_end - &vdso32_syscall_start;
|
|
@@ -298,7 +130,6 @@ int __init sysenter_setup(void)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
memcpy(syscall_page, vsyscall, vsyscall_len);
|
|
memcpy(syscall_page, vsyscall, vsyscall_len);
|
|
|
- relocate_vdso(syscall_page);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -309,48 +140,35 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
|
|
struct mm_struct *mm = current->mm;
|
|
struct mm_struct *mm = current->mm;
|
|
|
unsigned long addr;
|
|
unsigned long addr;
|
|
|
int ret = 0;
|
|
int ret = 0;
|
|
|
- bool compat;
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_X32_ABI
|
|
#ifdef CONFIG_X86_X32_ABI
|
|
|
if (test_thread_flag(TIF_X32))
|
|
if (test_thread_flag(TIF_X32))
|
|
|
return x32_setup_additional_pages(bprm, uses_interp);
|
|
return x32_setup_additional_pages(bprm, uses_interp);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- if (vdso_enabled == VDSO_DISABLED)
|
|
|
|
|
|
|
+ if (vdso_enabled != 1) /* Other values all mean "disabled" */
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
down_write(&mm->mmap_sem);
|
|
down_write(&mm->mmap_sem);
|
|
|
|
|
|
|
|
- /* Test compat mode once here, in case someone
|
|
|
|
|
- changes it via sysctl */
|
|
|
|
|
- compat = (vdso_enabled == VDSO_COMPAT);
|
|
|
|
|
-
|
|
|
|
|
- map_compat_vdso(compat);
|
|
|
|
|
-
|
|
|
|
|
- if (compat)
|
|
|
|
|
- addr = VDSO_HIGH_BASE;
|
|
|
|
|
- else {
|
|
|
|
|
- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
|
|
|
|
|
- if (IS_ERR_VALUE(addr)) {
|
|
|
|
|
- ret = addr;
|
|
|
|
|
- goto up_fail;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
|
|
|
|
|
+ if (IS_ERR_VALUE(addr)) {
|
|
|
|
|
+ ret = addr;
|
|
|
|
|
+ goto up_fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
current->mm->context.vdso = (void *)addr;
|
|
current->mm->context.vdso = (void *)addr;
|
|
|
|
|
|
|
|
- if (compat_uses_vma || !compat) {
|
|
|
|
|
- /*
|
|
|
|
|
- * MAYWRITE to allow gdb to COW and set breakpoints
|
|
|
|
|
- */
|
|
|
|
|
- ret = install_special_mapping(mm, addr, PAGE_SIZE,
|
|
|
|
|
- VM_READ|VM_EXEC|
|
|
|
|
|
- VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
|
|
|
|
|
- vdso32_pages);
|
|
|
|
|
-
|
|
|
|
|
- if (ret)
|
|
|
|
|
- goto up_fail;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * MAYWRITE to allow gdb to COW and set breakpoints
|
|
|
|
|
+ */
|
|
|
|
|
+ ret = install_special_mapping(mm, addr, PAGE_SIZE,
|
|
|
|
|
+ VM_READ|VM_EXEC|
|
|
|
|
|
+ VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
|
|
|
|
|
+ vdso32_pages);
|
|
|
|
|
+
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ goto up_fail;
|
|
|
|
|
|
|
|
current_thread_info()->sysenter_return =
|
|
current_thread_info()->sysenter_return =
|
|
|
VDSO32_SYMBOL(addr, SYSENTER_RETURN);
|
|
VDSO32_SYMBOL(addr, SYSENTER_RETURN);
|
|
@@ -411,20 +229,12 @@ const char *arch_vma_name(struct vm_area_struct *vma)
|
|
|
|
|
|
|
|
struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
|
|
struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
|
|
|
{
|
|
{
|
|
|
- /*
|
|
|
|
|
- * Check to see if the corresponding task was created in compat vdso
|
|
|
|
|
- * mode.
|
|
|
|
|
- */
|
|
|
|
|
- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
|
|
|
|
|
- return &gate_vma;
|
|
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int in_gate_area(struct mm_struct *mm, unsigned long addr)
|
|
int in_gate_area(struct mm_struct *mm, unsigned long addr)
|
|
|
{
|
|
{
|
|
|
- const struct vm_area_struct *vma = get_gate_vma(mm);
|
|
|
|
|
-
|
|
|
|
|
- return vma && addr >= vma->vm_start && addr < vma->vm_end;
|
|
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int in_gate_area_no_mm(unsigned long addr)
|
|
int in_gate_area_no_mm(unsigned long addr)
|