-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Daniel Borkmann says: ==================== This set adds probe_read_{user,kernel}(), probe_read_str_{user,kernel}() helpers, fixes probe_write_user() helper and selftests. For details please see individual patches. Thanks! v2 -> v3: - noticed two more things that are fixed in here: - bpf uapi helper description used 'int size' for *_str helpers, now u32 - we need TASK_SIZE_MAX + guard page on x86-64 in patch 2 otherwise we'll trigger the 00c4237 warn as well, so full range covered now v1 -> v2: - standardize unsafe_ptr terminology in uapi header comment (Andrii) - probe_read_{user,kernel}[_str] naming scheme (Andrii) - use global data in last test case, remove relaxed_maps (Andrii) - add strict non-pagefault kernel read funcs to avoid warning in kernel probe read helpers (Alexei) ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Showing
17 changed files
with
597 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
|
||
#include <linux/uaccess.h> | ||
#include <linux/kernel.h> | ||
|
||
#ifdef CONFIG_X86_64 | ||
static __always_inline u64 canonical_address(u64 vaddr, u8 vaddr_bits) | ||
{ | ||
return ((s64)vaddr << (64 - vaddr_bits)) >> (64 - vaddr_bits); | ||
} | ||
|
||
static __always_inline bool invalid_probe_range(u64 vaddr) | ||
{ | ||
/* | ||
* Range covering the highest possible canonical userspace address | ||
* as well as non-canonical address range. For the canonical range | ||
* we also need to include the userspace guard page. | ||
*/ | ||
return vaddr < TASK_SIZE_MAX + PAGE_SIZE || | ||
canonical_address(vaddr, boot_cpu_data.x86_virt_bits) != vaddr; | ||
} | ||
#else | ||
static __always_inline bool invalid_probe_range(u64 vaddr) | ||
{ | ||
return vaddr < TASK_SIZE_MAX; | ||
} | ||
#endif | ||
|
||
long probe_kernel_read_strict(void *dst, const void *src, size_t size) | ||
{ | ||
if (unlikely(invalid_probe_range((unsigned long)src))) | ||
return -EFAULT; | ||
|
||
return __probe_kernel_read(dst, src, size); | ||
} | ||
|
||
long strncpy_from_unsafe_strict(char *dst, const void *unsafe_addr, long count) | ||
{ | ||
if (unlikely(invalid_probe_range((unsigned long)unsafe_addr))) | ||
return -EFAULT; | ||
|
||
return __strncpy_from_unsafe(dst, unsafe_addr, count); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.