@@ -310,10 +310,15 @@ static inline unsigned long copy_from_user(void *to,
310310{
311311 unsigned long over ;
312312
313- if (access_ok (VERIFY_READ , from , n ))
313+ if (access_ok (VERIFY_READ , from , n )) {
314+ if (!__builtin_constant_p (n ))
315+ check_object_size (to , n , false);
314316 return __copy_tofrom_user ((__force void __user * )to , from , n );
317+ }
315318 if ((unsigned long )from < TASK_SIZE ) {
316319 over = (unsigned long )from + n - TASK_SIZE ;
320+ if (!__builtin_constant_p (n - over ))
321+ check_object_size (to , n - over , false);
317322 return __copy_tofrom_user ((__force void __user * )to , from ,
318323 n - over ) + over ;
319324 }
@@ -325,10 +330,15 @@ static inline unsigned long copy_to_user(void __user *to,
325330{
326331 unsigned long over ;
327332
328- if (access_ok (VERIFY_WRITE , to , n ))
333+ if (access_ok (VERIFY_WRITE , to , n )) {
334+ if (!__builtin_constant_p (n ))
335+ check_object_size (from , n , true);
329336 return __copy_tofrom_user (to , (__force void __user * )from , n );
337+ }
330338 if ((unsigned long )to < TASK_SIZE ) {
331339 over = (unsigned long )to + n - TASK_SIZE ;
340+ if (!__builtin_constant_p (n ))
341+ check_object_size (from , n - over , true);
332342 return __copy_tofrom_user (to , (__force void __user * )from ,
333343 n - over ) + over ;
334344 }
@@ -372,6 +382,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
372382 if (ret == 0 )
373383 return 0 ;
374384 }
385+
386+ if (!__builtin_constant_p (n ))
387+ check_object_size (to , n , false);
388+
375389 return __copy_tofrom_user ((__force void __user * )to , from , n );
376390}
377391
@@ -398,6 +412,9 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
398412 if (ret == 0 )
399413 return 0 ;
400414 }
415+ if (!__builtin_constant_p (n ))
416+ check_object_size (from , n , true);
417+
401418 return __copy_tofrom_user (to , (__force const void __user * )from , n );
402419}
403420
0 commit comments