Skip to content

Commit

Permalink
maccess: remove probe_read_common and probe_write_common
Browse files Browse the repository at this point in the history
Each of the helpers has just two callers, which also different in
dealing with kernel or userspace pointers.  Just open code the logic
in the callers.

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]>
  • Loading branch information
Christoph Hellwig authored and torvalds committed Jun 9, 2020
1 parent 02dddb1 commit cd03090
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions mm/maccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@
#include <linux/mm.h>
#include <linux/uaccess.h>

static __always_inline long
probe_read_common(void *dst, const void __user *src, size_t size)
{
long ret;

pagefault_disable();
ret = __copy_from_user_inatomic(dst, src, size);
pagefault_enable();

return ret ? -EFAULT : 0;
}

static __always_inline long
probe_write_common(void __user *dst, const void *src, size_t size)
{
long ret;

pagefault_disable();
ret = __copy_to_user_inatomic(dst, src, size);
pagefault_enable();

return ret ? -EFAULT : 0;
}

/**
* probe_kernel_read(): safely attempt to read from any location
* @dst: pointer to the buffer that shall take the data
Expand Down Expand Up @@ -70,10 +46,15 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
mm_segment_t old_fs = get_fs();

set_fs(KERNEL_DS);
ret = probe_read_common(dst, (__force const void __user *)src, size);
pagefault_disable();
ret = __copy_from_user_inatomic(dst, (__force const void __user *)src,
size);
pagefault_enable();
set_fs(old_fs);

return ret;
if (ret)
return -EFAULT;
return 0;
}
EXPORT_SYMBOL_GPL(probe_kernel_read);

Expand All @@ -92,11 +73,16 @@ long probe_user_read(void *dst, const void __user *src, size_t size)
mm_segment_t old_fs = get_fs();

set_fs(USER_DS);
if (access_ok(src, size))
ret = probe_read_common(dst, src, size);
if (access_ok(src, size)) {
pagefault_disable();
ret = __copy_from_user_inatomic(dst, src, size);
pagefault_enable();
}
set_fs(old_fs);

return ret;
if (ret)
return -EFAULT;
return 0;
}
EXPORT_SYMBOL_GPL(probe_user_read);

Expand All @@ -115,10 +101,14 @@ long probe_kernel_write(void *dst, const void *src, size_t size)
mm_segment_t old_fs = get_fs();

set_fs(KERNEL_DS);
ret = probe_write_common((__force void __user *)dst, src, size);
pagefault_disable();
ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
pagefault_enable();
set_fs(old_fs);

return ret;
if (ret)
return -EFAULT;
return 0;
}

/**
Expand All @@ -136,11 +126,16 @@ long probe_user_write(void __user *dst, const void *src, size_t size)
mm_segment_t old_fs = get_fs();

set_fs(USER_DS);
if (access_ok(dst, size))
ret = probe_write_common(dst, src, size);
if (access_ok(dst, size)) {
pagefault_disable();
ret = __copy_to_user_inatomic(dst, src, size);
pagefault_enable();
}
set_fs(old_fs);

return ret;
if (ret)
return -EFAULT;
return 0;
}
EXPORT_SYMBOL_GPL(probe_user_write);

Expand Down

0 comments on commit cd03090

Please sign in to comment.