linux-surface/kernel/lib/usercopy.c

34 lines
764 B
C
Raw Normal View History

2017-11-06 02:38:20 +00:00
// SPDX-License-Identifier: GPL-2.0
2017-08-10 13:25:24 +00:00
#include <linux/uaccess.h>
/* out-of-line parts */
#ifndef INLINE_COPY_FROM_USER
unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n)
{
unsigned long res = n;
2017-09-05 02:31:27 +00:00
might_fault();
if (likely(access_ok(VERIFY_READ, from, n))) {
kasan_check_write(to, n);
2017-08-10 13:25:24 +00:00
res = raw_copy_from_user(to, from, n);
2017-09-05 02:31:27 +00:00
}
2017-08-10 13:25:24 +00:00
if (unlikely(res))
memset(to + (n - res), 0, res);
return res;
}
EXPORT_SYMBOL(_copy_from_user);
#endif
#ifndef INLINE_COPY_TO_USER
unsigned long _copy_to_user(void *to, const void __user *from, unsigned long n)
{
2017-09-05 02:31:27 +00:00
might_fault();
if (likely(access_ok(VERIFY_WRITE, to, n))) {
kasan_check_read(from, n);
2017-08-10 13:25:24 +00:00
n = raw_copy_to_user(to, from, n);
2017-09-05 02:31:27 +00:00
}
2017-08-10 13:25:24 +00:00
return n;
}
EXPORT_SYMBOL(_copy_to_user);
#endif