xref: /linux/arch/x86/mm/maccess.c (revision 0a94608f0f7de9b1135ffea3546afe68eafef57f)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include <linux/uaccess.h>
4 #include <linux/kernel.h>
5 
6 #ifdef CONFIG_X86_64
7 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
8 {
9 	unsigned long vaddr = (unsigned long)unsafe_src;
10 
11 	/*
12 	 * Range covering the highest possible canonical userspace address
13 	 * as well as non-canonical address range. For the canonical range
14 	 * we also need to include the userspace guard page.
15 	 */
16 	return vaddr >= TASK_SIZE_MAX + PAGE_SIZE &&
17 	       __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
18 }
19 #else
20 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
21 {
22 	return (unsigned long)unsafe_src >= TASK_SIZE_MAX;
23 }
24 #endif
25