]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
statfs: move compat syscalls from compat.c
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 8 Apr 2017 22:08:15 +0000 (18:08 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 17 Apr 2017 16:52:23 +0000 (12:52 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/compat.c
fs/statfs.c

index 07cccc0fdd26a5e364baf817d14f313dbe3166c3..4f22a56c6fcaa06cb0b1629c61576ebcdbb2ef59 100644 (file)
@@ -137,144 +137,6 @@ COMPAT_SYSCALL_DEFINE2(newfstat, unsigned int, fd,
        return error;
 }
 
-static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf)
-{
-       
-       if (sizeof ubuf->f_blocks == 4) {
-               if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail |
-                    kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
-                       return -EOVERFLOW;
-               /* f_files and f_ffree may be -1; it's okay
-                * to stuff that into 32 bits */
-               if (kbuf->f_files != 0xffffffffffffffffULL
-                && (kbuf->f_files & 0xffffffff00000000ULL))
-                       return -EOVERFLOW;
-               if (kbuf->f_ffree != 0xffffffffffffffffULL
-                && (kbuf->f_ffree & 0xffffffff00000000ULL))
-                       return -EOVERFLOW;
-       }
-       if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
-           __put_user(kbuf->f_type, &ubuf->f_type) ||
-           __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
-           __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
-           __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
-           __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
-           __put_user(kbuf->f_files, &ubuf->f_files) ||
-           __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
-           __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
-           __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
-           __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
-           __put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
-           __put_user(kbuf->f_flags, &ubuf->f_flags) ||
-           __clear_user(ubuf->f_spare, sizeof(ubuf->f_spare)))
-               return -EFAULT;
-       return 0;
-}
-
-/*
- * The following statfs calls are copies of code from fs/statfs.c and
- * should be checked against those from time to time
- */
-COMPAT_SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct compat_statfs __user *, buf)
-{
-       struct kstatfs tmp;
-       int error = user_statfs(pathname, &tmp);
-       if (!error)
-               error = put_compat_statfs(buf, &tmp);
-       return error;
-}
-
-COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *, buf)
-{
-       struct kstatfs tmp;
-       int error = fd_statfs(fd, &tmp);
-       if (!error)
-               error = put_compat_statfs(buf, &tmp);
-       return error;
-}
-
-static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
-{
-       if (sizeof(ubuf->f_bsize) == 4) {
-               if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen |
-                    kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL)
-                       return -EOVERFLOW;
-               /* f_files and f_ffree may be -1; it's okay
-                * to stuff that into 32 bits */
-               if (kbuf->f_files != 0xffffffffffffffffULL
-                && (kbuf->f_files & 0xffffffff00000000ULL))
-                       return -EOVERFLOW;
-               if (kbuf->f_ffree != 0xffffffffffffffffULL
-                && (kbuf->f_ffree & 0xffffffff00000000ULL))
-                       return -EOVERFLOW;
-       }
-       if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
-           __put_user(kbuf->f_type, &ubuf->f_type) ||
-           __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
-           __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
-           __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
-           __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
-           __put_user(kbuf->f_files, &ubuf->f_files) ||
-           __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
-           __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
-           __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
-           __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
-           __put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
-           __put_user(kbuf->f_flags, &ubuf->f_flags) ||
-           __clear_user(ubuf->f_spare, sizeof(ubuf->f_spare)))
-               return -EFAULT;
-       return 0;
-}
-
-COMPAT_SYSCALL_DEFINE3(statfs64, const char __user *, pathname, compat_size_t, sz, struct compat_statfs64 __user *, buf)
-{
-       struct kstatfs tmp;
-       int error;
-
-       if (sz != sizeof(*buf))
-               return -EINVAL;
-
-       error = user_statfs(pathname, &tmp);
-       if (!error)
-               error = put_compat_statfs64(buf, &tmp);
-       return error;
-}
-
-COMPAT_SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, compat_size_t, sz, struct compat_statfs64 __user *, buf)
-{
-       struct kstatfs tmp;
-       int error;
-
-       if (sz != sizeof(*buf))
-               return -EINVAL;
-
-       error = fd_statfs(fd, &tmp);
-       if (!error)
-               error = put_compat_statfs64(buf, &tmp);
-       return error;
-}
-
-/*
- * This is a copy of sys_ustat, just dealing with a structure layout.
- * Given how simple this syscall is that apporach is more maintainable
- * than the various conversion hacks.
- */
-COMPAT_SYSCALL_DEFINE2(ustat, unsigned, dev, struct compat_ustat __user *, u)
-{
-       struct compat_ustat tmp;
-       struct kstatfs sbuf;
-       int err = vfs_ustat(new_decode_dev(dev), &sbuf);
-       if (err)
-               return err;
-
-       memset(&tmp, 0, sizeof(struct compat_ustat));
-       tmp.f_tfree = sbuf.f_bfree;
-       tmp.f_tinode = sbuf.f_ffree;
-       if (copy_to_user(u, &tmp, sizeof(struct compat_ustat)))
-               return -EFAULT;
-       return 0;
-}
-
 static int get_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
 {
        if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
index 13ae259d48795a782e566b7deaceadc73f86d8c7..4e4623c7a1260eafaf564e87b4812091a9b3eb0e 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/statfs.h>
 #include <linux/security.h>
 #include <linux/uaccess.h>
+#include <linux/compat.h>
 #include "internal.h"
 
 static int flags_by_mnt(int mnt_flags)
@@ -239,3 +240,142 @@ SYSCALL_DEFINE2(ustat, unsigned, dev, struct ustat __user *, ubuf)
 
        return copy_to_user(ubuf, &tmp, sizeof(struct ustat)) ? -EFAULT : 0;
 }
+
+#ifdef CONFIG_COMPAT
+static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf)
+{
+       if (sizeof ubuf->f_blocks == 4) {
+               if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail |
+                    kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
+                       return -EOVERFLOW;
+               /* f_files and f_ffree may be -1; it's okay
+                * to stuff that into 32 bits */
+               if (kbuf->f_files != 0xffffffffffffffffULL
+                && (kbuf->f_files & 0xffffffff00000000ULL))
+                       return -EOVERFLOW;
+               if (kbuf->f_ffree != 0xffffffffffffffffULL
+                && (kbuf->f_ffree & 0xffffffff00000000ULL))
+                       return -EOVERFLOW;
+       }
+       if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
+           __put_user(kbuf->f_type, &ubuf->f_type) ||
+           __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
+           __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
+           __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
+           __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
+           __put_user(kbuf->f_files, &ubuf->f_files) ||
+           __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
+           __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
+           __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
+           __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
+           __put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
+           __put_user(kbuf->f_flags, &ubuf->f_flags) ||
+           __clear_user(ubuf->f_spare, sizeof(ubuf->f_spare)))
+               return -EFAULT;
+       return 0;
+}
+
+/*
+ * The following statfs calls are copies of code from fs/statfs.c and
+ * should be checked against those from time to time
+ */
+COMPAT_SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct compat_statfs __user *, buf)
+{
+       struct kstatfs tmp;
+       int error = user_statfs(pathname, &tmp);
+       if (!error)
+               error = put_compat_statfs(buf, &tmp);
+       return error;
+}
+
+COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *, buf)
+{
+       struct kstatfs tmp;
+       int error = fd_statfs(fd, &tmp);
+       if (!error)
+               error = put_compat_statfs(buf, &tmp);
+       return error;
+}
+
+static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
+{
+       if (sizeof(ubuf->f_bsize) == 4) {
+               if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen |
+                    kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL)
+                       return -EOVERFLOW;
+               /* f_files and f_ffree may be -1; it's okay
+                * to stuff that into 32 bits */
+               if (kbuf->f_files != 0xffffffffffffffffULL
+                && (kbuf->f_files & 0xffffffff00000000ULL))
+                       return -EOVERFLOW;
+               if (kbuf->f_ffree != 0xffffffffffffffffULL
+                && (kbuf->f_ffree & 0xffffffff00000000ULL))
+                       return -EOVERFLOW;
+       }
+       if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
+           __put_user(kbuf->f_type, &ubuf->f_type) ||
+           __put_user(kbuf->f_bsize, &ubuf->f_bsize) ||
+           __put_user(kbuf->f_blocks, &ubuf->f_blocks) ||
+           __put_user(kbuf->f_bfree, &ubuf->f_bfree) ||
+           __put_user(kbuf->f_bavail, &ubuf->f_bavail) ||
+           __put_user(kbuf->f_files, &ubuf->f_files) ||
+           __put_user(kbuf->f_ffree, &ubuf->f_ffree) ||
+           __put_user(kbuf->f_namelen, &ubuf->f_namelen) ||
+           __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
+           __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
+           __put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
+           __put_user(kbuf->f_flags, &ubuf->f_flags) ||
+           __clear_user(ubuf->f_spare, sizeof(ubuf->f_spare)))
+               return -EFAULT;
+       return 0;
+}
+
+COMPAT_SYSCALL_DEFINE3(statfs64, const char __user *, pathname, compat_size_t, sz, struct compat_statfs64 __user *, buf)
+{
+       struct kstatfs tmp;
+       int error;
+
+       if (sz != sizeof(*buf))
+               return -EINVAL;
+
+       error = user_statfs(pathname, &tmp);
+       if (!error)
+               error = put_compat_statfs64(buf, &tmp);
+       return error;
+}
+
+COMPAT_SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, compat_size_t, sz, struct compat_statfs64 __user *, buf)
+{
+       struct kstatfs tmp;
+       int error;
+
+       if (sz != sizeof(*buf))
+               return -EINVAL;
+
+       error = fd_statfs(fd, &tmp);
+       if (!error)
+               error = put_compat_statfs64(buf, &tmp);
+       return error;
+}
+
+/*
+ * This is a copy of sys_ustat, just dealing with a structure layout.
+ * Given how simple this syscall is that apporach is more maintainable
+ * than the various conversion hacks.
+ */
+COMPAT_SYSCALL_DEFINE2(ustat, unsigned, dev, struct compat_ustat __user *, u)
+{
+       struct compat_ustat tmp;
+       struct kstatfs sbuf;
+       int err = vfs_ustat(new_decode_dev(dev), &sbuf);
+       if (err)
+               return err;
+
+       memset(&tmp, 0, sizeof(struct compat_ustat));
+       tmp.f_tfree = sbuf.f_bfree;
+       tmp.f_tinode = sbuf.f_ffree;
+       if (copy_to_user(u, &tmp, sizeof(struct compat_ustat)))
+               return -EFAULT;
+       return 0;
+}
+#endif