Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * (C) Copyright 2002 Linus Torvalds |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 3 | * Portions based on the vdso-randomization code from exec-shield: |
| 4 | * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This file contains the needed initializations to support sysenter. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/smp.h> |
| 11 | #include <linux/thread_info.h> |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/gfp.h> |
| 14 | #include <linux/string.h> |
| 15 | #include <linux/elf.h> |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 16 | #include <linux/mm.h> |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 17 | #include <linux/err.h> |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include <asm/cpufeature.h> |
| 21 | #include <asm/msr.h> |
| 22 | #include <asm/pgtable.h> |
| 23 | #include <asm/unistd.h> |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 24 | #include <asm/elf.h> |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 25 | #include <asm/tlbflush.h> |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 26 | #include <asm/vdso.h> |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 27 | #include <asm/proto.h> |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 28 | |
| 29 | enum { |
| 30 | VDSO_DISABLED = 0, |
| 31 | VDSO_ENABLED = 1, |
| 32 | VDSO_COMPAT = 2, |
| 33 | }; |
| 34 | |
| 35 | #ifdef CONFIG_COMPAT_VDSO |
| 36 | #define VDSO_DEFAULT VDSO_COMPAT |
| 37 | #else |
| 38 | #define VDSO_DEFAULT VDSO_ENABLED |
| 39 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 41 | #ifdef CONFIG_X86_64 |
| 42 | #define vdso_enabled sysctl_vsyscall32 |
| 43 | #define arch_setup_additional_pages syscall32_setup_pages |
| 44 | #endif |
| 45 | |
| 46 | /* |
| 47 | * This is the difference between the prelinked addresses in the vDSO images |
| 48 | * and the VDSO_HIGH_BASE address where CONFIG_COMPAT_VDSO places the vDSO |
| 49 | * in the user address space. |
| 50 | */ |
| 51 | #define VDSO_ADDR_ADJUST (VDSO_HIGH_BASE - (unsigned long)VDSO32_PRELINK) |
| 52 | |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 53 | /* |
| 54 | * Should the kernel map a VDSO page into processes and pass its |
| 55 | * address down to glibc upon exec()? |
| 56 | */ |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 57 | unsigned int __read_mostly vdso_enabled = VDSO_DEFAULT; |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 58 | |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 59 | static int __init vdso_setup(char *s) |
| 60 | { |
| 61 | vdso_enabled = simple_strtoul(s, NULL, 0); |
| 62 | |
| 63 | return 1; |
| 64 | } |
| 65 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 66 | /* |
| 67 | * For consistency, the argument vdso32=[012] affects the 32-bit vDSO |
| 68 | * behavior on both 64-bit and 32-bit kernels. |
| 69 | * On 32-bit kernels, vdso=[012] means the same thing. |
| 70 | */ |
| 71 | __setup("vdso32=", vdso_setup); |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 72 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 73 | #ifdef CONFIG_X86_32 |
| 74 | __setup_param("vdso=", vdso32_setup, vdso_setup, 0); |
| 75 | |
| 76 | EXPORT_SYMBOL_GPL(vdso_enabled); |
| 77 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 79 | static __init void reloc_symtab(Elf32_Ehdr *ehdr, |
| 80 | unsigned offset, unsigned size) |
| 81 | { |
| 82 | Elf32_Sym *sym = (void *)ehdr + offset; |
| 83 | unsigned nsym = size / sizeof(*sym); |
| 84 | unsigned i; |
| 85 | |
| 86 | for(i = 0; i < nsym; i++, sym++) { |
| 87 | if (sym->st_shndx == SHN_UNDEF || |
| 88 | sym->st_shndx == SHN_ABS) |
| 89 | continue; /* skip */ |
| 90 | |
| 91 | if (sym->st_shndx > SHN_LORESERVE) { |
| 92 | printk(KERN_INFO "VDSO: unexpected st_shndx %x\n", |
| 93 | sym->st_shndx); |
| 94 | continue; |
| 95 | } |
| 96 | |
| 97 | switch(ELF_ST_TYPE(sym->st_info)) { |
| 98 | case STT_OBJECT: |
| 99 | case STT_FUNC: |
| 100 | case STT_SECTION: |
| 101 | case STT_FILE: |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 102 | sym->st_value += VDSO_ADDR_ADJUST; |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | static __init void reloc_dyn(Elf32_Ehdr *ehdr, unsigned offset) |
| 108 | { |
| 109 | Elf32_Dyn *dyn = (void *)ehdr + offset; |
| 110 | |
| 111 | for(; dyn->d_tag != DT_NULL; dyn++) |
| 112 | switch(dyn->d_tag) { |
| 113 | case DT_PLTGOT: |
| 114 | case DT_HASH: |
| 115 | case DT_STRTAB: |
| 116 | case DT_SYMTAB: |
| 117 | case DT_RELA: |
| 118 | case DT_INIT: |
| 119 | case DT_FINI: |
| 120 | case DT_REL: |
| 121 | case DT_DEBUG: |
| 122 | case DT_JMPREL: |
| 123 | case DT_VERSYM: |
| 124 | case DT_VERDEF: |
| 125 | case DT_VERNEED: |
| 126 | case DT_ADDRRNGLO ... DT_ADDRRNGHI: |
| 127 | /* definitely pointers needing relocation */ |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 128 | dyn->d_un.d_ptr += VDSO_ADDR_ADJUST; |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 129 | break; |
| 130 | |
| 131 | case DT_ENCODING ... OLD_DT_LOOS-1: |
| 132 | case DT_LOOS ... DT_HIOS-1: |
| 133 | /* Tags above DT_ENCODING are pointers if |
| 134 | they're even */ |
| 135 | if (dyn->d_tag >= DT_ENCODING && |
| 136 | (dyn->d_tag & 1) == 0) |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 137 | dyn->d_un.d_ptr += VDSO_ADDR_ADJUST; |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 138 | break; |
| 139 | |
| 140 | case DT_VERDEFNUM: |
| 141 | case DT_VERNEEDNUM: |
| 142 | case DT_FLAGS_1: |
| 143 | case DT_RELACOUNT: |
| 144 | case DT_RELCOUNT: |
| 145 | case DT_VALRNGLO ... DT_VALRNGHI: |
| 146 | /* definitely not pointers */ |
| 147 | break; |
| 148 | |
| 149 | case OLD_DT_LOOS ... DT_LOOS-1: |
| 150 | case DT_HIOS ... DT_VALRNGLO-1: |
| 151 | default: |
| 152 | if (dyn->d_tag > DT_ENCODING) |
| 153 | printk(KERN_INFO "VDSO: unexpected DT_tag %x\n", |
| 154 | dyn->d_tag); |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | static __init void relocate_vdso(Elf32_Ehdr *ehdr) |
| 160 | { |
| 161 | Elf32_Phdr *phdr; |
| 162 | Elf32_Shdr *shdr; |
| 163 | int i; |
| 164 | |
| 165 | BUG_ON(memcmp(ehdr->e_ident, ELFMAG, 4) != 0 || |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 166 | !elf_check_arch_ia32(ehdr) || |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 167 | ehdr->e_type != ET_DYN); |
| 168 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 169 | ehdr->e_entry += VDSO_ADDR_ADJUST; |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 170 | |
| 171 | /* rebase phdrs */ |
| 172 | phdr = (void *)ehdr + ehdr->e_phoff; |
| 173 | for (i = 0; i < ehdr->e_phnum; i++) { |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 174 | phdr[i].p_vaddr += VDSO_ADDR_ADJUST; |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 175 | |
| 176 | /* relocate dynamic stuff */ |
| 177 | if (phdr[i].p_type == PT_DYNAMIC) |
| 178 | reloc_dyn(ehdr, phdr[i].p_offset); |
| 179 | } |
| 180 | |
| 181 | /* rebase sections */ |
| 182 | shdr = (void *)ehdr + ehdr->e_shoff; |
| 183 | for(i = 0; i < ehdr->e_shnum; i++) { |
| 184 | if (!(shdr[i].sh_flags & SHF_ALLOC)) |
| 185 | continue; |
| 186 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 187 | shdr[i].sh_addr += VDSO_ADDR_ADJUST; |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 188 | |
| 189 | if (shdr[i].sh_type == SHT_SYMTAB || |
| 190 | shdr[i].sh_type == SHT_DYNSYM) |
| 191 | reloc_symtab(ehdr, shdr[i].sh_offset, |
| 192 | shdr[i].sh_size); |
| 193 | } |
| 194 | } |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 195 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 196 | /* |
| 197 | * These symbols are defined by vdso32.S to mark the bounds |
| 198 | * of the ELF DSO images included therein. |
| 199 | */ |
| 200 | extern const char vdso32_default_start, vdso32_default_end; |
| 201 | extern const char vdso32_sysenter_start, vdso32_sysenter_end; |
| 202 | static struct page *vdso32_pages[1]; |
| 203 | |
| 204 | #ifdef CONFIG_X86_64 |
| 205 | |
| 206 | static int use_sysenter __read_mostly = -1; |
| 207 | |
| 208 | #define vdso32_sysenter() (use_sysenter > 0) |
| 209 | |
| 210 | /* May not be __init: called during resume */ |
| 211 | void syscall32_cpu_init(void) |
| 212 | { |
| 213 | if (use_sysenter < 0) |
| 214 | use_sysenter = (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL); |
| 215 | |
| 216 | /* Load these always in case some future AMD CPU supports |
| 217 | SYSENTER from compat mode too. */ |
| 218 | checking_wrmsrl(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS); |
| 219 | checking_wrmsrl(MSR_IA32_SYSENTER_ESP, 0ULL); |
| 220 | checking_wrmsrl(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target); |
| 221 | |
| 222 | wrmsrl(MSR_CSTAR, ia32_cstar_target); |
| 223 | } |
| 224 | |
| 225 | #define compat_uses_vma 1 |
| 226 | |
| 227 | static inline void map_compat_vdso(int map) |
| 228 | { |
| 229 | } |
| 230 | |
| 231 | #else /* CONFIG_X86_32 */ |
| 232 | |
| 233 | #define vdso32_sysenter() (boot_cpu_has(X86_FEATURE_SEP)) |
| 234 | |
Li Shaohua | 6fe940d | 2005-06-25 14:54:53 -0700 | [diff] [blame] | 235 | void enable_sep_cpu(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
| 237 | int cpu = get_cpu(); |
| 238 | struct tss_struct *tss = &per_cpu(init_tss, cpu); |
| 239 | |
Li Shaohua | 6fe940d | 2005-06-25 14:54:53 -0700 | [diff] [blame] | 240 | if (!boot_cpu_has(X86_FEATURE_SEP)) { |
| 241 | put_cpu(); |
| 242 | return; |
| 243 | } |
| 244 | |
Rusty Russell | a75c54f | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 245 | tss->x86_tss.ss1 = __KERNEL_CS; |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 246 | tss->x86_tss.sp1 = sizeof(struct tss_struct) + (unsigned long) tss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0); |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 248 | wrmsr(MSR_IA32_SYSENTER_ESP, tss->x86_tss.sp1, 0); |
Roland McGrath | 0aa97fb22 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 249 | wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) ia32_sysenter_target, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | put_cpu(); |
| 251 | } |
| 252 | |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 253 | static struct vm_area_struct gate_vma; |
| 254 | |
| 255 | static int __init gate_vma_init(void) |
| 256 | { |
| 257 | gate_vma.vm_mm = NULL; |
| 258 | gate_vma.vm_start = FIXADDR_USER_START; |
| 259 | gate_vma.vm_end = FIXADDR_USER_END; |
| 260 | gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC; |
| 261 | gate_vma.vm_page_prot = __P101; |
| 262 | /* |
| 263 | * Make sure the vDSO gets into every core dump. |
| 264 | * Dumping its contents makes post-mortem fully interpretable later |
| 265 | * without matching up the same kernel and hardware config to see |
| 266 | * what PC values meant. |
| 267 | */ |
| 268 | gate_vma.vm_flags |= VM_ALWAYSDUMP; |
| 269 | return 0; |
| 270 | } |
| 271 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 272 | #define compat_uses_vma 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 274 | static void map_compat_vdso(int map) |
| 275 | { |
| 276 | static int vdso_mapped; |
| 277 | |
| 278 | if (map == vdso_mapped) |
| 279 | return; |
| 280 | |
| 281 | vdso_mapped = map; |
| 282 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 283 | __set_fixmap(FIX_VDSO, page_to_pfn(vdso32_pages[0]) << PAGE_SHIFT, |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 284 | map ? PAGE_READONLY_EXEC : PAGE_NONE); |
| 285 | |
| 286 | /* flush stray tlbs */ |
| 287 | flush_tlb_all(); |
| 288 | } |
| 289 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 290 | #endif /* CONFIG_X86_64 */ |
| 291 | |
Jeremy Fitzhardinge | a6c4e07 | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 292 | int __init sysenter_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
Roland McGrath | 7d91d53 | 2007-02-08 14:20:42 -0800 | [diff] [blame] | 294 | void *syscall_page = (void *)get_zeroed_page(GFP_ATOMIC); |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 295 | const void *vsyscall; |
| 296 | size_t vsyscall_len; |
| 297 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 298 | vdso32_pages[0] = virt_to_page(syscall_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 300 | #ifdef CONFIG_X86_32 |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 301 | gate_vma_init(); |
| 302 | |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 303 | printk("Compat vDSO mapped to %08lx.\n", __fix_to_virt(FIX_VDSO)); |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 304 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 306 | if (!vdso32_sysenter()) { |
| 307 | vsyscall = &vdso32_default_start; |
| 308 | vsyscall_len = &vdso32_default_end - &vdso32_default_start; |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 309 | } else { |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 310 | vsyscall = &vdso32_sysenter_start; |
| 311 | vsyscall_len = &vdso32_sysenter_end - &vdso32_sysenter_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Jeremy Fitzhardinge | d4f7a2c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 314 | memcpy(syscall_page, vsyscall, vsyscall_len); |
| 315 | relocate_vdso(syscall_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return 0; |
| 318 | } |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 319 | |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 320 | /* Setup a VMA at program startup for the vsyscall page */ |
| 321 | int arch_setup_additional_pages(struct linux_binprm *bprm, int exstack) |
| 322 | { |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 323 | struct mm_struct *mm = current->mm; |
| 324 | unsigned long addr; |
Zachary Amsden | 752783c | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 325 | int ret = 0; |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 326 | bool compat; |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 327 | |
Roland McGrath | 5de253c | 2008-04-09 01:30:06 -0700 | [diff] [blame^] | 328 | if (vdso_enabled == VDSO_DISABLED) |
| 329 | return 0; |
| 330 | |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 331 | down_write(&mm->mmap_sem); |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 332 | |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 333 | /* Test compat mode once here, in case someone |
| 334 | changes it via sysctl */ |
| 335 | compat = (vdso_enabled == VDSO_COMPAT); |
| 336 | |
| 337 | map_compat_vdso(compat); |
| 338 | |
| 339 | if (compat) |
| 340 | addr = VDSO_HIGH_BASE; |
| 341 | else { |
| 342 | addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0); |
| 343 | if (IS_ERR_VALUE(addr)) { |
| 344 | ret = addr; |
| 345 | goto up_fail; |
| 346 | } |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 347 | } |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 348 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 349 | if (compat_uses_vma || !compat) { |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 350 | /* |
| 351 | * MAYWRITE to allow gdb to COW and set breakpoints |
| 352 | * |
| 353 | * Make sure the vDSO gets into every core dump. |
| 354 | * Dumping its contents makes post-mortem fully |
| 355 | * interpretable later without matching up the same |
| 356 | * kernel and hardware config to see what PC values |
| 357 | * meant. |
| 358 | */ |
| 359 | ret = install_special_mapping(mm, addr, PAGE_SIZE, |
| 360 | VM_READ|VM_EXEC| |
| 361 | VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC| |
| 362 | VM_ALWAYSDUMP, |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 363 | vdso32_pages); |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 364 | |
| 365 | if (ret) |
| 366 | goto up_fail; |
| 367 | } |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 368 | |
| 369 | current->mm->context.vdso = (void *)addr; |
| 370 | current_thread_info()->sysenter_return = |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 371 | VDSO32_SYMBOL(addr, SYSENTER_RETURN); |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 372 | |
| 373 | up_fail: |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 374 | up_write(&mm->mmap_sem); |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 375 | |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 376 | return ret; |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 379 | #ifdef CONFIG_X86_64 |
| 380 | |
| 381 | __initcall(sysenter_setup); |
| 382 | |
Roland McGrath | a97f52e | 2008-01-30 13:31:55 +0100 | [diff] [blame] | 383 | #ifdef CONFIG_SYSCTL |
| 384 | /* Register vsyscall32 into the ABI table */ |
| 385 | #include <linux/sysctl.h> |
| 386 | |
| 387 | static ctl_table abi_table2[] = { |
| 388 | { |
| 389 | .procname = "vsyscall32", |
| 390 | .data = &sysctl_vsyscall32, |
| 391 | .maxlen = sizeof(int), |
| 392 | .mode = 0644, |
| 393 | .proc_handler = proc_dointvec |
| 394 | }, |
| 395 | {} |
| 396 | }; |
| 397 | |
| 398 | static ctl_table abi_root_table2[] = { |
| 399 | { |
| 400 | .ctl_name = CTL_ABI, |
| 401 | .procname = "abi", |
| 402 | .mode = 0555, |
| 403 | .child = abi_table2 |
| 404 | }, |
| 405 | {} |
| 406 | }; |
| 407 | |
| 408 | static __init int ia32_binfmt_init(void) |
| 409 | { |
| 410 | register_sysctl_table(abi_root_table2); |
| 411 | return 0; |
| 412 | } |
| 413 | __initcall(ia32_binfmt_init); |
| 414 | #endif |
| 415 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 416 | #else /* CONFIG_X86_32 */ |
| 417 | |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 418 | const char *arch_vma_name(struct vm_area_struct *vma) |
| 419 | { |
| 420 | if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso) |
| 421 | return "[vdso]"; |
| 422 | return NULL; |
| 423 | } |
| 424 | |
| 425 | struct vm_area_struct *get_gate_vma(struct task_struct *tsk) |
| 426 | { |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 427 | struct mm_struct *mm = tsk->mm; |
| 428 | |
| 429 | /* Check to see if this task was created in compat vdso mode */ |
| 430 | if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE) |
| 431 | return &gate_vma; |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 432 | return NULL; |
| 433 | } |
| 434 | |
| 435 | int in_gate_area(struct task_struct *task, unsigned long addr) |
| 436 | { |
Jan Beulich | 2f30c00 | 2007-07-21 17:10:21 +0200 | [diff] [blame] | 437 | const struct vm_area_struct *vma = get_gate_vma(task); |
| 438 | |
| 439 | return vma && addr >= vma->vm_start && addr < vma->vm_end; |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | int in_gate_area_no_task(unsigned long addr) |
| 443 | { |
| 444 | return 0; |
| 445 | } |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 446 | |
| 447 | #endif /* CONFIG_X86_64 */ |