Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Al Viro | d597580 | 2017-03-20 21:56:06 -0400 | [diff] [blame] | 2 | #include <linux/uaccess.h> |
| 3 | |
| 4 | /* out-of-line parts */ |
| 5 | |
| 6 | #ifndef INLINE_COPY_FROM_USER |
| 7 | unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n) |
| 8 | { |
| 9 | unsigned long res = n; |
Al Viro | 9c5f690 | 2017-06-29 21:39:54 -0400 | [diff] [blame] | 10 | might_fault(); |
| 11 | if (likely(access_ok(VERIFY_READ, from, n))) { |
| 12 | kasan_check_write(to, n); |
Al Viro | d597580 | 2017-03-20 21:56:06 -0400 | [diff] [blame] | 13 | res = raw_copy_from_user(to, from, n); |
Al Viro | 9c5f690 | 2017-06-29 21:39:54 -0400 | [diff] [blame] | 14 | } |
Al Viro | d597580 | 2017-03-20 21:56:06 -0400 | [diff] [blame] | 15 | if (unlikely(res)) |
| 16 | memset(to + (n - res), 0, res); |
| 17 | return res; |
| 18 | } |
| 19 | EXPORT_SYMBOL(_copy_from_user); |
| 20 | #endif |
| 21 | |
| 22 | #ifndef INLINE_COPY_TO_USER |
| 23 | unsigned long _copy_to_user(void *to, const void __user *from, unsigned long n) |
| 24 | { |
Al Viro | 9c5f690 | 2017-06-29 21:39:54 -0400 | [diff] [blame] | 25 | might_fault(); |
| 26 | if (likely(access_ok(VERIFY_WRITE, to, n))) { |
| 27 | kasan_check_read(from, n); |
Al Viro | d597580 | 2017-03-20 21:56:06 -0400 | [diff] [blame] | 28 | n = raw_copy_to_user(to, from, n); |
Al Viro | 9c5f690 | 2017-06-29 21:39:54 -0400 | [diff] [blame] | 29 | } |
Al Viro | d597580 | 2017-03-20 21:56:06 -0400 | [diff] [blame] | 30 | return n; |
| 31 | } |
| 32 | EXPORT_SYMBOL(_copy_to_user); |
| 33 | #endif |