syscall32.c 2.4 KB

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