sys_compat.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Based on arch/arm/kernel/sys_arm.c
  3. *
  4. * Copyright (C) People who wrote linux/arch/i386/kernel/sys_i386.c
  5. * Copyright (C) 1995, 1996 Russell King.
  6. * Copyright (C) 2012 ARM Ltd.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <linux/compat.h>
  21. #include <linux/cpufeature.h>
  22. #include <linux/personality.h>
  23. #include <linux/sched.h>
  24. #include <linux/sched/signal.h>
  25. #include <linux/slab.h>
  26. #include <linux/syscalls.h>
  27. #include <linux/uaccess.h>
  28. #include <asm/cacheflush.h>
  29. #include <asm/system_misc.h>
  30. #include <asm/tlbflush.h>
  31. #include <asm/unistd.h>
  32. static long
  33. __do_compat_cache_op(unsigned long start, unsigned long end)
  34. {
  35. long ret;
  36. do {
  37. unsigned long chunk = min(PAGE_SIZE, end - start);
  38. if (fatal_signal_pending(current))
  39. return 0;
  40. if (cpus_have_const_cap(ARM64_WORKAROUND_1542419)) {
  41. /*
  42. * The workaround requires an inner-shareable tlbi.
  43. * We pick the reserved-ASID to minimise the impact.
  44. */
  45. __tlbi(aside1is, __TLBI_VADDR(0, 0));
  46. dsb(ish);
  47. }
  48. ret = __flush_cache_user_range(start, start + chunk);
  49. if (ret)
  50. return ret;
  51. cond_resched();
  52. start += chunk;
  53. } while (start < end);
  54. return 0;
  55. }
  56. static inline long
  57. do_compat_cache_op(unsigned long start, unsigned long end, int flags)
  58. {
  59. if (end < start || flags)
  60. return -EINVAL;
  61. if (!access_ok(VERIFY_READ, (const void __user *)start, end - start))
  62. return -EFAULT;
  63. return __do_compat_cache_op(start, end);
  64. }
  65. /*
  66. * Handle all unrecognised system calls.
  67. */
  68. long compat_arm_syscall(struct pt_regs *regs, int scno)
  69. {
  70. siginfo_t info;
  71. switch (scno) {
  72. /*
  73. * Flush a region from virtual address 'r0' to virtual address 'r1'
  74. * _exclusive_. There is no alignment requirement on either address;
  75. * user space does not need to know the hardware cache layout.
  76. *
  77. * r2 contains flags. It should ALWAYS be passed as ZERO until it
  78. * is defined to be something else. For now we ignore it, but may
  79. * the fires of hell burn in your belly if you break this rule. ;)
  80. *
  81. * (at a later date, we may want to allow this call to not flush
  82. * various aspects of the cache. Passing '0' will guarantee that
  83. * everything necessary gets flushed to maintain consistency in
  84. * the specified region).
  85. */
  86. case __ARM_NR_compat_cacheflush:
  87. return do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
  88. case __ARM_NR_compat_set_tls:
  89. current->thread.uw.tp_value = regs->regs[0];
  90. /*
  91. * Protect against register corruption from context switch.
  92. * See comment in tls_thread_flush.
  93. */
  94. barrier();
  95. write_sysreg(regs->regs[0], tpidrro_el0);
  96. return 0;
  97. default:
  98. /*
  99. * Calls 0xf0xxx..0xf07ff are defined to return -ENOSYS
  100. * if not implemented, rather than raising SIGILL. This
  101. * way the calling program can gracefully determine whether
  102. * a feature is supported.
  103. */
  104. if (scno < __ARM_NR_COMPAT_END)
  105. return -ENOSYS;
  106. break;
  107. }
  108. clear_siginfo(&info);
  109. info.si_signo = SIGILL;
  110. info.si_errno = 0;
  111. info.si_code = ILL_ILLTRP;
  112. info.si_addr = (void __user *)instruction_pointer(regs) -
  113. (compat_thumb_mode(regs) ? 2 : 4);
  114. arm64_notify_die("Oops - bad compat syscall(2)", regs, &info, scno);
  115. return 0;
  116. }