take compat_sys_old_getrlimit() to native syscall
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 27 May 2017 02:04:29 +0000 (22:04 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 27 May 2017 19:38:06 +0000 (15:38 -0400)
... and sanitize the ifdefs in there

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
arch/powerpc/include/asm/compat.h
arch/s390/include/asm/compat.h
arch/x86/include/asm/compat.h
include/linux/syscalls.h
kernel/compat.c
kernel/sys.c

index 4f2df58..f256e1d 100644 (file)
@@ -109,7 +109,6 @@ struct compat_statfs {
        int             f_spare[4];
 };
 
-#define COMPAT_RLIM_OLD_INFINITY       0x7fffffff
 #define COMPAT_RLIM_INFINITY           0xffffffff
 
 typedef u32            compat_old_sigset_t;
index 0ddd37e..b9300f8 100644 (file)
@@ -178,7 +178,6 @@ struct compat_statfs64 {
        u32             f_spare[4];
 };
 
-#define COMPAT_RLIM_OLD_INFINITY       0x7fffffff
 #define COMPAT_RLIM_INFINITY           0xffffffff
 
 typedef u32            compat_old_sigset_t;    /* at least 32 bits */
index 24118c0..5343c19 100644 (file)
@@ -116,7 +116,6 @@ struct compat_statfs {
        int             f_spare[4];
 };
 
-#define COMPAT_RLIM_OLD_INFINITY       0x7fffffff
 #define COMPAT_RLIM_INFINITY           0xffffffff
 
 typedef u32            compat_old_sigset_t;    /* at least 32 bits */
index 980c3c9..3cb15ea 100644 (file)
@@ -650,7 +650,7 @@ asmlinkage long sys_olduname(struct oldold_utsname __user *);
 
 asmlinkage long sys_getrlimit(unsigned int resource,
                                struct rlimit __user *rlim);
-#if defined(COMPAT_RLIM_OLD_INFINITY) || !(defined(CONFIG_IA64))
+#ifdef __ARCH_WANT_SYS_OLD_GETRLIMIT
 asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *rlim);
 #endif
 asmlinkage long sys_setrlimit(unsigned int resource,
index 933bcb3..860f674 100644 (file)
@@ -468,35 +468,6 @@ COMPAT_SYSCALL_DEFINE2(setrlimit, unsigned int, resource,
        return do_prlimit(current, resource, &r, NULL);
 }
 
-#ifdef COMPAT_RLIM_OLD_INFINITY
-
-COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
-                      struct compat_rlimit __user *, rlim)
-{
-       struct rlimit r;
-       int ret;
-       mm_segment_t old_fs = get_fs();
-
-       set_fs(KERNEL_DS);
-       ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
-       set_fs(old_fs);
-
-       if (!ret) {
-               if (r.rlim_cur > COMPAT_RLIM_OLD_INFINITY)
-                       r.rlim_cur = COMPAT_RLIM_INFINITY;
-               if (r.rlim_max > COMPAT_RLIM_OLD_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;
-}
-
-#endif
-
 COMPAT_SYSCALL_DEFINE2(getrlimit, unsigned int, resource,
                       struct compat_rlimit __user *, rlim)
 {
index 8a94b4e..3778a8a 100644 (file)
@@ -1328,6 +1328,30 @@ SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
        return copy_to_user(rlim, &x, sizeof(x)) ? -EFAULT : 0;
 }
 
+#ifdef CONFIG_COMPAT
+COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
+                      struct compat_rlimit __user *, rlim)
+{
+       struct rlimit r;
+
+       if (resource >= RLIM_NLIMITS)
+               return -EINVAL;
+
+       task_lock(current->group_leader);
+       r = current->signal->rlim[resource];
+       task_unlock(current->group_leader);
+       if (r.rlim_cur > 0x7FFFFFFF)
+               r.rlim_cur = 0x7FFFFFFF;
+       if (r.rlim_max > 0x7FFFFFFF)
+               r.rlim_max = 0x7FFFFFFF;
+
+       if (put_user(r.rlim_cur, &rlim->rlim_cur) ||
+           put_user(r.rlim_max, &rlim->rlim_max))
+               return -EFAULT;
+       return 0;
+}
+#endif
+
 #endif
 
 static inline bool rlim64_is_infinity(__u64 rlim64)