usercopy.c 764 B

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/uaccess.h>
  3. /* out-of-line parts */
  4. #ifndef INLINE_COPY_FROM_USER
  5. unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n)
  6. {
  7. unsigned long res = n;
  8. might_fault();
  9. if (likely(access_ok(VERIFY_READ, from, n))) {
  10. kasan_check_write(to, n);
  11. res = raw_copy_from_user(to, from, n);
  12. }
  13. if (unlikely(res))
  14. memset(to + (n - res), 0, res);
  15. return res;
  16. }
  17. EXPORT_SYMBOL(_copy_from_user);
  18. #endif
  19. #ifndef INLINE_COPY_TO_USER
  20. unsigned long _copy_to_user(void __user *to, const void *from, unsigned long n)
  21. {
  22. might_fault();
  23. if (likely(access_ok(VERIFY_WRITE, to, n))) {
  24. kasan_check_read(from, n);
  25. n = raw_copy_to_user(to, from, n);
  26. }
  27. return n;
  28. }
  29. EXPORT_SYMBOL(_copy_to_user);
  30. #endif