lib: Reduce user_access_begin() boundaries in strncpy_from_user() and strnlen_user()
[linux-2.6-block.git] / lib / strncpy_from_user.c
index dccb95af600322cc6a3f7db1229d52b47a6b037b..706020b06617ce6fae8e0e9517259a6a0fcfcb78 100644 (file)
@@ -30,13 +30,6 @@ static inline long do_strncpy_from_user(char *dst, const char __user *src,
        const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
        unsigned long res = 0;
 
-       /*
-        * Truncate 'max' to the user-specified limit, so that
-        * we only have one limit we need to check in the loop
-        */
-       if (max > count)
-               max = count;
-
        if (IS_UNALIGNED(src, dst))
                goto byte_at_a_time;
 
@@ -114,6 +107,13 @@ long strncpy_from_user(char *dst, const char __user *src, long count)
                unsigned long max = max_addr - src_addr;
                long retval;
 
+               /*
+                * Truncate 'max' to the user-specified limit, so that
+                * we only have one limit we need to check in the loop
+                */
+               if (max > count)
+                       max = count;
+
                kasan_check_write(dst, count);
                check_object_size(dst, count, false);
                if (user_access_begin(src, max)) {