Skip to content

Commit

Permalink
maccess: move user access routines together
Browse files Browse the repository at this point in the history
Move kernel access vs user access routines together to ease upcoming
ifdefs.

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 98a2360 commit fc3562d
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions mm/maccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,6 @@ long probe_kernel_read(void *dst, const void *src, size_t size)
}
EXPORT_SYMBOL_GPL(probe_kernel_read);

/**
* probe_user_read(): safely attempt to read from a user-space location
* @dst: pointer to the buffer that shall take the data
* @src: address to read from. This must be a user address.
* @size: size of the data chunk
*
* Safely read from user address @src to the buffer at @dst. If a kernel fault
* happens, handle that and return -EFAULT.
*/
long probe_user_read(void *dst, const void __user *src, size_t size)
{
long ret = -EFAULT;
mm_segment_t old_fs = get_fs();

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

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

/**
* probe_kernel_write(): safely attempt to write to a location
* @dst: address to write to
Expand All @@ -99,34 +71,6 @@ long probe_kernel_write(void *dst, const void *src, size_t size)
return 0;
}

/**
* probe_user_write(): safely attempt to write to a user-space location
* @dst: address to write to
* @src: pointer to the data that shall be written
* @size: size of the data chunk
*
* Safely write to address @dst from the buffer at @src. If a kernel fault
* happens, handle that and return -EFAULT.
*/
long probe_user_write(void __user *dst, const void *src, size_t size)
{
long ret = -EFAULT;
mm_segment_t old_fs = get_fs();

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

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

/**
* strncpy_from_kernel_nofault: - Copy a NUL terminated string from unsafe
* address.
Expand Down Expand Up @@ -170,6 +114,62 @@ long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
return ret ? -EFAULT : src - unsafe_addr;
}

/**
* probe_user_read(): safely attempt to read from a user-space location
* @dst: pointer to the buffer that shall take the data
* @src: address to read from. This must be a user address.
* @size: size of the data chunk
*
* Safely read from user address @src to the buffer at @dst. If a kernel fault
* happens, handle that and return -EFAULT.
*/
long probe_user_read(void *dst, const void __user *src, size_t size)
{
long ret = -EFAULT;
mm_segment_t old_fs = get_fs();

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

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

/**
* probe_user_write(): safely attempt to write to a user-space location
* @dst: address to write to
* @src: pointer to the data that shall be written
* @size: size of the data chunk
*
* Safely write to address @dst from the buffer at @src. If a kernel fault
* happens, handle that and return -EFAULT.
*/
long probe_user_write(void __user *dst, const void *src, size_t size)
{
long ret = -EFAULT;
mm_segment_t old_fs = get_fs();

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

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

/**
* strncpy_from_user_nofault: - Copy a NUL terminated string from unsafe user
* address.
Expand Down

0 comments on commit fc3562d

Please sign in to comment.