LCOV - code coverage report
Current view: top level - arch/x86/lib - usercopy.c (source / functions) Hit Total Coverage
Test: landlock.info Lines: 8 8 100.0 %
Date: 2021-04-22 12:43:58 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * User address space access functions.
       3             :  *
       4             :  *  For licencing details see kernel-base/COPYING
       5             :  */
       6             : 
       7             : #include <linux/uaccess.h>
       8             : #include <linux/export.h>
       9             : 
      10             : #include <asm/tlbflush.h>
      11             : 
      12             : /**
      13             :  * copy_from_user_nmi - NMI safe copy from user
      14             :  * @to:         Pointer to the destination buffer
      15             :  * @from:       Pointer to a user space address of the current task
      16             :  * @n:          Number of bytes to copy
      17             :  *
      18             :  * Returns: The number of not copied bytes. 0 is success, i.e. all bytes copied
      19             :  *
      20             :  * Contrary to other copy_from_user() variants this function can be called
      21             :  * from NMI context. Despite the name it is not restricted to be called
      22             :  * from NMI context. It is safe to be called from any other context as
      23             :  * well. It disables pagefaults across the copy which means a fault will
      24             :  * abort the copy.
      25             :  *
      26             :  * For NMI context invocations this relies on the nested NMI work to allow
      27             :  * atomic faults from the NMI path; the nested NMI paths are careful to
      28             :  * preserve CR2.
      29             :  */
      30             : unsigned long
      31           1 : copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
      32             : {
      33           1 :         unsigned long ret;
      34             : 
      35           2 :         if (__range_not_ok(from, n, TASK_SIZE))
      36             :                 return n;
      37             : 
      38           1 :         if (!nmi_uaccess_okay())
      39             :                 return n;
      40             : 
      41             :         /*
      42             :          * Even though this function is typically called from NMI/IRQ context
      43             :          * disable pagefaults so that its behaviour is consistent even when
      44             :          * called from other contexts.
      45             :          */
      46           1 :         pagefault_disable();
      47           1 :         ret = __copy_from_user_inatomic(to, from, n);
      48           1 :         pagefault_enable();
      49             : 
      50           1 :         return ret;
      51             : }
      52             : EXPORT_SYMBOL_GPL(copy_from_user_nmi);

Generated by: LCOV version 1.14