1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/uaccess.h>
4 #include <linux/kernel.h>
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
;
23 static __always_inline
bool invalid_probe_range(u64 vaddr
)
25 return vaddr
< TASK_SIZE_MAX
;
29 long probe_kernel_read_strict(void *dst
, const void *src
, size_t size
)
31 if (unlikely(invalid_probe_range((unsigned long)src
)))
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
)))
42 return __strncpy_from_unsafe(dst
, unsafe_addr
, count
);