Skip to content

Commit

Permalink
maccess: remove strncpy_from_unsafe
Browse files Browse the repository at this point in the history
All users are gone now.

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 9de1fec commit 7676fbf
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
1 change: 0 additions & 1 deletion include/linux/uaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ extern long probe_user_read(void *dst, const void __user *src, size_t size);
extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
extern long notrace probe_user_write(void __user *dst, const void *src, size_t size);

extern long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count);
long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr,
long count);

Expand Down
39 changes: 1 addition & 38 deletions mm/maccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

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)
Expand Down Expand Up @@ -157,35 +155,6 @@ long probe_user_write(void __user *dst, const void *src, size_t size)
}
EXPORT_SYMBOL_GPL(probe_user_write);

/**
* strncpy_from_unsafe: - Copy a NUL terminated string from unsafe address.
* @dst: Destination address, in kernel space. This buffer must be at
* least @count bytes long.
* @unsafe_addr: Unsafe address.
* @count: Maximum number of bytes to copy, including the trailing NUL.
*
* Copies a NUL-terminated string from unsafe address to kernel buffer.
*
* On success, returns the length of the string INCLUDING the trailing NUL.
*
* If access fails, returns -EFAULT (some data may have been copied
* and the trailing NUL added).
*
* If @count is smaller than the length of the string, copies @count-1 bytes,
* sets the last byte of @dst buffer to NUL and returns @count.
*
* Same as strncpy_from_kernel_nofault() 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 strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count)
{
return __strncpy_from_unsafe(dst, unsafe_addr, count, false);
}

/**
* strncpy_from_kernel_nofault: - Copy a NUL terminated string from unsafe
* address.
Expand All @@ -205,20 +174,14 @@ long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count)
* sets the last byte of @dst buffer to NUL and returns @count.
*/
long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
{
return __strncpy_from_unsafe(dst, unsafe_addr, count, true);
}

static long __strncpy_from_unsafe(char *dst, const void *unsafe_addr,
long count, bool strict)
{
mm_segment_t old_fs = get_fs();
const void *src = unsafe_addr;
long ret;

if (unlikely(count <= 0))
return 0;
if (!probe_kernel_read_allowed(unsafe_addr, count, strict))
if (!probe_kernel_read_allowed(unsafe_addr, count, true))
return -EFAULT;

set_fs(KERNEL_DS);
Expand Down

0 comments on commit 7676fbf

Please sign in to comment.