diff options
Diffstat (limited to 'include/linux/uaccess.h')
-rw-r--r-- | include/linux/uaccess.h | 40 |
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 | ||
132 | extern long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count); | 102 | extern 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__ */ |