Blame view
mm/maccess.c
1.63 KB
c33fa9f56
|
1 2 3 |
/* * Access kernel memory without faulting. */ |
b95f1b31b
|
4 |
#include <linux/export.h> |
c33fa9f56
|
5 |
#include <linux/mm.h> |
7c7fcf762
|
6 |
#include <linux/uaccess.h> |
c33fa9f56
|
7 8 9 10 11 12 13 14 15 16 |
/** * probe_kernel_read(): safely attempt to read from a location * @dst: pointer to the buffer that shall take the data * @src: address to read from * @size: size of the data chunk * * Safely read from address @src to the buffer at @dst. If a kernel fault * happens, handle that and return -EFAULT. */ |
6144a85a0
|
17 |
|
f29c50419
|
18 |
long __weak probe_kernel_read(void *dst, const void *src, size_t size) |
6144a85a0
|
19 |
__attribute__((alias("__probe_kernel_read"))); |
f29c50419
|
20 |
long __probe_kernel_read(void *dst, const void *src, size_t size) |
c33fa9f56
|
21 22 |
{ long ret; |
b4b8ac524
|
23 |
mm_segment_t old_fs = get_fs(); |
c33fa9f56
|
24 |
|
b4b8ac524
|
25 |
set_fs(KERNEL_DS); |
c33fa9f56
|
26 27 28 29 |
pagefault_disable(); ret = __copy_from_user_inatomic(dst, (__force const void __user *)src, size); pagefault_enable(); |
b4b8ac524
|
30 |
set_fs(old_fs); |
c33fa9f56
|
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
return ret ? -EFAULT : 0; } EXPORT_SYMBOL_GPL(probe_kernel_read); /** * probe_kernel_write(): safely attempt to write to a 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. */ |
f29c50419
|
45 |
long __weak probe_kernel_write(void *dst, const void *src, size_t size) |
6144a85a0
|
46 |
__attribute__((alias("__probe_kernel_write"))); |
f29c50419
|
47 |
long __probe_kernel_write(void *dst, const void *src, size_t size) |
c33fa9f56
|
48 49 |
{ long ret; |
b4b8ac524
|
50 |
mm_segment_t old_fs = get_fs(); |
c33fa9f56
|
51 |
|
b4b8ac524
|
52 |
set_fs(KERNEL_DS); |
c33fa9f56
|
53 54 55 |
pagefault_disable(); ret = __copy_to_user_inatomic((__force void __user *)dst, src, size); pagefault_enable(); |
b4b8ac524
|
56 |
set_fs(old_fs); |
c33fa9f56
|
57 58 59 60 |
return ret ? -EFAULT : 0; } EXPORT_SYMBOL_GPL(probe_kernel_write); |