Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Copyright 2002,2003 Andi Kleen, SuSE Labs */ |
| 2 | |
| 3 | /* vsyscall handling for 32bit processes. Map a stub page into it |
| 4 | on demand because 32bit cannot reach the kernel's fixmaps */ |
| 5 | |
| 6 | #include <linux/mm.h> |
| 7 | #include <linux/string.h> |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/gfp.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/stringify.h> |
Andi Kleen | 1e01441 | 2005-04-16 15:24:55 -0700 | [diff] [blame] | 12 | #include <linux/security.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/proto.h> |
| 14 | #include <asm/tlbflush.h> |
| 15 | #include <asm/ia32_unistd.h> |
Jan Beulich | b035479 | 2007-05-02 19:27:04 +0200 | [diff] [blame] | 16 | #include <asm/vsyscall32.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | extern unsigned char syscall32_syscall[], syscall32_syscall_end[]; |
| 19 | extern unsigned char syscall32_sysenter[], syscall32_sysenter_end[]; |
| 20 | extern int sysctl_vsyscall32; |
| 21 | |
Roland McGrath | dc5882b | 2007-02-08 14:20:43 -0800 | [diff] [blame] | 22 | static struct page *syscall32_pages[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | static int use_sysenter = -1; |
| 24 | |
Andi Kleen | 1e01441 | 2005-04-16 15:24:55 -0700 | [diff] [blame] | 25 | struct linux_binprm; |
| 26 | |
| 27 | /* Setup a VMA at program startup for the vsyscall page */ |
| 28 | int syscall32_setup_pages(struct linux_binprm *bprm, int exstack) |
| 29 | { |
Andi Kleen | 1e01441 | 2005-04-16 15:24:55 -0700 | [diff] [blame] | 30 | struct mm_struct *mm = current->mm; |
Siddha, Suresh B | 9fb1759 | 2005-07-15 19:17:44 -0700 | [diff] [blame] | 31 | int ret; |
Andi Kleen | 1e01441 | 2005-04-16 15:24:55 -0700 | [diff] [blame] | 32 | |
Roland McGrath | dc5882b | 2007-02-08 14:20:43 -0800 | [diff] [blame] | 33 | down_write(&mm->mmap_sem); |
Roland McGrath | e03f0ca | 2007-01-26 00:56:50 -0800 | [diff] [blame] | 34 | /* |
Roland McGrath | dc5882b | 2007-02-08 14:20:43 -0800 | [diff] [blame] | 35 | * MAYWRITE to allow gdb to COW and set breakpoints |
| 36 | * |
Roland McGrath | e03f0ca | 2007-01-26 00:56:50 -0800 | [diff] [blame] | 37 | * Make sure the vDSO gets into every core dump. |
| 38 | * Dumping its contents makes post-mortem fully interpretable later |
| 39 | * without matching up the same kernel and hardware config to see |
| 40 | * what PC values meant. |
| 41 | */ |
Roland McGrath | dc5882b | 2007-02-08 14:20:43 -0800 | [diff] [blame] | 42 | /* Could randomize here */ |
| 43 | ret = install_special_mapping(mm, VSYSCALL32_BASE, PAGE_SIZE, |
| 44 | VM_READ|VM_EXEC| |
| 45 | VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC| |
| 46 | VM_ALWAYSDUMP, |
| 47 | syscall32_pages); |
Andi Kleen | 1e01441 | 2005-04-16 15:24:55 -0700 | [diff] [blame] | 48 | up_write(&mm->mmap_sem); |
Roland McGrath | dc5882b | 2007-02-08 14:20:43 -0800 | [diff] [blame] | 49 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Roland McGrath | c633090 | 2007-01-26 00:56:52 -0800 | [diff] [blame] | 52 | const char *arch_vma_name(struct vm_area_struct *vma) |
| 53 | { |
| 54 | if (vma->vm_start == VSYSCALL32_BASE && |
| 55 | vma->vm_mm && vma->vm_mm->task_size == IA32_PAGE_OFFSET) |
| 56 | return "[vdso]"; |
| 57 | return NULL; |
| 58 | } |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static int __init init_syscall32(void) |
| 61 | { |
Roland McGrath | dc5882b | 2007-02-08 14:20:43 -0800 | [diff] [blame] | 62 | char *syscall32_page = (void *)get_zeroed_page(GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | if (!syscall32_page) |
| 64 | panic("Cannot allocate syscall32 page"); |
Roland McGrath | dc5882b | 2007-02-08 14:20:43 -0800 | [diff] [blame] | 65 | syscall32_pages[0] = virt_to_page(syscall32_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | if (use_sysenter > 0) { |
| 67 | memcpy(syscall32_page, syscall32_sysenter, |
| 68 | syscall32_sysenter_end - syscall32_sysenter); |
| 69 | } else { |
| 70 | memcpy(syscall32_page, syscall32_syscall, |
| 71 | syscall32_syscall_end - syscall32_syscall); |
| 72 | } |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | __initcall(init_syscall32); |
| 77 | |
| 78 | /* May not be __init: called during resume */ |
| 79 | void syscall32_cpu_init(void) |
| 80 | { |
| 81 | if (use_sysenter < 0) |
| 82 | use_sysenter = (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL); |
| 83 | |
| 84 | /* Load these always in case some future AMD CPU supports |
| 85 | SYSENTER from compat mode too. */ |
| 86 | checking_wrmsrl(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS); |
| 87 | checking_wrmsrl(MSR_IA32_SYSENTER_ESP, 0ULL); |
| 88 | checking_wrmsrl(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target); |
| 89 | |
| 90 | wrmsrl(MSR_CSTAR, ia32_cstar_target); |
| 91 | } |