Linux Audio

Check our new training course

Loading...
v6.2
 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
 7bool 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
20bool 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
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0-only
 2
 3#include <linux/uaccess.h>
 4#include <linux/kernel.h>
 5
 6#include <asm/vsyscall.h>
 7
 8#ifdef CONFIG_X86_64
 9bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
10{
11	unsigned long vaddr = (unsigned long)unsafe_src;
12
13	/*
14	 * Do not allow userspace addresses.  This disallows
15	 * normal userspace and the userspace guard page:
16	 */
17	if (vaddr < TASK_SIZE_MAX + PAGE_SIZE)
18		return false;
19
20	/*
21	 * Reading from the vsyscall page may cause an unhandled fault in
22	 * certain cases.  Though it is at an address above TASK_SIZE_MAX, it is
23	 * usually considered as a user space address.
24	 */
25	if (is_vsyscall_vaddr(vaddr))
26		return false;
27
28	/*
29	 * Allow everything during early boot before 'x86_virt_bits'
30	 * is initialized.  Needed for instruction decoding in early
31	 * exception handlers.
32	 */
33	if (!boot_cpu_data.x86_virt_bits)
34		return true;
35
36	return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits);
37}
38#else
39bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
40{
41	return (unsigned long)unsafe_src >= TASK_SIZE_MAX;
42}
43#endif