sysenter.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * linux/arch/i386/kernel/sysenter.c
  3. *
  4. * (C) Copyright 2002 Linus Torvalds
  5. * Portions based on the vdso-randomization code from exec-shield:
  6. * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar
  7. *
  8. * This file contains the needed initializations to support sysenter.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/smp.h>
  12. #include <linux/thread_info.h>
  13. #include <linux/sched.h>
  14. #include <linux/gfp.h>
  15. #include <linux/string.h>
  16. #include <linux/elf.h>
  17. #include <linux/mm.h>
  18. #include <linux/module.h>
  19. #include <asm/cpufeature.h>
  20. #include <asm/msr.h>
  21. #include <asm/pgtable.h>
  22. #include <asm/unistd.h>
  23. /*
  24. * Should the kernel map a VDSO page into processes and pass its
  25. * address down to glibc upon exec()?
  26. */
  27. #ifdef CONFIG_PARAVIRT
  28. unsigned int __read_mostly vdso_enabled = 0;
  29. #else
  30. unsigned int __read_mostly vdso_enabled = 1;
  31. #endif
  32. EXPORT_SYMBOL_GPL(vdso_enabled);
  33. static int __init vdso_setup(char *s)
  34. {
  35. vdso_enabled = simple_strtoul(s, NULL, 0);
  36. return 1;
  37. }
  38. __setup("vdso=", vdso_setup);
  39. extern asmlinkage void sysenter_entry(void);
  40. void enable_sep_cpu(void)
  41. {
  42. int cpu = get_cpu();
  43. struct tss_struct *tss = &per_cpu(init_tss, cpu);
  44. if (!boot_cpu_has(X86_FEATURE_SEP)) {
  45. put_cpu();
  46. return;
  47. }
  48. tss->ss1 = __KERNEL_CS;
  49. tss->esp1 = sizeof(struct tss_struct) + (unsigned long) tss;
  50. wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
  51. wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp1, 0);
  52. wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
  53. put_cpu();
  54. }
  55. /*
  56. * These symbols are defined by vsyscall.o to mark the bounds
  57. * of the ELF DSO images included therein.
  58. */
  59. extern const char vsyscall_int80_start, vsyscall_int80_end;
  60. extern const char vsyscall_sysenter_start, vsyscall_sysenter_end;
  61. static struct page *syscall_pages[1];
  62. int __init sysenter_setup(void)
  63. {
  64. void *syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
  65. syscall_pages[0] = virt_to_page(syscall_page);
  66. #ifdef CONFIG_COMPAT_VDSO
  67. __set_fixmap(FIX_VDSO, __pa(syscall_page), PAGE_READONLY);
  68. printk("Compat vDSO mapped to %08lx.\n", __fix_to_virt(FIX_VDSO));
  69. #endif
  70. if (!boot_cpu_has(X86_FEATURE_SEP)) {
  71. memcpy(syscall_page,
  72. &vsyscall_int80_start,
  73. &vsyscall_int80_end - &vsyscall_int80_start);
  74. return 0;
  75. }
  76. memcpy(syscall_page,
  77. &vsyscall_sysenter_start,
  78. &vsyscall_sysenter_end - &vsyscall_sysenter_start);
  79. return 0;
  80. }
  81. #ifndef CONFIG_COMPAT_VDSO
  82. /* Defined in vsyscall-sysenter.S */
  83. extern void SYSENTER_RETURN;
  84. /* Setup a VMA at program startup for the vsyscall page */
  85. int arch_setup_additional_pages(struct linux_binprm *bprm, int exstack)
  86. {
  87. struct mm_struct *mm = current->mm;
  88. unsigned long addr;
  89. int ret;
  90. down_write(&mm->mmap_sem);
  91. addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
  92. if (IS_ERR_VALUE(addr)) {
  93. ret = addr;
  94. goto up_fail;
  95. }
  96. /*
  97. * MAYWRITE to allow gdb to COW and set breakpoints
  98. *
  99. * Make sure the vDSO gets into every core dump.
  100. * Dumping its contents makes post-mortem fully interpretable later
  101. * without matching up the same kernel and hardware config to see
  102. * what PC values meant.
  103. */
  104. ret = install_special_mapping(mm, addr, PAGE_SIZE,
  105. VM_READ|VM_EXEC|
  106. VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
  107. VM_ALWAYSDUMP,
  108. syscall_pages);
  109. if (ret)
  110. goto up_fail;
  111. current->mm->context.vdso = (void *)addr;
  112. current_thread_info()->sysenter_return =
  113. (void *)VDSO_SYM(&SYSENTER_RETURN);
  114. up_fail:
  115. up_write(&mm->mmap_sem);
  116. return ret;
  117. }
  118. const char *arch_vma_name(struct vm_area_struct *vma)
  119. {
  120. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  121. return "[vdso]";
  122. return NULL;
  123. }
  124. struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
  125. {
  126. return NULL;
  127. }
  128. int in_gate_area(struct task_struct *task, unsigned long addr)
  129. {
  130. return 0;
  131. }
  132. int in_gate_area_no_task(unsigned long addr)
  133. {
  134. return 0;
  135. }
  136. #endif