vsyscall.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * arch/sh/kernel/vsyscall.c
  3. *
  4. * Copyright (C) 2006 Paul Mundt
  5. *
  6. * vDSO randomization
  7. * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/mm.h>
  14. #include <linux/slab.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/gfp.h>
  18. #include <linux/module.h>
  19. #include <linux/elf.h>
  20. /*
  21. * Should the kernel map a VDSO page into processes and pass its
  22. * address down to glibc upon exec()?
  23. */
  24. unsigned int __read_mostly vdso_enabled = 1;
  25. EXPORT_SYMBOL_GPL(vdso_enabled);
  26. static int __init vdso_setup(char *s)
  27. {
  28. vdso_enabled = simple_strtoul(s, NULL, 0);
  29. return 1;
  30. }
  31. __setup("vdso=", vdso_setup);
  32. /*
  33. * These symbols are defined by vsyscall.o to mark the bounds
  34. * of the ELF DSO images included therein.
  35. */
  36. extern const char vsyscall_trapa_start, vsyscall_trapa_end;
  37. static struct page *syscall_pages[1];
  38. int __init vsyscall_init(void)
  39. {
  40. void *syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
  41. syscall_pages[0] = virt_to_page(syscall_page);
  42. /*
  43. * XXX: Map this page to a fixmap entry if we get around
  44. * to adding the page to ELF core dumps
  45. */
  46. memcpy(syscall_page,
  47. &vsyscall_trapa_start,
  48. &vsyscall_trapa_end - &vsyscall_trapa_start);
  49. return 0;
  50. }
  51. /* Setup a VMA at program startup for the vsyscall page */
  52. int arch_setup_additional_pages(struct linux_binprm *bprm,
  53. int executable_stack)
  54. {
  55. struct mm_struct *mm = current->mm;
  56. unsigned long addr;
  57. int ret;
  58. down_write(&mm->mmap_sem);
  59. addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
  60. if (IS_ERR_VALUE(addr)) {
  61. ret = addr;
  62. goto up_fail;
  63. }
  64. ret = install_special_mapping(mm, addr, PAGE_SIZE,
  65. VM_READ | VM_EXEC |
  66. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC |
  67. VM_ALWAYSDUMP,
  68. syscall_pages);
  69. if (unlikely(ret))
  70. goto up_fail;
  71. current->mm->context.vdso = (void *)addr;
  72. up_fail:
  73. up_write(&mm->mmap_sem);
  74. return ret;
  75. }
  76. const char *arch_vma_name(struct vm_area_struct *vma)
  77. {
  78. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  79. return "[vdso]";
  80. return NULL;
  81. }
  82. struct vm_area_struct *get_gate_vma(struct task_struct *task)
  83. {
  84. return NULL;
  85. }
  86. int in_gate_area(struct task_struct *task, unsigned long address)
  87. {
  88. return 0;
  89. }
  90. int in_gate_area_no_task(unsigned long address)
  91. {
  92. return 0;
  93. }