diff options
-rw-r--r-- | include/linux/uaccess.h | 22 | ||||
-rw-r--r-- | mm/Makefile | 2 | ||||
-rw-r--r-- | mm/maccess.c | 49 |
3 files changed, 72 insertions, 1 deletions
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 975c963e5789..fec6decfb983 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h | |||
@@ -84,4 +84,26 @@ static inline unsigned long __copy_from_user_nocache(void *to, | |||
84 | ret; \ | 84 | ret; \ |
85 | }) | 85 | }) |
86 | 86 | ||
87 | /* | ||
88 | * probe_kernel_read(): safely attempt to read from a location | ||
89 | * @dst: pointer to the buffer that shall take the data | ||
90 | * @src: address to read from | ||
91 | * @size: size of the data chunk | ||
92 | * | ||
93 | * Safely read from address @src to the buffer at @dst. If a kernel fault | ||
94 | * happens, handle that and return -EFAULT. | ||
95 | */ | ||
96 | extern long probe_kernel_read(void *dst, void *src, size_t size); | ||
97 | |||
98 | /* | ||
99 | * probe_kernel_write(): safely attempt to write to a location | ||
100 | * @dst: address to write to | ||
101 | * @src: pointer to the data that shall be written | ||
102 | * @size: size of the data chunk | ||
103 | * | ||
104 | * Safely write to address @dst from the buffer at @src. If a kernel fault | ||
105 | * happens, handle that and return -EFAULT. | ||
106 | */ | ||
107 | extern long probe_kernel_write(void *dst, void *src, size_t size); | ||
108 | |||
87 | #endif /* __LINUX_UACCESS_H__ */ | 109 | #endif /* __LINUX_UACCESS_H__ */ |
diff --git a/mm/Makefile b/mm/Makefile index a5b0dd93427a..18c143b3c46c 100644 --- a/mm/Makefile +++ b/mm/Makefile | |||
@@ -8,7 +8,7 @@ mmu-$(CONFIG_MMU) := fremap.o highmem.o madvise.o memory.o mincore.o \ | |||
8 | vmalloc.o | 8 | vmalloc.o |
9 | 9 | ||
10 | obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \ | 10 | obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \ |
11 | page_alloc.o page-writeback.o pdflush.o \ | 11 | maccess.o page_alloc.o page-writeback.o pdflush.o \ |
12 | readahead.o swap.o truncate.o vmscan.o \ | 12 | readahead.o swap.o truncate.o vmscan.o \ |
13 | prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \ | 13 | prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \ |
14 | page_isolation.o $(mmu-y) | 14 | page_isolation.o $(mmu-y) |
diff --git a/mm/maccess.c b/mm/maccess.c new file mode 100644 index 000000000000..24f81b971403 --- /dev/null +++ b/mm/maccess.c | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * Access kernel memory without faulting. | ||
3 | */ | ||
4 | #include <linux/uaccess.h> | ||
5 | #include <linux/module.h> | ||
6 | #include <linux/mm.h> | ||
7 | |||
8 | /** | ||
9 | * probe_kernel_read(): safely attempt to read from a location | ||
10 | * @dst: pointer to the buffer that shall take the data | ||
11 | * @src: address to read from | ||
12 | * @size: size of the data chunk | ||
13 | * | ||
14 | * Safely read from address @src to the buffer at @dst. If a kernel fault | ||
15 | * happens, handle that and return -EFAULT. | ||
16 | */ | ||
17 | long probe_kernel_read(void *dst, void *src, size_t size) | ||
18 | { | ||
19 | long ret; | ||
20 | |||
21 | pagefault_disable(); | ||
22 | ret = __copy_from_user_inatomic(dst, | ||
23 | (__force const void __user *)src, size); | ||
24 | pagefault_enable(); | ||
25 | |||
26 | return ret ? -EFAULT : 0; | ||
27 | } | ||
28 | EXPORT_SYMBOL_GPL(probe_kernel_read); | ||
29 | |||
30 | /** | ||
31 | * probe_kernel_write(): safely attempt to write to a location | ||
32 | * @dst: address to write to | ||
33 | * @src: pointer to the data that shall be written | ||
34 | * @size: size of the data chunk | ||
35 | * | ||
36 | * Safely write to address @dst from the buffer at @src. If a kernel fault | ||
37 | * happens, handle that and return -EFAULT. | ||
38 | */ | ||
39 | long probe_kernel_write(void *dst, void *src, size_t size) | ||
40 | { | ||
41 | long ret; | ||
42 | |||
43 | pagefault_disable(); | ||
44 | ret = __copy_to_user_inatomic((__force void __user *)dst, src, size); | ||
45 | pagefault_enable(); | ||
46 | |||
47 | return ret ? -EFAULT : 0; | ||
48 | } | ||
49 | EXPORT_SYMBOL_GPL(probe_kernel_write); | ||