2 * Access kernel memory without faulting.
4 #include <linux/uaccess.h>
5 #include <linux/module.h>
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
14 * Safely read from address @src to the buffer at @dst. If a kernel fault
15 * happens, handle that and return -EFAULT.
17 long probe_kernel_read(void *dst
, void *src
, size_t size
)
20 mm_segment_t old_fs
= get_fs();
24 ret
= __copy_from_user_inatomic(dst
,
25 (__force
const void __user
*)src
, size
);
29 return ret
? -EFAULT
: 0;
31 EXPORT_SYMBOL_GPL(probe_kernel_read
);
34 * probe_kernel_write(): safely attempt to write to a location
35 * @dst: address to write to
36 * @src: pointer to the data that shall be written
37 * @size: size of the data chunk
39 * Safely write to address @dst from the buffer at @src. If a kernel fault
40 * happens, handle that and return -EFAULT.
42 long probe_kernel_write(void *dst
, void *src
, size_t size
)
45 mm_segment_t old_fs
= get_fs();
49 ret
= __copy_to_user_inatomic((__force
void __user
*)dst
, src
, size
);
53 return ret
? -EFAULT
: 0;
55 EXPORT_SYMBOL_GPL(probe_kernel_write
);
This page took 0.031342 seconds and 5 git commands to generate.