2011-06-07 16:49:55 +07:00
|
|
|
/*
|
|
|
|
* User address space access functions.
|
|
|
|
*
|
|
|
|
* For licencing details see kernel-base/COPYING
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/highmem.h>
|
2016-07-14 07:18:57 +07:00
|
|
|
#include <linux/export.h>
|
2011-06-07 16:49:55 +07:00
|
|
|
|
2012-04-07 04:32:32 +07:00
|
|
|
#include <asm/word-at-a-time.h>
|
2012-04-21 05:41:36 +07:00
|
|
|
#include <linux/sched.h>
|
2012-04-07 04:32:32 +07:00
|
|
|
|
2011-06-07 16:49:55 +07:00
|
|
|
/*
|
2013-10-24 17:52:06 +07:00
|
|
|
* We rely on the nested NMI work to allow atomic faults from the NMI path; the
|
|
|
|
* nested NMI paths are careful to preserve CR2.
|
2011-06-07 16:49:55 +07:00
|
|
|
*/
|
|
|
|
unsigned long
|
|
|
|
copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
|
|
|
|
{
|
2013-10-24 17:52:06 +07:00
|
|
|
unsigned long ret;
|
2011-06-07 16:49:55 +07:00
|
|
|
|
2012-06-11 20:44:26 +07:00
|
|
|
if (__range_not_ok(from, n, TASK_SIZE))
|
2015-06-23 02:38:43 +07:00
|
|
|
return n;
|
2013-10-24 17:52:06 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Even though this function is typically called from NMI/IRQ context
|
|
|
|
* disable pagefaults so that its behaviour is consistent even when
|
|
|
|
* called form other contexts.
|
|
|
|
*/
|
|
|
|
pagefault_disable();
|
|
|
|
ret = __copy_from_user_inatomic(to, from, n);
|
|
|
|
pagefault_enable();
|
|
|
|
|
2013-10-31 03:16:22 +07:00
|
|
|
return ret;
|
2011-06-07 16:49:55 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(copy_from_user_nmi);
|
2016-10-31 22:10:15 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* copy_to_user: - Copy a block of data into user space.
|
|
|
|
* @to: Destination address, in user space.
|
|
|
|
* @from: Source address, in kernel space.
|
|
|
|
* @n: Number of bytes to copy.
|
|
|
|
*
|
|
|
|
* Context: User context only. This function may sleep if pagefaults are
|
|
|
|
* enabled.
|
|
|
|
*
|
|
|
|
* Copy data from kernel space to user space.
|
|
|
|
*
|
|
|
|
* Returns number of bytes that could not be copied.
|
|
|
|
* On success, this will be zero.
|
|
|
|
*/
|
|
|
|
unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
|
|
|
|
{
|
|
|
|
if (access_ok(VERIFY_WRITE, to, n))
|
|
|
|
n = __copy_to_user(to, from, n);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(_copy_to_user);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* copy_from_user: - Copy a block of data from user space.
|
|
|
|
* @to: Destination address, in kernel space.
|
|
|
|
* @from: Source address, in user space.
|
|
|
|
* @n: Number of bytes to copy.
|
|
|
|
*
|
|
|
|
* Context: User context only. This function may sleep if pagefaults are
|
|
|
|
* enabled.
|
|
|
|
*
|
|
|
|
* Copy data from user space to kernel space.
|
|
|
|
*
|
|
|
|
* Returns number of bytes that could not be copied.
|
|
|
|
* On success, this will be zero.
|
|
|
|
*
|
|
|
|
* If some data could not be copied, this function will pad the copied
|
|
|
|
* data to the requested size using zero bytes.
|
|
|
|
*/
|
|
|
|
unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
|
|
|
|
{
|
2017-03-26 05:36:22 +07:00
|
|
|
unsigned long res = n;
|
2016-10-31 22:10:15 +07:00
|
|
|
if (access_ok(VERIFY_READ, from, n))
|
2017-03-26 05:36:22 +07:00
|
|
|
res = __copy_from_user_inatomic(to, from, n);
|
|
|
|
if (unlikely(res))
|
|
|
|
memset(to + n - res, 0, res);
|
|
|
|
return res;
|
2016-10-31 22:10:15 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(_copy_from_user);
|