uaccess_32.h revision 4a3127693001c61a21d1ce680db6340623f52e93
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/prefetch.h>
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/string.h>
1114e6d17d683c02c114fccdde3a867033e8781416H. Peter Anvin#include <asm/asm.h>
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/page.h>
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
14b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_to_user_ll
15b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void __user *to, const void *from, unsigned long n);
16b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_from_user_ll
17b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void *to, const void __user *from, unsigned long n);
18b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_from_user_ll_nozero
19b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void *to, const void __user *from, unsigned long n);
20b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_from_user_ll_nocache
21b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void *to, const void __user *from, unsigned long n);
22b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perchesunsigned long __must_check __copy_from_user_ll_nocache_nozero
23b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches		(void *to, const void __user *from, unsigned long n);
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
256d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V/**
266d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
276d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * @to:   Destination address, in user space.
286d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * @from: Source address, in kernel space.
296d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * @n:    Number of bytes to copy.
306d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V *
316d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * Context: User context only.
326d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V *
336d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * Copy data from kernel space to user space.  Caller must check
346d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * the specified block with access_ok() before calling this function.
356d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V * The caller should also make sure he pins the user space address
364fe487828b912ca004b4f4505275ab164ed6ce9fSergey Senozhatsky * so that we don't result in page fault and sleep.
376d1c426158131b11d05d66e7dd6bf91e5b1b4fc7Aneesh Kumar K.V *
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Here we special-case 1, 2 and 4-byte copy_*_user invocations.  On a fault
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * we return the initial request size (1, 2 or 4), as copy_*_user should do.
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If a store crosses a page boundary and gets a fault, the x86 will not write
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * anything, so this is accurate.
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
44652050aec936fdd70ed9cbce1cd1ef30a7c9d117Ingo Molnarstatic __always_inline unsigned long __must_check
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (__builtin_constant_p(n)) {
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		unsigned long ret;
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		switch (n) {
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 1:
52b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches			__put_user_size(*(u8 *)from, (u8 __user *)to,
53b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					1, ret, 1);
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 2:
56b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches			__put_user_size(*(u16 *)from, (u16 __user *)to,
57b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					2, ret, 2);
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 4:
60b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches			__put_user_size(*(u32 *)from, (u32 __user *)to,
61b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					4, ret, 4);
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return __copy_to_user_ll(to, from, n);
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**
699c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * __copy_to_user: - Copy a block of data into user space, with less checking.
709c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @to:   Destination address, in user space.
719c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @from: Source address, in kernel space.
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @n:    Number of bytes to copy.
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Context: User context only.  This function may sleep.
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
769c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * Copy data from kernel space to user space.  Caller must check
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the specified block with access_ok() before calling this function.
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Returns number of bytes that could not be copied.
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * On success, this will be zero.
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
829c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlapstatic __always_inline unsigned long __must_check
839c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap__copy_to_user(void __user *to, const void *from, unsigned long n)
849c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap{
853ee1afa308f2a38e5d1e2ad3752ad7abcf480da1Nick Piggin	might_fault();
86c10d38dda1774ed4540380333cabd229eff37094Nick Piggin	return __copy_to_user_inatomic(to, from, n);
879c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap}
889c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap
89652050aec936fdd70ed9cbce1cd1ef30a7c9d117Ingo Molnarstatic __always_inline unsigned long
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
927c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	/* Avoid zeroing the tail if the copy fails..
937c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
947c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	 * but as the zeroing behaviour is only significant when n is not
957c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	 * constant, that shouldn't be a problem.
967c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	 */
977c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	if (__builtin_constant_p(n)) {
987c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		unsigned long ret;
997c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown
1007c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		switch (n) {
1017c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		case 1:
1027c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			__get_user_size(*(u8 *)to, from, 1, ret, 1);
1037c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			return ret;
1047c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		case 2:
1057c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			__get_user_size(*(u16 *)to, from, 2, ret, 2);
1067c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			return ret;
1077c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		case 4:
1087c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			__get_user_size(*(u32 *)to, from, 4, ret, 4);
1097c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown			return ret;
1107c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown		}
1117c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	}
1127c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown	return __copy_from_user_ll_nozero(to, from, n);
1137c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown}
1149c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap
1159c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap/**
1169c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * __copy_from_user: - Copy a block of data from user space, with less checking.
1179c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @to:   Destination address, in kernel space.
1189c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @from: Source address, in user space.
1199c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * @n:    Number of bytes to copy.
1209c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1219c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * Context: User context only.  This function may sleep.
1229c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1239c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * Copy data from user space to kernel space.  Caller must check
1249c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * the specified block with access_ok() before calling this function.
1259c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1269c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * Returns number of bytes that could not be copied.
1279c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * On success, this will be zero.
1289c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1299c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * If some data could not be copied, this function will pad the copied
1309c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * data to the requested size using zero bytes.
1319c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap *
1329c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * An alternate version - __copy_from_user_inatomic() - may be called from
1339c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * atomic context and will fail rather than sleep.  In this case the
1349c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * uncopied bytes will *NOT* be padded with zeros.  See fs/filemap.h
1359c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap * for explanation of why this is needed.
1369c7fff6ef36526fb54694ee8201870f98b6a1747Randy Dunlap */
1377c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrownstatic __always_inline unsigned long
1387c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown__copy_from_user(void *to, const void __user *from, unsigned long n)
1397c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown{
1403ee1afa308f2a38e5d1e2ad3752ad7abcf480da1Nick Piggin	might_fault();
1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (__builtin_constant_p(n)) {
1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		unsigned long ret;
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		switch (n) {
1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 1:
1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__get_user_size(*(u8 *)to, from, 1, ret, 1);
1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 2:
1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__get_user_size(*(u16 *)to, from, 2, ret, 2);
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		case 4:
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			__get_user_size(*(u32 *)to, from, 4, ret, 4);
1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			return ret;
1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return __copy_from_user_ll(to, from, n);
1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1597c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrownstatic __always_inline unsigned long __copy_from_user_nocache(void *to,
160c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka				const void __user *from, unsigned long n)
161c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka{
1623ee1afa308f2a38e5d1e2ad3752ad7abcf480da1Nick Piggin	might_fault();
163c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka	if (__builtin_constant_p(n)) {
164c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		unsigned long ret;
165c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka
166c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		switch (n) {
167c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		case 1:
168c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			__get_user_size(*(u8 *)to, from, 1, ret, 1);
169c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			return ret;
170c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		case 2:
171c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			__get_user_size(*(u16 *)to, from, 2, ret, 2);
172c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			return ret;
173c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		case 4:
174c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			__get_user_size(*(u32 *)to, from, 4, ret, 4);
175c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka			return ret;
176c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka		}
177c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka	}
178c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka	return __copy_from_user_ll_nocache(to, from, n);
179c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka}
180c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka
181652050aec936fdd70ed9cbce1cd1ef30a7c9d117Ingo Molnarstatic __always_inline unsigned long
182b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches__copy_from_user_inatomic_nocache(void *to, const void __user *from,
183b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches				  unsigned long n)
1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
1857c12d81134b130ccd4c286b434ca48c4cda71a2fNeilBrown       return __copy_from_user_ll_nocache_nozero(to, from, n);
186c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka}
187c22ce143d15eb288543fe9873e1c5ac1c01b69a1Hiro Yoshioka
1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsunsigned long __must_check copy_to_user(void __user *to,
189b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					const void *from, unsigned long n);
1909f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Venunsigned long __must_check _copy_from_user(void *to,
191b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					  const void __user *from,
192b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches					  unsigned long n);
1939f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven
1944a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven
1954a3127693001c61a21d1ce680db6340623f52e93Arjan van de Venextern void copy_from_user_overflow(void)
1964a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven#ifdef CONFIG_DEBUG_STACKOVERFLOW
1974a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven	__compiletime_warning("copy_from_user() buffer size is not provably correct")
1984a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven#endif
1994a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven;
2004a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven
2019f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Venstatic inline unsigned long __must_check copy_from_user(void *to,
2029f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven					  const void __user *from,
2039f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven					  unsigned long n)
2049f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven{
2059f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven	int sz = __compiletime_object_size(to);
2069f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven	int ret = -EFAULT;
2079f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven
2089f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven	if (likely(sz == -1 || sz >= n))
2099f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven		ret = _copy_from_user(to, from, n);
2109f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven	else
2114a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven		copy_from_user_overflow();
2124a3127693001c61a21d1ce680db6340623f52e93Arjan van de Ven
2139f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven	return ret;
2149f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven}
2159f0cf4adb6aa0bfccf675c938124e68f7f06349dArjan van de Ven
2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldslong __must_check strncpy_from_user(char *dst, const char __user *src,
217b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches				    long count);
2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldslong __must_check __strncpy_from_user(char *dst,
219b1fcec7f2296c4b9126e1b85b52494ac8910d528Joe Perches				      const char __user *src, long count);
2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/**
2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * strlen_user: - Get the size of a string in user space.
2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @str: The string to measure.
2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Context: User context only.  This function may sleep.
2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Get the size of a NUL-terminated string in user space.
2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Returns the size of the string INCLUDING the terminating NUL.
2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * On exception, returns 0.
2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If there is a limit on the length of a valid string, you may wish to
2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * consider using strnlen_user() instead.
2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
23548dd9343d0bb54362a2ba65380fea7c8f07f9e74Robert P. J. Day#define strlen_user(str) strnlen_user(str, LONG_MAX)
2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldslong strnlen_user(const char __user *str, long n);
2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsunsigned long __must_check clear_user(void __user *mem, unsigned long len);
2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsunsigned long __must_check __clear_user(void __user *mem, unsigned long len);
2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2411965aae3c98397aad957412413c07e97b1bd4e64H. Peter Anvin#endif /* _ASM_X86_UACCESS_32_H */
242