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 4f2df589ec1de2e227d0ed7fa43fddf1eecff3ee..f256e1d14a147f417eb537cd5467ecacf84655bf 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 0ddd37e6c29d90e2b996d9056b89a3d367582eae..b9300f8aee10a5754909e63946c6f06d0bbc74f1 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 24118c0b464090372fbd831a891890ecb8debd9b..5343c19814b381065492a58ddf49ca8b7ec814bc 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 980c3c9b06f88176347a73bd6335f270779738d5..3cb15ea48aeea8414beed8cdd11d1ece13f71d0d 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 933bcb31ae10d4c1dcaf2c9b5f48861080d9b3df..860f674fa556edb2342eb84832b2afa22d2a6389 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 8a94b4eabcaa291e6315858deba48a0269363fb9..3778a8a417b6067bfb5e9f8a0d9a359b20549691 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)