getrlimit()/setrlimit(): move compat to native
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 31 May 2017 08:33:51 +0000 (04:33 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 10 Jun 2017 03:51:33 +0000 (23:51 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
kernel/compat.c
kernel/sys.c

index 99408252762e2f8c3de2b22bb1ac51432096e27a..58b8e57398d1ddfeb5bd9b7028309103adad2b91 100644 (file)
@@ -427,44 +427,6 @@ COMPAT_SYSCALL_DEFINE3(sigprocmask, int, how,
 
 #endif
 
-COMPAT_SYSCALL_DEFINE2(setrlimit, unsigned int, resource,
-                      struct compat_rlimit __user *, rlim)
-{
-       struct rlimit r;
-
-       if (!access_ok(VERIFY_READ, rlim, sizeof(*rlim)) ||
-           __get_user(r.rlim_cur, &rlim->rlim_cur) ||
-           __get_user(r.rlim_max, &rlim->rlim_max))
-               return -EFAULT;
-
-       if (r.rlim_cur == COMPAT_RLIM_INFINITY)
-               r.rlim_cur = RLIM_INFINITY;
-       if (r.rlim_max == COMPAT_RLIM_INFINITY)
-               r.rlim_max = RLIM_INFINITY;
-       return do_prlimit(current, resource, &r, NULL);
-}
-
-COMPAT_SYSCALL_DEFINE2(getrlimit, unsigned int, resource,
-                      struct compat_rlimit __user *, rlim)
-{
-       struct rlimit r;
-       int ret;
-
-       ret = do_prlimit(current, resource, NULL, &r);
-       if (!ret) {
-               if (r.rlim_cur > COMPAT_RLIM_INFINITY)
-                       r.rlim_cur = COMPAT_RLIM_INFINITY;
-               if (r.rlim_max > COMPAT_RLIM_INFINITY)
-                       r.rlim_max = COMPAT_RLIM_INFINITY;
-
-               if (!access_ok(VERIFY_WRITE, rlim, sizeof(*rlim)) ||
-                   __put_user(r.rlim_cur, &rlim->rlim_cur) ||
-                   __put_user(r.rlim_max, &rlim->rlim_max))
-                       return -EFAULT;
-       }
-       return ret;
-}
-
 int put_compat_rusage(const struct rusage *r, struct compat_rusage __user *ru)
 {
        if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru)) ||
index 161b5eae9c77f4297770614091ff80270ba6a630..873e6eaa314f732d1db3668644976621f3b5152c 100644 (file)
@@ -1332,6 +1332,54 @@ SYSCALL_DEFINE2(getrlimit, unsigned int, resource, struct rlimit __user *, rlim)
        return ret;
 }
 
+#ifdef CONFIG_COMPAT
+
+COMPAT_SYSCALL_DEFINE2(setrlimit, unsigned int, resource,
+                      struct compat_rlimit __user *, rlim)
+{
+       struct rlimit r;
+       struct compat_rlimit r32;
+
+       if (copy_from_user(&r32, rlim, sizeof(struct compat_rlimit)))
+               return -EFAULT;
+
+       if (r32.rlim_cur == COMPAT_RLIM_INFINITY)
+               r.rlim_cur = RLIM_INFINITY;
+       else
+               r.rlim_cur = r32.rlim_cur;
+       if (r32.rlim_max == COMPAT_RLIM_INFINITY)
+               r.rlim_max = RLIM_INFINITY;
+       else
+               r.rlim_max = r32.rlim_max;
+       return do_prlimit(current, resource, &r, NULL);
+}
+
+COMPAT_SYSCALL_DEFINE2(getrlimit, unsigned int, resource,
+                      struct compat_rlimit __user *, rlim)
+{
+       struct rlimit r;
+       int ret;
+
+       ret = do_prlimit(current, resource, NULL, &r);
+       if (!ret) {
+               struct rlimit r32;
+               if (r.rlim_cur > COMPAT_RLIM_INFINITY)
+                       r32.rlim_cur = COMPAT_RLIM_INFINITY;
+               else
+                       r32.rlim_cur = r.rlim_cur;
+               if (r.rlim_max > COMPAT_RLIM_INFINITY)
+                       r32.rlim_max = COMPAT_RLIM_INFINITY;
+               else
+                       r32.rlim_max = r.rlim_max;
+
+               if (copy_to_user(rlim, &r32, sizeof(struct compat_rlimit)))
+                       return -EFAULT;
+       }
+       return ret;
+}
+
+#endif
+
 #ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
 
 /*