vsyscall.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 void *syscall_page;
  38. int __init vsyscall_init(void)
  39. {
  40. syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
  41. /*
  42. * XXX: Map this page to a fixmap entry if we get around
  43. * to adding the page to ELF core dumps
  44. */
  45. memcpy(syscall_page,
  46. &vsyscall_trapa_start,
  47. &vsyscall_trapa_end - &vsyscall_trapa_start);
  48. return 0;
  49. }
  50. static struct page *syscall_vma_nopage(struct vm_area_struct *vma,
  51. unsigned long address, int *type)
  52. {
  53. unsigned long offset = address - vma->vm_start;
  54. struct page *page;
  55. if (address < vma->vm_start || address > vma->vm_end)
  56. return NOPAGE_SIGBUS;
  57. page = virt_to_page(syscall_page + offset);
  58. get_page(page);
  59. return page;
  60. }
  61. /* Prevent VMA merging */
  62. static void syscall_vma_close(struct vm_area_struct *vma)
  63. {
  64. }
  65. static struct vm_operations_struct syscall_vm_ops = {
  66. .nopage = syscall_vma_nopage,
  67. .close = syscall_vma_close,
  68. };
  69. /* Setup a VMA at program startup for the vsyscall page */
  70. int arch_setup_additional_pages(struct linux_binprm *bprm,
  71. int executable_stack)
  72. {
  73. struct vm_area_struct *vma;
  74. struct mm_struct *mm = current->mm;
  75. unsigned long addr;
  76. int ret;
  77. down_write(&mm->mmap_sem);
  78. addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
  79. if (IS_ERR_VALUE(addr)) {
  80. ret = addr;
  81. goto up_fail;
  82. }
  83. vma = kmem_cache_zalloc(vm_area_cachep, SLAB_KERNEL);
  84. if (!vma) {
  85. ret = -ENOMEM;
  86. goto up_fail;
  87. }
  88. vma->vm_start = addr;
  89. vma->vm_end = addr + PAGE_SIZE;
  90. /* MAYWRITE to allow gdb to COW and set breakpoints */
  91. vma->vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC|VM_MAYWRITE;
  92. vma->vm_flags |= mm->def_flags;
  93. vma->vm_page_prot = protection_map[vma->vm_flags & 7];
  94. vma->vm_ops = &syscall_vm_ops;
  95. vma->vm_mm = mm;
  96. ret = insert_vm_struct(mm, vma);
  97. if (unlikely(ret)) {
  98. kmem_cache_free(vm_area_cachep, vma);
  99. goto up_fail;
  100. }
  101. current->mm->context.vdso = (void *)addr;
  102. mm->total_vm++;
  103. up_fail:
  104. up_write(&mm->mmap_sem);
  105. return ret;
  106. }
  107. const char *arch_vma_name(struct vm_area_struct *vma)
  108. {
  109. if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
  110. return "[vdso]";
  111. return NULL;
  112. }
  113. struct vm_area_struct *get_gate_vma(struct task_struct *task)
  114. {
  115. return NULL;
  116. }
  117. int in_gate_area(struct task_struct *task, unsigned long address)
  118. {
  119. return 0;
  120. }
  121. int in_gate_area_no_task(unsigned long address)
  122. {
  123. return 0;
  124. }