11965aae3c98397aad957412413c07e97b1bd4e64H. Peter Anvin#ifndef _ASM_X86_UACCESS_32_H
21965aae3c98397aad957412413c07e97b1bd4e64H. Peter Anvin#define _ASM_X86_UACCESS_32_H
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * User space memory access functions
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/errno.h>
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/thread_info.h>
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/string.h>
1014e6d17d683c02c114fccdde3a867033e8781416H. Peter Anvin#include <asm/asm.h>
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/page.h>
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
13b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_to_user_ll
14b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void __user *to, const void *from, unsigned long n);
15b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_from_user_ll
16b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void *to, const void __user *from, unsigned long n);
17b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_from_user_ll_nozero
18b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void *to, const void __user *from, unsigned long n);
19b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_from_user_ll_nocache
20b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void *to, const void __user *from, unsigned long n);
21b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_from_user_ll_nocache_nozero
22b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void *to, const void __user *from, unsigned long n);
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
246d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V/**
256d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
266d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * @to:   Destination address, in user space.
276d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * @from: Source address, in kernel space.
286d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * @n:    Number of bytes to copy.
296d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V *
306d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * Context: User context only.
316d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V *
326d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * Copy data from kernel space to user space.  Caller must check
336d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * the specified block with access_ok() before calling this function.
346d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * The caller should also make sure he pins the user space address
354fe487828b912ca004b4f4505275ab164ed6ce9fSergey Senozhatsky * so that we don't result in page fault and sleep.
366d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V *
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Here we special-case 1, 2 and 4-byte copy_*_user invocations.  On a fault
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * we return the initial request size (1, 2 or 4), as copy_*_user should do.
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If a store crosses a page boundary and gets a fault, the x86 will not write
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * anything, so this is accurate.
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
43652050aec936fdd70ed9cbce1cd1ef30a7c9d117Ingo Molnarstatic __always_inline unsigned long __must_check
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (__builtin_constant_p(n)) {
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		unsigned long ret;
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		switch (n) {
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 1:
51b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches			__put_user_size(*(u8 *)from, (u8 __user *)to,
52b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					1, ret, 1);
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 2:
55b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches			__put_user_size(*(u16 *)from, (u16 __user *)to,
56b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					2, ret, 2);
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 4:
59b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches			__put_user_size(*(u32 *)from, (u32 __user *)to,
60b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					4, ret, 4);
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return __copy_to_user_ll(to, from, n);
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**
689c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * __copy_to_user: - Copy a block of data into user space, with less checking.
699c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @to:   Destination address, in user space.
709c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @from: Source address, in kernel space.
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @n:    Number of bytes to copy.
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Context: User context only.  This function may sleep.
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
759c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * Copy data from kernel space to user space.  Caller must check
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the specified block with access_ok() before calling this function.
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Returns number of bytes that could not be copied.
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * On success, this will be zero.
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
819c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlapstatic __always_inline unsigned long __must_check
829c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap__copy_to_user(void __user *to, const void *from, unsigned long n)
839c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap{
843ee1afa308f2a38e5d1e2ad3752ad7abcf480da1Nick Piggin	might_fault();
85c10d38dda1774ed4540380333cabd229eff37094Nick Piggin	return __copy_to_user_inatomic(to, from, n);
869c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap}
879c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap
88652050aec936fdd70ed9cbce1cd1ef30a7c9d117Ingo Molnarstatic __always_inline unsigned long
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
917c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	/* Avoid zeroing the tail if the copy fails..
927c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
937c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	 * but as the zeroing behaviour is only significant when n is not
947c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	 * constant, that shouldn't be a problem.
957c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	 */
967c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	if (__builtin_constant_p(n)) {
977c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		unsigned long ret;
987c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown
997c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		switch (n) {
1007c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		case 1:
1017c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			__get_user_size(*(u8 *)to, from, 1, ret, 1);
1027c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			return ret;
1037c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		case 2:
1047c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			__get_user_size(*(u16 *)to, from, 2, ret, 2);
1057c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			return ret;
1067c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		case 4:
1077c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			__get_user_size(*(u32 *)to, from, 4, ret, 4);
1087c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			return ret;
1097c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		}
1107c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	}
1117c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	return __copy_from_user_ll_nozero(to, from, n);
1127c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown}
1139c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap
1149c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap/**
1159c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * __copy_from_user: - Copy a block of data from user space, with less checking.
1169c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @to:   Destination address, in kernel space.
1179c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @from: Source address, in user space.
1189c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @n:    Number of bytes to copy.
1199c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1209c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * Context: User context only.  This function may sleep.
1219c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1229c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * Copy data from user space to kernel space.  Caller must check
1239c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * the specified block with access_ok() before calling this function.
1249c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1259c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * Returns number of bytes that could not be copied.
1269c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * On success, this will be zero.
1279c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1289c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * If some data could not be copied, this function will pad the copied
1299c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * data to the requested size using zero bytes.
1309c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1319c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * An alternate version - __copy_from_user_inatomic() - may be called from
1329c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * atomic context and will fail rather than sleep.  In this case the
1339c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * uncopied bytes will *NOT* be padded with zeros.  See fs/filemap.h
1349c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * for explanation of why this is needed.
1359c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap */
1367c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrownstatic __always_inline unsigned long
1377c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown__copy_from_user(void *to, const void __user *from, unsigned long n)
1387c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown{
1393ee1afa308f2a38e5d1e2ad3752ad7abcf480da1Nick Piggin	might_fault();
1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (__builtin_constant_p(n)) {
1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		unsigned long ret;
1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		switch (n) {
1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 1:
1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__get_user_size(*(u8 *)to, from, 1, ret, 1);
1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 2:
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__get_user_size(*(u16 *)to, from, 2, ret, 2);
1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 4:
1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__get_user_size(*(u32 *)to, from, 4, ret, 4);
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return __copy_from_user_ll(to, from, n);
1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1587c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrownstatic __always_inline unsigned long __copy_from_user_nocache(void *to,
159c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka				const void __user *from, unsigned long n)
160c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka{
1613ee1afa308f2a38e5d1e2ad3752ad7abcf480da1Nick Piggin	might_fault();
162c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka	if (__builtin_constant_p(n)) {
163c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		unsigned long ret;
164c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka
165c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		switch (n) {
166c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		case 1:
167c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			__get_user_size(*(u8 *)to, from, 1, ret, 1);
168c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			return ret;
169c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		case 2:
170c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			__get_user_size(*(u16 *)to, from, 2, ret, 2);
171c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			return ret;
172c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		case 4:
173c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			__get_user_size(*(u32 *)to, from, 4, ret, 4);
174c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			return ret;
175c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		}
176c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka	}
177c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka	return __copy_from_user_ll_nocache(to, from, n);
178c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka}
179c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka
180652050aec936fdd70ed9cbce1cd1ef30a7c9d117Ingo Molnarstatic __always_inline unsigned long
181b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches__copy_from_user_inatomic_nocache(void *to, const void __user *from,
182b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches				  unsigned long n)
1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1847c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown       return __copy_from_user_ll_nocache_nozero(to, from, n);
185c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka}
186c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka
1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsunsigned long __must_check copy_to_user(void __user *to,
188b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					const void *from, unsigned long n);
1899f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Venunsigned long __must_check _copy_from_user(void *to,
190b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					  const void __user *from,
191b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					  unsigned long n);
1929f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven
1934a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven
1944a3127693001c61a21d1ce680db6340623f52e93Arjan van de Venextern void copy_from_user_overflow(void)
19563312b6a6faae3f2e5577f2b001e3b504f10a2aaArjan van de Ven#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19663312b6a6faae3f2e5577f2b001e3b504f10a2aaArjan van de Ven	__compiletime_error("copy_from_user() buffer size is not provably correct")
19763312b6a6faae3f2e5577f2b001e3b504f10a2aaArjan van de Ven#else
1984a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven	__compiletime_warning("copy_from_user() buffer size is not provably correct")
1994a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven#endif
2004a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven;
2014a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven
2029f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Venstatic inline unsigned long __must_check copy_from_user(void *to,
2039f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven					  const void __user *from,
2049f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven					  unsigned long n)
2059f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven{
2069f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven	int sz = __compiletime_object_size(to);
2079f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven
2089f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven	if (likely(sz == -1 || sz >= n))
209409d02ef6d74f5e91f5ea4c587b2ee1375f106fcHeiko Carstens		n = _copy_from_user(to, from, n);
2109f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven	else
2114a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven		copy_from_user_overflow();
2124a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven
213409d02ef6d74f5e91f5ea4c587b2ee1375f106fcHeiko Carstens	return n;
2149f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven}
2159f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven
2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**
2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * strlen_user: - Get the size of a string in user space.
2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @str: The string to measure.
2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Context: User context only.  This function may sleep.
2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Get the size of a NUL-terminated string in user space.
2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Returns the size of the string INCLUDING the terminating NUL.
2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * On exception, returns 0.
2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If there is a limit on the length of a valid string, you may wish to
2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * consider using strnlen_user() instead.
2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
23048dd9343d0bb54362a2ba65380fea7c8f07f9e74Robert P. J. Day#define strlen_user(str) strnlen_user(str, LONG_MAX)
2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldslong strnlen_user(const char __user *str, long n);
2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsunsigned long __must_check clear_user(void __user *mem, unsigned long len);
2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsunsigned long __must_check __clear_user(void __user *mem, unsigned long len);
2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2361965aae3c98397aad957412413c07e97b1bd4e64H. Peter Anvin#endif /* _ASM_X86_UACCESS_32_H */
237