@@ -109,8 +109,11 @@ static inline unsigned long
109
109
_copy_from_user (void * to , const void __user * from , unsigned long n )
110
110
{
111
111
unsigned long res = n ;
112
- if (likely (access_ok (VERIFY_READ , from , n )))
112
+ might_fault ();
113
+ if (likely (access_ok (VERIFY_READ , from , n ))) {
114
+ kasan_check_write (to , n );
113
115
res = raw_copy_from_user (to , from , n );
116
+ }
114
117
if (unlikely (res ))
115
118
memset (to + (n - res ), 0 , res );
116
119
return res ;
@@ -124,8 +127,11 @@ _copy_from_user(void *, const void __user *, unsigned long);
124
127
static inline unsigned long
125
128
_copy_to_user (void __user * to , const void * from , unsigned long n )
126
129
{
127
- if (access_ok (VERIFY_WRITE , to , n ))
130
+ might_fault ();
131
+ if (access_ok (VERIFY_WRITE , to , n )) {
132
+ kasan_check_read (from , n );
128
133
n = raw_copy_to_user (to , from , n );
134
+ }
129
135
return n ;
130
136
}
131
137
#else
@@ -146,9 +152,6 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
146
152
{
147
153
int sz = __compiletime_object_size (to );
148
154
149
- might_fault ();
150
- kasan_check_write (to , n );
151
-
152
155
if (likely (sz < 0 || sz >= n )) {
153
156
check_object_size (to , n , false);
154
157
n = _copy_from_user (to , from , n );
@@ -165,9 +168,6 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
165
168
{
166
169
int sz = __compiletime_object_size (from );
167
170
168
- kasan_check_read (from , n );
169
- might_fault ();
170
-
171
171
if (likely (sz < 0 || sz >= n )) {
172
172
check_object_size (from , n , true);
173
173
n = _copy_to_user (to , from , n );
0 commit comments