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