x86_64: csum_..._copy_..._user(): switch to unsafe_..._user()
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 16 Feb 2020 19:56:36 +0000 (14:56 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 29 May 2020 20:11:28 +0000 (16:11 -0400)
We already have stac/clac pair around the calls of csum_partial_copy_generic().
Stretch that area back, so that it covers the preceding loop (and convert
the loop body from __{get,put}_user() to unsafe_{get,put}_user()).
That brings the beginning of the areas to the earlier access_ok(),
which allows to convert them into user_access_{begin,end}() ones.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
arch/x86/lib/csum-wrappers_64.c

index 875c2f5..7028d1d 100644 (file)
@@ -27,7 +27,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
        might_sleep();
        *errp = 0;
 
-       if (!likely(access_ok(src, len)))
+       if (!user_access_begin(src, len))
                goto out_err;
 
        /*
@@ -42,8 +42,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
                while (((unsigned long)src & 6) && len >= 2) {
                        __u16 val16;
 
-                       if (__get_user(val16, (const __u16 __user *)src))
-                               goto out_err;
+                       unsafe_get_user(val16, (const __u16 __user *)src, out);
 
                        *(__u16 *)dst = val16;
                        isum = (__force __wsum)add32_with_carry(
@@ -53,15 +52,16 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
                        len -= 2;
                }
        }
-       stac();
        isum = csum_partial_copy_generic((__force const void *)src,
                                dst, len, isum, errp, NULL);
-       clac();
+       user_access_end();
        if (unlikely(*errp))
                goto out_err;
 
        return isum;
 
+out:
+       user_access_end();
 out_err:
        *errp = -EFAULT;
        memset(dst, 0, len);
@@ -89,7 +89,7 @@ csum_and_copy_to_user(const void *src, void __user *dst,
 
        might_sleep();
 
-       if (unlikely(!access_ok(dst, len))) {
+       if (!user_access_begin(dst, len)) {
                *errp = -EFAULT;
                return 0;
        }
@@ -100,9 +100,7 @@ csum_and_copy_to_user(const void *src, void __user *dst,
 
                        isum = (__force __wsum)add32_with_carry(
                                        (__force unsigned)isum, val16);
-                       *errp = __put_user(val16, (__u16 __user *)dst);
-                       if (*errp)
-                               return isum;
+                       unsafe_put_user(val16, (__u16 __user *)dst, out);
                        src += 2;
                        dst += 2;
                        len -= 2;
@@ -110,11 +108,14 @@ csum_and_copy_to_user(const void *src, void __user *dst,
        }
 
        *errp = 0;
-       stac();
        ret = csum_partial_copy_generic(src, (void __force *)dst,
                                        len, isum, NULL, errp);
-       clac();
+       user_access_end();
        return ret;
+out:
+       user_access_end();
+       *errp = -EFAULT;
+       return isum;
 }
 EXPORT_SYMBOL(csum_and_copy_to_user);