blob: 3744b2a8e591c666e932b25aa80fd43f0d9956b3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Al Virod5975802017-03-20 21:56:06 -04002#include <linux/uaccess.h>
3
4/* out-of-line parts */
5
6#ifndef INLINE_COPY_FROM_USER
7unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n)
8{
9 unsigned long res = n;
Al Viro9c5f6902017-06-29 21:39:54 -040010 might_fault();
11 if (likely(access_ok(VERIFY_READ, from, n))) {
12 kasan_check_write(to, n);
Al Virod5975802017-03-20 21:56:06 -040013 res = raw_copy_from_user(to, from, n);
Al Viro9c5f6902017-06-29 21:39:54 -040014 }
Al Virod5975802017-03-20 21:56:06 -040015 if (unlikely(res))
16 memset(to + (n - res), 0, res);
17 return res;
18}
19EXPORT_SYMBOL(_copy_from_user);
20#endif
21
22#ifndef INLINE_COPY_TO_USER
Christophe Leroya0e94592017-12-09 17:24:24 +010023unsigned long _copy_to_user(void __user *to, const void *from, unsigned long n)
Al Virod5975802017-03-20 21:56:06 -040024{
Al Viro9c5f6902017-06-29 21:39:54 -040025 might_fault();
26 if (likely(access_ok(VERIFY_WRITE, to, n))) {
27 kasan_check_read(from, n);
Al Virod5975802017-03-20 21:56:06 -040028 n = raw_copy_to_user(to, from, n);
Al Viro9c5f6902017-06-29 21:39:54 -040029 }
Al Virod5975802017-03-20 21:56:06 -040030 return n;
31}
32EXPORT_SYMBOL(_copy_to_user);
33#endif