BACKPORT: maccess: always use strict semantics for probe_kernel_read

Except for historical confusion in the kprobes/uprobes and bpf tracers,
which has been fixed now, there is no good reason to ever allow user
memory accesses from probe_kernel_read.  Switch probe_kernel_read to only
read from kernel memory.

[[email protected]: update it for "mm, dump_page(): do not crash with invalid mapping pointer"]

Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
Change-Id: Id68f398b368bc4bd0f787a5a1684abf5f47504a9
This commit is contained in:
Christoph Hellwig 2020-06-08 21:34:50 -07:00 • committed by basamaryan
commit 275f76f06e
No known key found for this signature in database
GPG key ID: 210D5384FB2A5885
6 changed files with 12 additions and 46 deletions

View file

@ -6,38 +6,16 @@
#include <linux/mm.h>
#include <linux/uaccess.h>
static long __probe_kernel_read(void *dst, const void *src, size_t size,
bool strict);
static long __strncpy_from_unsafe(char *dst, const void *unsafe_addr,
long count, bool strict);
bool __weak probe_kernel_read_allowed(const void *unsafe_src, size_t size,
bool strict)
bool __weak probe_kernel_read_allowed(const void *unsafe_src, size_t size)
{
return true;
}
/**
* probe_kernel_read(): safely attempt to read from any location
* @dst: pointer to the buffer that shall take the data
* @src: address to read from
* @size: size of the data chunk
*
* Same as probe_kernel_read_strict() except that for architectures with
* not fully separated user and kernel address spaces this function also works
* for user address tanges.
*
* DO NOT USE THIS FUNCTION - it is broken on architectures with entirely
* separate kernel and user address spaces, and also a bad idea otherwise.
*/
long probe_kernel_read(void *dst, const void *src, size_t size)
{
return __probe_kernel_read(dst, src, size, false);
}
EXPORT_SYMBOL_GPL(probe_kernel_read);
/**
* probe_kernel_read_strict(): safely attempt to read from kernel-space
* probe_kernel_read(): safely attempt to read from kernel-space
* @dst: pointer to the buffer that shall take the data
* @src: address to read from
* @size: size of the data chunk
@ -50,18 +28,12 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
* probe_kernel_read() suitable for use within regions where the caller
* already holds mmap_sem, or other locks which nest inside mmap_sem.
*/
long probe_kernel_read_strict(void *dst, const void *src, size_t size)
{
return __probe_kernel_read(dst, src, size, true);
}
static long __probe_kernel_read(void *dst, const void *src, size_t size,
bool strict)
long probe_kernel_read(void *dst, const void *src, size_t size)
{
long ret;
mm_segment_t old_fs = get_fs();
if (!probe_kernel_read_allowed(src, size, strict))
if (!probe_kernel_read_allowed(src, size))
return -EFAULT;
set_fs(KERNEL_DS);
@ -75,6 +47,7 @@ static long __probe_kernel_read(void *dst, const void *src, size_t size,
return -EFAULT;
return 0;
}
EXPORT_SYMBOL_GPL(probe_kernel_read);
/**
* probe_user_read(): safely attempt to read from a user-space location
@ -219,7 +192,7 @@ static long __strncpy_from_unsafe(char *dst, const void *unsafe_addr,
if (unlikely(count <= 0))
return 0;
if (!probe_kernel_read_allowed(unsafe_addr, count, strict))
if (!probe_kernel_read_allowed(unsafe_addr, count))
return -EFAULT;
set_fs(KERNEL_DS);