summaryrefslogtreecommitdiffstats
path: root/include/linux/uaccess.h
diff options
context:
space:
mode:
authorAndrew Morton <akpm@linux-foundation.org>2015-11-05 21:46:03 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-11-05 22:34:48 -0500
commit0ab32b6f1b88444524e52429fab334ff96683a3f (patch)
tree421de8da078f1ca72131097fdee0b9d4d1ef7c59 /include/linux/uaccess.h
parent86d2adccfbe7d5a1f050fa08db9638c9168736d9 (diff)
uaccess: reimplement probe_kernel_address() using probe_kernel_read()
probe_kernel_address() is basically the same as the (later added) probe_kernel_read(). The return value on EFAULT is a bit different: probe_kernel_address() returns number-of-bytes-not-copied whereas probe_kernel_read() returns -EFAULT. All callers have been checked, none cared. probe_kernel_read() can be overridden by the architecture whereas probe_kernel_address() cannot. parisc, blackfin and um do this, to insert additional checking. Hence this patch possibly fixes obscure bugs, although there are only two probe_kernel_address() callsites outside arch/. My first attempt involved removing probe_kernel_address() entirely and converting all callsites to use probe_kernel_read() directly, but that got tiresome. This patch shrinks mm/slab_common.o by 218 bytes. For a single probe_kernel_address() callsite. Cc: Steven Miao <realmz6@gmail.com> Cc: Jeff Dike <jdike@addtoit.com> Cc: Richard Weinberger <richard@nod.at> Cc: "James E.J. Bottomley" <jejb@parisc-linux.org> Cc: Helge Deller <deller@gmx.de> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/uaccess.h')
-rw-r--r--include/linux/uaccess.h40
1 files changed, 10 insertions, 30 deletions
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index d6f2c2c5b043..558129af828a 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -75,36 +75,6 @@ static inline unsigned long __copy_from_user_nocache(void *to,
75 75
76#endif /* ARCH_HAS_NOCACHE_UACCESS */ 76#endif /* ARCH_HAS_NOCACHE_UACCESS */
77 77
78/**
79 * probe_kernel_address(): safely attempt to read from a location
80 * @addr: address to read from - its type is type typeof(retval)*
81 * @retval: read into this variable
82 *
83 * Safely read from address @addr into variable @revtal. If a kernel fault
84 * happens, handle that and return -EFAULT.
85 * We ensure that the __get_user() is executed in atomic context so that
86 * do_page_fault() doesn't attempt to take mmap_sem. This makes
87 * probe_kernel_address() suitable for use within regions where the caller
88 * already holds mmap_sem, or other locks which nest inside mmap_sem.
89 * This must be a macro because __get_user() needs to know the types of the
90 * args.
91 *
92 * We don't include enough header files to be able to do the set_fs(). We
93 * require that the probe_kernel_address() caller will do that.
94 */
95#define probe_kernel_address(addr, retval) \
96 ({ \
97 long ret; \
98 mm_segment_t old_fs = get_fs(); \
99 \
100 set_fs(KERNEL_DS); \
101 pagefault_disable(); \
102 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
103 pagefault_enable(); \
104 set_fs(old_fs); \
105 ret; \
106 })
107
108/* 78/*
109 * probe_kernel_read(): safely attempt to read from a location 79 * probe_kernel_read(): safely attempt to read from a location
110 * @dst: pointer to the buffer that shall take the data 80 * @dst: pointer to the buffer that shall take the data
@@ -131,4 +101,14 @@ extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size
131 101
132extern long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count); 102extern long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count);
133 103
104/**
105 * probe_kernel_address(): safely attempt to read from a location
106 * @addr: address to read from
107 * @retval: read into this variable
108 *
109 * Returns 0 on success, or -EFAULT.
110 */
111#define probe_kernel_address(addr, retval) \
112 probe_kernel_read(&retval, addr, sizeof(retval))
113
134#endif /* __LINUX_UACCESS_H__ */ 114#endif /* __LINUX_UACCESS_H__ */