syscall32.c 2.6 KB

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