1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/uaccess.h>
4 #include <linux/kernel.h>
7 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
9 unsigned long vaddr = (unsigned long)unsafe_src;
12 * Do not allow userspace addresses. This disallows
13 * normal userspace and the userspace guard page:
15 if (vaddr < TASK_SIZE_MAX + PAGE_SIZE)
19 * Allow everything during early boot before 'x86_virt_bits'
20 * is initialized. Needed for instruction decoding in early
23 if (!boot_cpu_data.x86_virt_bits)
26 return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
29 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
31 return (unsigned long)unsafe_src >= TASK_SIZE_MAX;