@@ -24,7 +24,7 @@ bool __weak probe_kernel_read_allowed(const void *unsafe_src, size_t size)
24
24
long probe_kernel_read (void * dst , const void * src , size_t size )
25
25
{
26
26
if (!probe_kernel_read_allowed (src , size ))
27
- return - EFAULT ;
27
+ return - ERANGE ;
28
28
29
29
pagefault_disable ();
30
30
probe_kernel_read_loop (dst , src , size , u64 , Efault );
@@ -68,7 +68,7 @@ long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
68
68
if (unlikely (count <= 0 ))
69
69
return 0 ;
70
70
if (!probe_kernel_read_allowed (unsafe_addr , count ))
71
- return - EFAULT ;
71
+ return - ERANGE ;
72
72
73
73
pagefault_disable ();
74
74
do {
@@ -93,7 +93,8 @@ long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
93
93
* @size: size of the data chunk
94
94
*
95
95
* Safely read from kernel address @src to the buffer at @dst. If a kernel
96
- * fault happens, handle that and return -EFAULT.
96
+ * fault happens, handle that and return -EFAULT. If @src is not a valid kernel
97
+ * address, return -ERANGE.
97
98
*
98
99
* We ensure that the copy_from_user is executed in atomic context so that
99
100
* do_page_fault() doesn't attempt to take mmap_lock. This makes
@@ -106,7 +107,7 @@ long probe_kernel_read(void *dst, const void *src, size_t size)
106
107
mm_segment_t old_fs = get_fs ();
107
108
108
109
if (!probe_kernel_read_allowed (src , size ))
109
- return - EFAULT ;
110
+ return - ERANGE ;
110
111
111
112
set_fs (KERNEL_DS );
112
113
pagefault_disable ();
@@ -158,8 +159,9 @@ long probe_kernel_write(void *dst, const void *src, size_t size)
158
159
*
159
160
* On success, returns the length of the string INCLUDING the trailing NUL.
160
161
*
161
- * If access fails, returns -EFAULT (some data may have been copied
162
- * and the trailing NUL added).
162
+ * If access fails, returns -EFAULT (some data may have been copied and the
163
+ * trailing NUL added). If @unsafe_addr is not a valid kernel address, return
164
+ * -ERANGE.
163
165
*
164
166
* If @count is smaller than the length of the string, copies @count-1 bytes,
165
167
* sets the last byte of @dst buffer to NUL and returns @count.
@@ -173,7 +175,7 @@ long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
173
175
if (unlikely (count <= 0 ))
174
176
return 0 ;
175
177
if (!probe_kernel_read_allowed (unsafe_addr , count ))
176
- return - EFAULT ;
178
+ return - ERANGE ;
177
179
178
180
set_fs (KERNEL_DS );
179
181
pagefault_disable ();
0 commit comments