summaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2020-07-11 06:27:49 +0200
committerAl Viro <viro@zeniv.linux.org.uk>2020-08-20 21:45:15 +0200
commitc693cc4676a055c4126e487b30b0a96ea7ec9936 (patch)
tree8f057e3923deeffd1405e40e7ab1c056fa204189 /arch/x86
parentcsum_and_copy_..._user(): pass 0xffffffff instead of 0 as initial sum (diff)
downloadlinux-c693cc4676a055c4126e487b30b0a96ea7ec9936.tar.xz
linux-c693cc4676a055c4126e487b30b0a96ea7ec9936.zip
saner calling conventions for csum_and_copy_..._user()
All callers of these primitives will * discard anything we might've copied in case of error * ignore the csum value in case of error * always pass 0xffffffff as the initial sum, so the resulting csum value (in case of success, that is) will never be 0. That suggest the following calling conventions: * don't pass err_ptr - just return 0 on error. * don't bother with zeroing destination, etc. in case of error * don't pass the initial sum - just use 0xffffffff. This commit does the minimal conversion in the instances of csum_and_copy_...(); the changes of actual asm code behind them are done later in the series. Note that this asm code is often shared with csum_partial_copy_nocheck(); the difference is that csum_partial_copy_nocheck() passes 0 for initial sum while csum_and_copy_..._user() pass 0xffffffff. Fortunately, we are free to pass 0xffffffff in all cases and subsequent patches will use that freedom without any special comments. A part that could be split off: parisc and uml/i386 claimed to have csum_and_copy_to_user() instances of their own, but those were identical to the generic one, so we simply drop them. Not sure if it's worth a separate commit... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/include/asm/checksum_32.h35
-rw-r--r--arch/x86/include/asm/checksum_64.h6
-rw-r--r--arch/x86/lib/csum-wrappers_64.c38
-rw-r--r--arch/x86/um/asm/checksum_32.h23
4 files changed, 32 insertions, 70 deletions
diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
index 137a3033edcc..5948cde9e4ad 100644
--- a/arch/x86/include/asm/checksum_32.h
+++ b/arch/x86/include/asm/checksum_32.h
@@ -44,22 +44,19 @@ static inline __wsum csum_partial_copy_nocheck(const void *src, void *dst, int l
}
static inline __wsum csum_and_copy_from_user(const void __user *src,
- void *dst, int len,
- __wsum sum, int *err_ptr)
+ void *dst, int len)
{
__wsum ret;
+ int err = 0;
might_sleep();
- if (!user_access_begin(src, len)) {
- if (len)
- *err_ptr = -EFAULT;
- return sum;
- }
+ if (!user_access_begin(src, len))
+ return 0;
ret = csum_partial_copy_generic((__force void *)src, dst,
- len, sum, err_ptr, NULL);
+ len, ~0U, &err, NULL);
user_access_end();
- return ret;
+ return err ? 0 : ret;
}
/*
@@ -177,23 +174,19 @@ static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
*/
static inline __wsum csum_and_copy_to_user(const void *src,
void __user *dst,
- int len, __wsum sum,
- int *err_ptr)
+ int len)
{
__wsum ret;
+ int err = 0;
might_sleep();
- if (user_access_begin(dst, len)) {
- ret = csum_partial_copy_generic(src, (__force void *)dst,
- len, sum, NULL, err_ptr);
- user_access_end();
- return ret;
- }
+ if (!user_access_begin(dst, len))
+ return 0;
- if (len)
- *err_ptr = -EFAULT;
-
- return (__force __wsum)-1; /* invalid checksum */
+ ret = csum_partial_copy_generic(src, (__force void *)dst,
+ len, ~0U, NULL, &err);
+ user_access_end();
+ return err ? 0 : ret;
}
#endif /* _ASM_X86_CHECKSUM_32_H */
diff --git a/arch/x86/include/asm/checksum_64.h b/arch/x86/include/asm/checksum_64.h
index 5339f5dfc776..9af3aed54c6b 100644
--- a/arch/x86/include/asm/checksum_64.h
+++ b/arch/x86/include/asm/checksum_64.h
@@ -135,10 +135,8 @@ extern __visible __wsum csum_partial_copy_generic(const void *src, const void *d
int *src_err_ptr, int *dst_err_ptr);
-extern __wsum csum_and_copy_from_user(const void __user *src, void *dst,
- int len, __wsum isum, int *errp);
-extern __wsum csum_and_copy_to_user(const void *src, void __user *dst,
- int len, __wsum isum, int *errp);
+extern __wsum csum_and_copy_from_user(const void __user *src, void *dst, int len);
+extern __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len);
extern __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len);
/**
diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
index 245f929a1c2c..ae2fb87e2274 100644
--- a/arch/x86/lib/csum-wrappers_64.c
+++ b/arch/x86/lib/csum-wrappers_64.c
@@ -22,13 +22,15 @@
*/
__wsum
csum_and_copy_from_user(const void __user *src, void *dst,
- int len, __wsum isum, int *errp)
+ int len)
{
+ int err = 0;
+ __wsum isum = ~0U;
+
might_sleep();
- *errp = 0;
if (!user_access_begin(src, len))
- goto out_err;
+ return 0;
/*
* Why 6, not 7? To handle odd addresses aligned we
@@ -53,20 +55,15 @@ csum_and_copy_from_user(const void __user *src, void *dst,
}
}
isum = csum_partial_copy_generic((__force const void *)src,
- dst, len, isum, errp, NULL);
+ dst, len, isum, &err, NULL);
user_access_end();
- if (unlikely(*errp))
- goto out_err;
-
+ if (unlikely(err))
+ isum = 0;
return isum;
out:
user_access_end();
-out_err:
- *errp = -EFAULT;
- memset(dst, 0, len);
-
- return isum;
+ return 0;
}
EXPORT_SYMBOL(csum_and_copy_from_user);
@@ -83,16 +80,15 @@ EXPORT_SYMBOL(csum_and_copy_from_user);
*/
__wsum
csum_and_copy_to_user(const void *src, void __user *dst,
- int len, __wsum isum, int *errp)
+ int len)
{
- __wsum ret;
+ __wsum ret, isum = ~0U;
+ int err = 0;
might_sleep();
- if (!user_access_begin(dst, len)) {
- *errp = -EFAULT;
+ if (!user_access_begin(dst, len))
return 0;
- }
if (unlikely((unsigned long)dst & 6)) {
while (((unsigned long)dst & 6) && len >= 2) {
@@ -107,15 +103,13 @@ csum_and_copy_to_user(const void *src, void __user *dst,
}
}
- *errp = 0;
ret = csum_partial_copy_generic(src, (void __force *)dst,
- len, isum, NULL, errp);
+ len, isum, NULL, &err);
user_access_end();
- return ret;
+ return err ? 0 : ret;
out:
user_access_end();
- *errp = -EFAULT;
- return isum;
+ return 0;
}
EXPORT_SYMBOL(csum_and_copy_to_user);
diff --git a/arch/x86/um/asm/checksum_32.h b/arch/x86/um/asm/checksum_32.h
index b9ac7c9eb72c..0b13c2947ad1 100644
--- a/arch/x86/um/asm/checksum_32.h
+++ b/arch/x86/um/asm/checksum_32.h
@@ -35,27 +35,4 @@ static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
return csum_fold(sum);
}
-/*
- * Copy and checksum to user
- */
-#define HAVE_CSUM_COPY_USER
-static __inline__ __wsum csum_and_copy_to_user(const void *src,
- void __user *dst,
- int len, __wsum sum, int *err_ptr)
-{
- if (access_ok(dst, len)) {
- if (copy_to_user(dst, src, len)) {
- *err_ptr = -EFAULT;
- return (__force __wsum)-1;
- }
-
- return csum_partial(src, len, sum);
- }
-
- if (len)
- *err_ptr = -EFAULT;
-
- return (__force __wsum)-1; /* invalid checksum */
-}
-
#endif