Linux 5.7.6
[linux/fpc-iii.git] / arch / x86 / mm / maccess.c
blobf5b85bdc0535cf7350a274d9bea447ce838ef473
1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/uaccess.h>
4 #include <linux/kernel.h>
6 #ifdef CONFIG_X86_64
7 static __always_inline u64 canonical_address(u64 vaddr, u8 vaddr_bits)
9 return ((s64)vaddr << (64 - vaddr_bits)) >> (64 - vaddr_bits);
12 static __always_inline bool invalid_probe_range(u64 vaddr)
15 * Range covering the highest possible canonical userspace address
16 * as well as non-canonical address range. For the canonical range
17 * we also need to include the userspace guard page.
19 return vaddr < TASK_SIZE_MAX + PAGE_SIZE ||
20 canonical_address(vaddr, boot_cpu_data.x86_virt_bits) != vaddr;
22 #else
23 static __always_inline bool invalid_probe_range(u64 vaddr)
25 return vaddr < TASK_SIZE_MAX;
27 #endif
29 long probe_kernel_read_strict(void *dst, const void *src, size_t size)
31 if (unlikely(invalid_probe_range((unsigned long)src)))
32 return -EFAULT;
34 return __probe_kernel_read(dst, src, size);
37 long strncpy_from_unsafe_strict(char *dst, const void *unsafe_addr, long count)
39 if (unlikely(invalid_probe_range((unsigned long)unsafe_addr)))
40 return -EFAULT;
42 return __strncpy_from_unsafe(dst, unsafe_addr, count);