maccess.c 838 B

123456789101112131415161718192021222324252627282930313233
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/uaccess.h>
  3. #include <linux/kernel.h>
  4. #ifdef CONFIG_X86_64
  5. bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
  6. {
  7. unsigned long vaddr = (unsigned long)unsafe_src;
  8. /*
  9. * Do not allow userspace addresses. This disallows
  10. * normal userspace and the userspace guard page:
  11. */
  12. if (vaddr < TASK_SIZE_MAX + PAGE_SIZE)
  13. return false;
  14. /*
  15. * Allow everything during early boot before 'x86_virt_bits'
  16. * is initialized. Needed for instruction decoding in early
  17. * exception handlers.
  18. */
  19. if (!boot_cpu_data.x86_virt_bits)
  20. return true;
  21. return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
  22. }
  23. #else
  24. bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
  25. {
  26. return (unsigned long)unsafe_src >= TASK_SIZE_MAX;
  27. }
  28. #endif