// SPDX-License-Identifier: GPL-2.0-only12#include <linux/uaccess.h>3#include <linux/kernel.h>45#include <asm/vsyscall.h>67#ifdef CONFIG_X86_648bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)9{10unsigned long vaddr = (unsigned long)unsafe_src;1112/*13* Do not allow userspace addresses. This disallows14* normal userspace and the userspace guard page:15*/16if (vaddr < TASK_SIZE_MAX + PAGE_SIZE)17return false;1819/*20* Reading from the vsyscall page may cause an unhandled fault in21* certain cases. Though it is at an address above TASK_SIZE_MAX, it is22* usually considered as a user space address.23*/24if (is_vsyscall_vaddr(vaddr))25return false;2627/*28* Allow everything during early boot before 'x86_virt_bits'29* is initialized. Needed for instruction decoding in early30* exception handlers.31*/32if (!boot_cpu_data.x86_virt_bits)33return true;3435return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);36}37#else38bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)39{40return (unsigned long)unsafe_src >= TASK_SIZE_MAX;41}42#endif434445