~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/usercopy.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <linux/compiler.h>
  3 #include <linux/errno.h>
  4 #include <linux/export.h>
  5 #include <linux/fault-inject-usercopy.h>
  6 #include <linux/instrumented.h>
  7 #include <linux/kernel.h>
  8 #include <linux/nospec.h>
  9 #include <linux/string.h>
 10 #include <linux/uaccess.h>
 11 #include <linux/wordpart.h>
 12 
 13 /* out-of-line parts */
 14 
 15 #if !defined(INLINE_COPY_FROM_USER) || defined(CONFIG_RUST)
 16 unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n)
 17 {
 18         return _inline_copy_from_user(to, from, n);
 19 }
 20 EXPORT_SYMBOL(_copy_from_user);
 21 #endif
 22 
 23 #if !defined(INLINE_COPY_TO_USER) || defined(CONFIG_RUST)
 24 unsigned long _copy_to_user(void __user *to, const void *from, unsigned long n)
 25 {
 26         return _inline_copy_to_user(to, from, n);
 27 }
 28 EXPORT_SYMBOL(_copy_to_user);
 29 #endif
 30 
 31 /**
 32  * check_zeroed_user: check if a userspace buffer only contains zero bytes
 33  * @from: Source address, in userspace.
 34  * @size: Size of buffer.
 35  *
 36  * This is effectively shorthand for "memchr_inv(from, 0, size) == NULL" for
 37  * userspace addresses (and is more efficient because we don't care where the
 38  * first non-zero byte is).
 39  *
 40  * Returns:
 41  *  * 0: There were non-zero bytes present in the buffer.
 42  *  * 1: The buffer was full of zero bytes.
 43  *  * -EFAULT: access to userspace failed.
 44  */
 45 int check_zeroed_user(const void __user *from, size_t size)
 46 {
 47         unsigned long val;
 48         uintptr_t align = (uintptr_t) from % sizeof(unsigned long);
 49 
 50         if (unlikely(size == 0))
 51                 return 1;
 52 
 53         from -= align;
 54         size += align;
 55 
 56         if (!user_read_access_begin(from, size))
 57                 return -EFAULT;
 58 
 59         unsafe_get_user(val, (unsigned long __user *) from, err_fault);
 60         if (align)
 61                 val &= ~aligned_byte_mask(align);
 62 
 63         while (size > sizeof(unsigned long)) {
 64                 if (unlikely(val))
 65                         goto done;
 66 
 67                 from += sizeof(unsigned long);
 68                 size -= sizeof(unsigned long);
 69 
 70                 unsafe_get_user(val, (unsigned long __user *) from, err_fault);
 71         }
 72 
 73         if (size < sizeof(unsigned long))
 74                 val &= aligned_byte_mask(size);
 75 
 76 done:
 77         user_read_access_end();
 78         return (val == 0);
 79 err_fault:
 80         user_read_access_end();
 81         return -EFAULT;
 82 }
 83 EXPORT_SYMBOL(check_zeroed_user);
 84 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php