Merge tag 'perf-tools-fixes-for-v6.7-2-2023-12-08' of git://git.kernel.org/pub/scm...
[linux-2.6-block.git] / arch / x86 / mm / maccess.c
CommitLineData
75a1a607
DB
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
fe557319 7bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
75a1a607 8{
eab0c608
CH
9 unsigned long vaddr = (unsigned long)unsafe_src;
10
75a1a607 11 /*
f7993654
AD
12 * Do not allow userspace addresses. This disallows
13 * normal userspace and the userspace guard page:
75a1a607 14 */
f7993654
AD
15 if (vaddr < TASK_SIZE_MAX + PAGE_SIZE)
16 return false;
17
18 /*
19 * Allow everything during early boot before 'x86_virt_bits'
20 * is initialized. Needed for instruction decoding in early
21 * exception handlers.
22 */
23 if (!boot_cpu_data.x86_virt_bits)
24 return true;
25
26 return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
75a1a607
DB
27}
28#else
fe557319 29bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
75a1a607 30{
eab0c608 31 return (unsigned long)unsafe_src >= TASK_SIZE_MAX;
75a1a607
DB
32}
33#endif