put_compat_rusage(): switch to copy_to_user()
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 31 May 2017 10:39:31 +0000 (06:39 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 10 Jun 2017 03:56:13 +0000 (23:56 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
kernel/compat.c

index 195e23469854eea52ecb2610e237bb78ab89889f..64e772aabdb5f8e8d736ad730a4f02bc1e3087fa 100644 (file)
@@ -406,25 +406,27 @@ COMPAT_SYSCALL_DEFINE3(sigprocmask, int, how,
 
 int put_compat_rusage(const struct rusage *r, struct compat_rusage __user *ru)
 {
-       if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru)) ||
-           __put_user(r->ru_utime.tv_sec, &ru->ru_utime.tv_sec) ||
-           __put_user(r->ru_utime.tv_usec, &ru->ru_utime.tv_usec) ||
-           __put_user(r->ru_stime.tv_sec, &ru->ru_stime.tv_sec) ||
-           __put_user(r->ru_stime.tv_usec, &ru->ru_stime.tv_usec) ||
-           __put_user(r->ru_maxrss, &ru->ru_maxrss) ||
-           __put_user(r->ru_ixrss, &ru->ru_ixrss) ||
-           __put_user(r->ru_idrss, &ru->ru_idrss) ||
-           __put_user(r->ru_isrss, &ru->ru_isrss) ||
-           __put_user(r->ru_minflt, &ru->ru_minflt) ||
-           __put_user(r->ru_majflt, &ru->ru_majflt) ||
-           __put_user(r->ru_nswap, &ru->ru_nswap) ||
-           __put_user(r->ru_inblock, &ru->ru_inblock) ||
-           __put_user(r->ru_oublock, &ru->ru_oublock) ||
-           __put_user(r->ru_msgsnd, &ru->ru_msgsnd) ||
-           __put_user(r->ru_msgrcv, &ru->ru_msgrcv) ||
-           __put_user(r->ru_nsignals, &ru->ru_nsignals) ||
-           __put_user(r->ru_nvcsw, &ru->ru_nvcsw) ||
-           __put_user(r->ru_nivcsw, &ru->ru_nivcsw))
+       struct compat_rusage r32;
+       memset(&r32, 0, sizeof(r32));
+       r32.ru_utime.tv_sec = r->ru_utime.tv_sec;
+       r32.ru_utime.tv_usec = r->ru_utime.tv_usec;
+       r32.ru_stime.tv_sec = r->ru_stime.tv_sec;
+       r32.ru_stime.tv_usec = r->ru_stime.tv_usec;
+       r32.ru_maxrss = r->ru_maxrss;
+       r32.ru_ixrss = r->ru_ixrss;
+       r32.ru_idrss = r->ru_idrss;
+       r32.ru_isrss = r->ru_isrss;
+       r32.ru_minflt = r->ru_minflt;
+       r32.ru_majflt = r->ru_majflt;
+       r32.ru_nswap = r->ru_nswap;
+       r32.ru_inblock = r->ru_inblock;
+       r32.ru_oublock = r->ru_oublock;
+       r32.ru_msgsnd = r->ru_msgsnd;
+       r32.ru_msgrcv = r->ru_msgrcv;
+       r32.ru_nsignals = r->ru_nsignals;
+       r32.ru_nvcsw = r->ru_nvcsw;
+       r32.ru_nivcsw = r->ru_nivcsw;
+       if (copy_to_user(ru, &r32, sizeof(r32)))
                return -EFAULT;
        return 0;
 }