|
@@ -544,6 +544,8 @@ extern struct movsl_mask {
|
|
|
|
|
|
unsigned long __must_check _copy_from_user(void *to, const void __user *from,
|
|
|
unsigned n);
|
|
|
+unsigned long __must_check _copy_to_user(void __user *to, const void *from,
|
|
|
+ unsigned n);
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
|
|
|
# define copy_user_diag __compiletime_error
|
|
@@ -553,6 +555,8 @@ unsigned long __must_check _copy_from_user(void *to, const void __user *from,
|
|
|
|
|
|
extern void copy_user_diag("copy_from_user() buffer size is too small")
|
|
|
copy_from_user_overflow(void);
|
|
|
+extern void copy_user_diag("copy_to_user() buffer size is too small")
|
|
|
+copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
|
|
|
|
|
|
#undef copy_user_diag
|
|
|
|
|
@@ -563,6 +567,11 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
|
|
|
__copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
|
|
|
#define __copy_from_user_overflow(size, count) __copy_from_user_overflow()
|
|
|
|
|
|
+extern void
|
|
|
+__compiletime_warning("copy_to_user() buffer size is not provably correct")
|
|
|
+__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
|
|
|
+#define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
|
|
|
+
|
|
|
#else
|
|
|
|
|
|
static inline void
|
|
@@ -571,6 +580,8 @@ __copy_from_user_overflow(int size, unsigned long count)
|
|
|
WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
|
|
|
}
|
|
|
|
|
|
+#define __copy_to_user_overflow __copy_from_user_overflow
|
|
|
+
|
|
|
#endif
|
|
|
|
|
|
static inline unsigned long __must_check
|
|
@@ -608,7 +619,26 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
|
|
|
return n;
|
|
|
}
|
|
|
|
|
|
+static inline unsigned long __must_check
|
|
|
+copy_to_user(void __user *to, const void *from, unsigned long n)
|
|
|
+{
|
|
|
+ int sz = __compiletime_object_size(from);
|
|
|
+
|
|
|
+ might_fault();
|
|
|
+
|
|
|
+ /* See the comment in copy_from_user() above. */
|
|
|
+ if (likely(sz < 0 || sz >= n))
|
|
|
+ n = _copy_to_user(to, from, n);
|
|
|
+ else if(__builtin_constant_p(n))
|
|
|
+ copy_to_user_overflow();
|
|
|
+ else
|
|
|
+ __copy_to_user_overflow(sz, n);
|
|
|
+
|
|
|
+ return n;
|
|
|
+}
|
|
|
+
|
|
|
#undef __copy_from_user_overflow
|
|
|
+#undef __copy_to_user_overflow
|
|
|
|
|
|
#endif /* _ASM_X86_UACCESS_H */
|
|
|
|