Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 2 | #include <linux/syscalls.h> |
Paul Gortmaker | 630d9c4 | 2011-11-16 23:57:37 -0500 | [diff] [blame] | 3 | #include <linux/export.h> |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 4 | #include <linux/fs.h> |
| 5 | #include <linux/file.h> |
Christoph Hellwig | 365b181 | 2010-07-07 18:53:25 +0200 | [diff] [blame] | 6 | #include <linux/mount.h> |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 7 | #include <linux/namei.h> |
| 8 | #include <linux/statfs.h> |
| 9 | #include <linux/security.h> |
| 10 | #include <linux/uaccess.h> |
Al Viro | 4ada54e | 2017-04-08 18:08:15 -0400 | [diff] [blame] | 11 | #include <linux/compat.h> |
Al Viro | cf31e70 | 2012-01-02 22:28:36 -0500 | [diff] [blame] | 12 | #include "internal.h" |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 13 | |
Christoph Hellwig | 365b181 | 2010-07-07 18:53:25 +0200 | [diff] [blame] | 14 | static int flags_by_mnt(int mnt_flags) |
| 15 | { |
| 16 | int flags = 0; |
| 17 | |
| 18 | if (mnt_flags & MNT_READONLY) |
| 19 | flags |= ST_RDONLY; |
| 20 | if (mnt_flags & MNT_NOSUID) |
| 21 | flags |= ST_NOSUID; |
| 22 | if (mnt_flags & MNT_NODEV) |
| 23 | flags |= ST_NODEV; |
| 24 | if (mnt_flags & MNT_NOEXEC) |
| 25 | flags |= ST_NOEXEC; |
| 26 | if (mnt_flags & MNT_NOATIME) |
| 27 | flags |= ST_NOATIME; |
| 28 | if (mnt_flags & MNT_NODIRATIME) |
| 29 | flags |= ST_NODIRATIME; |
| 30 | if (mnt_flags & MNT_RELATIME) |
| 31 | flags |= ST_RELATIME; |
Mattias Nissler | dab741e0 | 2020-08-27 11:09:46 -0600 | [diff] [blame] | 32 | if (mnt_flags & MNT_NOSYMFOLLOW) |
| 33 | flags |= ST_NOSYMFOLLOW; |
Christoph Hellwig | 365b181 | 2010-07-07 18:53:25 +0200 | [diff] [blame] | 34 | return flags; |
| 35 | } |
| 36 | |
| 37 | static int flags_by_sb(int s_flags) |
| 38 | { |
| 39 | int flags = 0; |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 40 | if (s_flags & SB_SYNCHRONOUS) |
Christoph Hellwig | 365b181 | 2010-07-07 18:53:25 +0200 | [diff] [blame] | 41 | flags |= ST_SYNCHRONOUS; |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 42 | if (s_flags & SB_MANDLOCK) |
Christoph Hellwig | 365b181 | 2010-07-07 18:53:25 +0200 | [diff] [blame] | 43 | flags |= ST_MANDLOCK; |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 44 | if (s_flags & SB_RDONLY) |
Carlos Maiolino | a8e2b63 | 2017-06-29 11:25:40 +0200 | [diff] [blame] | 45 | flags |= ST_RDONLY; |
Christoph Hellwig | 365b181 | 2010-07-07 18:53:25 +0200 | [diff] [blame] | 46 | return flags; |
| 47 | } |
| 48 | |
| 49 | static int calculate_f_flags(struct vfsmount *mnt) |
| 50 | { |
| 51 | return ST_VALID | flags_by_mnt(mnt->mnt_flags) | |
| 52 | flags_by_sb(mnt->mnt_sb->s_flags); |
| 53 | } |
| 54 | |
Al Viro | cf31e70 | 2012-01-02 22:28:36 -0500 | [diff] [blame] | 55 | static int statfs_by_dentry(struct dentry *dentry, struct kstatfs *buf) |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 56 | { |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 57 | int retval; |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 58 | |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 59 | if (!dentry->d_sb->s_op->statfs) |
| 60 | return -ENOSYS; |
| 61 | |
| 62 | memset(buf, 0, sizeof(*buf)); |
| 63 | retval = security_sb_statfs(dentry); |
| 64 | if (retval) |
| 65 | return retval; |
| 66 | retval = dentry->d_sb->s_op->statfs(dentry, buf); |
| 67 | if (retval == 0 && buf->f_frsize == 0) |
| 68 | buf->f_frsize = buf->f_bsize; |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 69 | return retval; |
| 70 | } |
| 71 | |
Amir Goldstein | ec86ff5 | 2019-01-10 19:04:38 +0200 | [diff] [blame] | 72 | int vfs_get_fsid(struct dentry *dentry, __kernel_fsid_t *fsid) |
| 73 | { |
| 74 | struct kstatfs st; |
| 75 | int error; |
| 76 | |
| 77 | error = statfs_by_dentry(dentry, &st); |
| 78 | if (error) |
| 79 | return error; |
| 80 | |
| 81 | *fsid = st.f_fsid; |
| 82 | return 0; |
| 83 | } |
| 84 | EXPORT_SYMBOL(vfs_get_fsid); |
| 85 | |
Al Viro | f0bb5aa | 2016-11-20 20:27:12 -0500 | [diff] [blame] | 86 | int vfs_statfs(const struct path *path, struct kstatfs *buf) |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 87 | { |
Christoph Hellwig | 365b181 | 2010-07-07 18:53:25 +0200 | [diff] [blame] | 88 | int error; |
| 89 | |
| 90 | error = statfs_by_dentry(path->dentry, buf); |
| 91 | if (!error) |
| 92 | buf->f_flags = calculate_f_flags(path->mnt); |
| 93 | return error; |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 94 | } |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 95 | EXPORT_SYMBOL(vfs_statfs); |
| 96 | |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 97 | int user_statfs(const char __user *pathname, struct kstatfs *st) |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 98 | { |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 99 | struct path path; |
Jeff Layton | 96948fc | 2012-12-11 12:10:14 -0500 | [diff] [blame] | 100 | int error; |
| 101 | unsigned int lookup_flags = LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT; |
| 102 | retry: |
| 103 | error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 104 | if (!error) { |
| 105 | error = vfs_statfs(&path, st); |
| 106 | path_put(&path); |
Jeff Layton | 96948fc | 2012-12-11 12:10:14 -0500 | [diff] [blame] | 107 | if (retry_estale(error, lookup_flags)) { |
| 108 | lookup_flags |= LOOKUP_REVAL; |
| 109 | goto retry; |
| 110 | } |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 111 | } |
| 112 | return error; |
| 113 | } |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 114 | |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 115 | int fd_statfs(int fd, struct kstatfs *st) |
| 116 | { |
Linus Torvalds | 9d05746 | 2013-09-30 08:35:10 -0700 | [diff] [blame] | 117 | struct fd f = fdget_raw(fd); |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 118 | int error = -EBADF; |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 119 | if (f.file) { |
| 120 | error = vfs_statfs(&f.file->f_path, st); |
| 121 | fdput(f); |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 122 | } |
| 123 | return error; |
| 124 | } |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 125 | |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 126 | static int do_statfs_native(struct kstatfs *st, struct statfs __user *p) |
| 127 | { |
| 128 | struct statfs buf; |
| 129 | |
| 130 | if (sizeof(buf) == sizeof(*st)) |
| 131 | memcpy(&buf, st, sizeof(*st)); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 132 | else { |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 133 | if (sizeof buf.f_blocks == 4) { |
| 134 | if ((st->f_blocks | st->f_bfree | st->f_bavail | |
| 135 | st->f_bsize | st->f_frsize) & |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 136 | 0xffffffff00000000ULL) |
| 137 | return -EOVERFLOW; |
| 138 | /* |
| 139 | * f_files and f_ffree may be -1; it's okay to stuff |
| 140 | * that into 32 bits |
| 141 | */ |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 142 | if (st->f_files != -1 && |
| 143 | (st->f_files & 0xffffffff00000000ULL)) |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 144 | return -EOVERFLOW; |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 145 | if (st->f_ffree != -1 && |
| 146 | (st->f_ffree & 0xffffffff00000000ULL)) |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 147 | return -EOVERFLOW; |
| 148 | } |
| 149 | |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 150 | buf.f_type = st->f_type; |
| 151 | buf.f_bsize = st->f_bsize; |
| 152 | buf.f_blocks = st->f_blocks; |
| 153 | buf.f_bfree = st->f_bfree; |
| 154 | buf.f_bavail = st->f_bavail; |
| 155 | buf.f_files = st->f_files; |
| 156 | buf.f_ffree = st->f_ffree; |
| 157 | buf.f_fsid = st->f_fsid; |
| 158 | buf.f_namelen = st->f_namelen; |
| 159 | buf.f_frsize = st->f_frsize; |
| 160 | buf.f_flags = st->f_flags; |
| 161 | memset(buf.f_spare, 0, sizeof(buf.f_spare)); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 162 | } |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 163 | if (copy_to_user(p, &buf, sizeof(buf))) |
| 164 | return -EFAULT; |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 168 | static int do_statfs64(struct kstatfs *st, struct statfs64 __user *p) |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 169 | { |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 170 | struct statfs64 buf; |
| 171 | if (sizeof(buf) == sizeof(*st)) |
| 172 | memcpy(&buf, st, sizeof(*st)); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 173 | else { |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 174 | buf.f_type = st->f_type; |
| 175 | buf.f_bsize = st->f_bsize; |
| 176 | buf.f_blocks = st->f_blocks; |
| 177 | buf.f_bfree = st->f_bfree; |
| 178 | buf.f_bavail = st->f_bavail; |
| 179 | buf.f_files = st->f_files; |
| 180 | buf.f_ffree = st->f_ffree; |
| 181 | buf.f_fsid = st->f_fsid; |
| 182 | buf.f_namelen = st->f_namelen; |
| 183 | buf.f_frsize = st->f_frsize; |
| 184 | buf.f_flags = st->f_flags; |
| 185 | memset(buf.f_spare, 0, sizeof(buf.f_spare)); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 186 | } |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 187 | if (copy_to_user(p, &buf, sizeof(buf))) |
| 188 | return -EFAULT; |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct statfs __user *, buf) |
| 193 | { |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 194 | struct kstatfs st; |
| 195 | int error = user_statfs(pathname, &st); |
| 196 | if (!error) |
| 197 | error = do_statfs_native(&st, buf); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 198 | return error; |
| 199 | } |
| 200 | |
| 201 | SYSCALL_DEFINE3(statfs64, const char __user *, pathname, size_t, sz, struct statfs64 __user *, buf) |
| 202 | { |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 203 | struct kstatfs st; |
| 204 | int error; |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 205 | if (sz != sizeof(*buf)) |
| 206 | return -EINVAL; |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 207 | error = user_statfs(pathname, &st); |
| 208 | if (!error) |
| 209 | error = do_statfs64(&st, buf); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 210 | return error; |
| 211 | } |
| 212 | |
| 213 | SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct statfs __user *, buf) |
| 214 | { |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 215 | struct kstatfs st; |
| 216 | int error = fd_statfs(fd, &st); |
| 217 | if (!error) |
| 218 | error = do_statfs_native(&st, buf); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 219 | return error; |
| 220 | } |
| 221 | |
| 222 | SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, size_t, sz, struct statfs64 __user *, buf) |
| 223 | { |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 224 | struct kstatfs st; |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 225 | int error; |
| 226 | |
| 227 | if (sz != sizeof(*buf)) |
| 228 | return -EINVAL; |
| 229 | |
Al Viro | c8b91ac | 2011-03-12 10:41:39 -0500 | [diff] [blame] | 230 | error = fd_statfs(fd, &st); |
| 231 | if (!error) |
| 232 | error = do_statfs64(&st, buf); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 233 | return error; |
| 234 | } |
| 235 | |
Al Viro | 53fd88ab6 | 2017-10-14 23:00:54 -0400 | [diff] [blame] | 236 | static int vfs_ustat(dev_t dev, struct kstatfs *sbuf) |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 237 | { |
Al Viro | cf31e70 | 2012-01-02 22:28:36 -0500 | [diff] [blame] | 238 | struct super_block *s = user_get_super(dev); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 239 | int err; |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 240 | if (!s) |
| 241 | return -EINVAL; |
| 242 | |
Al Viro | cf31e70 | 2012-01-02 22:28:36 -0500 | [diff] [blame] | 243 | err = statfs_by_dentry(s->s_root, sbuf); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 244 | drop_super(s); |
Al Viro | cf31e70 | 2012-01-02 22:28:36 -0500 | [diff] [blame] | 245 | return err; |
| 246 | } |
| 247 | |
| 248 | SYSCALL_DEFINE2(ustat, unsigned, dev, struct ustat __user *, ubuf) |
| 249 | { |
| 250 | struct ustat tmp; |
| 251 | struct kstatfs sbuf; |
| 252 | int err = vfs_ustat(new_decode_dev(dev), &sbuf); |
Al Viro | 7ed1ee6 | 2010-03-23 10:37:36 -0400 | [diff] [blame] | 253 | if (err) |
| 254 | return err; |
| 255 | |
| 256 | memset(&tmp,0,sizeof(struct ustat)); |
| 257 | tmp.f_tfree = sbuf.f_bfree; |
| 258 | tmp.f_tinode = sbuf.f_ffree; |
| 259 | |
| 260 | return copy_to_user(ubuf, &tmp, sizeof(struct ustat)) ? -EFAULT : 0; |
| 261 | } |
Al Viro | 4ada54e | 2017-04-08 18:08:15 -0400 | [diff] [blame] | 262 | |
| 263 | #ifdef CONFIG_COMPAT |
| 264 | static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf) |
| 265 | { |
Al Viro | ae2a9762 | 2017-06-03 21:41:51 -0400 | [diff] [blame] | 266 | struct compat_statfs buf; |
Al Viro | 4ada54e | 2017-04-08 18:08:15 -0400 | [diff] [blame] | 267 | if (sizeof ubuf->f_blocks == 4) { |
| 268 | if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail | |
| 269 | kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL) |
| 270 | return -EOVERFLOW; |
| 271 | /* f_files and f_ffree may be -1; it's okay |
| 272 | * to stuff that into 32 bits */ |
| 273 | if (kbuf->f_files != 0xffffffffffffffffULL |
| 274 | && (kbuf->f_files & 0xffffffff00000000ULL)) |
| 275 | return -EOVERFLOW; |
| 276 | if (kbuf->f_ffree != 0xffffffffffffffffULL |
| 277 | && (kbuf->f_ffree & 0xffffffff00000000ULL)) |
| 278 | return -EOVERFLOW; |
| 279 | } |
Al Viro | ae2a9762 | 2017-06-03 21:41:51 -0400 | [diff] [blame] | 280 | memset(&buf, 0, sizeof(struct compat_statfs)); |
| 281 | buf.f_type = kbuf->f_type; |
| 282 | buf.f_bsize = kbuf->f_bsize; |
| 283 | buf.f_blocks = kbuf->f_blocks; |
| 284 | buf.f_bfree = kbuf->f_bfree; |
| 285 | buf.f_bavail = kbuf->f_bavail; |
| 286 | buf.f_files = kbuf->f_files; |
| 287 | buf.f_ffree = kbuf->f_ffree; |
| 288 | buf.f_namelen = kbuf->f_namelen; |
| 289 | buf.f_fsid.val[0] = kbuf->f_fsid.val[0]; |
| 290 | buf.f_fsid.val[1] = kbuf->f_fsid.val[1]; |
| 291 | buf.f_frsize = kbuf->f_frsize; |
| 292 | buf.f_flags = kbuf->f_flags; |
| 293 | if (copy_to_user(ubuf, &buf, sizeof(struct compat_statfs))) |
Al Viro | 4ada54e | 2017-04-08 18:08:15 -0400 | [diff] [blame] | 294 | return -EFAULT; |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * The following statfs calls are copies of code from fs/statfs.c and |
| 300 | * should be checked against those from time to time |
| 301 | */ |
| 302 | COMPAT_SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct compat_statfs __user *, buf) |
| 303 | { |
| 304 | struct kstatfs tmp; |
| 305 | int error = user_statfs(pathname, &tmp); |
| 306 | if (!error) |
| 307 | error = put_compat_statfs(buf, &tmp); |
| 308 | return error; |
| 309 | } |
| 310 | |
| 311 | COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *, buf) |
| 312 | { |
| 313 | struct kstatfs tmp; |
| 314 | int error = fd_statfs(fd, &tmp); |
| 315 | if (!error) |
| 316 | error = put_compat_statfs(buf, &tmp); |
| 317 | return error; |
| 318 | } |
| 319 | |
| 320 | static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf) |
| 321 | { |
Al Viro | ae2a9762 | 2017-06-03 21:41:51 -0400 | [diff] [blame] | 322 | struct compat_statfs64 buf; |
Eric Sandeen | cc3a7bf | 2019-10-02 16:17:54 -0500 | [diff] [blame] | 323 | |
| 324 | if ((kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL) |
| 325 | return -EOVERFLOW; |
| 326 | |
Al Viro | ae2a9762 | 2017-06-03 21:41:51 -0400 | [diff] [blame] | 327 | memset(&buf, 0, sizeof(struct compat_statfs64)); |
| 328 | buf.f_type = kbuf->f_type; |
| 329 | buf.f_bsize = kbuf->f_bsize; |
| 330 | buf.f_blocks = kbuf->f_blocks; |
| 331 | buf.f_bfree = kbuf->f_bfree; |
| 332 | buf.f_bavail = kbuf->f_bavail; |
| 333 | buf.f_files = kbuf->f_files; |
| 334 | buf.f_ffree = kbuf->f_ffree; |
| 335 | buf.f_namelen = kbuf->f_namelen; |
| 336 | buf.f_fsid.val[0] = kbuf->f_fsid.val[0]; |
| 337 | buf.f_fsid.val[1] = kbuf->f_fsid.val[1]; |
| 338 | buf.f_frsize = kbuf->f_frsize; |
| 339 | buf.f_flags = kbuf->f_flags; |
| 340 | if (copy_to_user(ubuf, &buf, sizeof(struct compat_statfs64))) |
Al Viro | 4ada54e | 2017-04-08 18:08:15 -0400 | [diff] [blame] | 341 | return -EFAULT; |
| 342 | return 0; |
| 343 | } |
| 344 | |
Mark Rutland | 9b54bf9 | 2018-07-11 14:56:51 +0100 | [diff] [blame] | 345 | int kcompat_sys_statfs64(const char __user * pathname, compat_size_t sz, struct compat_statfs64 __user * buf) |
Al Viro | 4ada54e | 2017-04-08 18:08:15 -0400 | [diff] [blame] | 346 | { |
| 347 | struct kstatfs tmp; |
| 348 | int error; |
| 349 | |
| 350 | if (sz != sizeof(*buf)) |
| 351 | return -EINVAL; |
| 352 | |
| 353 | error = user_statfs(pathname, &tmp); |
| 354 | if (!error) |
| 355 | error = put_compat_statfs64(buf, &tmp); |
| 356 | return error; |
| 357 | } |
| 358 | |
Mark Rutland | 9b54bf9 | 2018-07-11 14:56:51 +0100 | [diff] [blame] | 359 | COMPAT_SYSCALL_DEFINE3(statfs64, const char __user *, pathname, compat_size_t, sz, struct compat_statfs64 __user *, buf) |
| 360 | { |
| 361 | return kcompat_sys_statfs64(pathname, sz, buf); |
| 362 | } |
| 363 | |
| 364 | int kcompat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user * buf) |
Al Viro | 4ada54e | 2017-04-08 18:08:15 -0400 | [diff] [blame] | 365 | { |
| 366 | struct kstatfs tmp; |
| 367 | int error; |
| 368 | |
| 369 | if (sz != sizeof(*buf)) |
| 370 | return -EINVAL; |
| 371 | |
| 372 | error = fd_statfs(fd, &tmp); |
| 373 | if (!error) |
| 374 | error = put_compat_statfs64(buf, &tmp); |
| 375 | return error; |
| 376 | } |
| 377 | |
Mark Rutland | 9b54bf9 | 2018-07-11 14:56:51 +0100 | [diff] [blame] | 378 | COMPAT_SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, compat_size_t, sz, struct compat_statfs64 __user *, buf) |
| 379 | { |
| 380 | return kcompat_sys_fstatfs64(fd, sz, buf); |
| 381 | } |
| 382 | |
Al Viro | 4ada54e | 2017-04-08 18:08:15 -0400 | [diff] [blame] | 383 | /* |
| 384 | * This is a copy of sys_ustat, just dealing with a structure layout. |
| 385 | * Given how simple this syscall is that apporach is more maintainable |
| 386 | * than the various conversion hacks. |
| 387 | */ |
| 388 | COMPAT_SYSCALL_DEFINE2(ustat, unsigned, dev, struct compat_ustat __user *, u) |
| 389 | { |
| 390 | struct compat_ustat tmp; |
| 391 | struct kstatfs sbuf; |
| 392 | int err = vfs_ustat(new_decode_dev(dev), &sbuf); |
| 393 | if (err) |
| 394 | return err; |
| 395 | |
| 396 | memset(&tmp, 0, sizeof(struct compat_ustat)); |
| 397 | tmp.f_tfree = sbuf.f_bfree; |
| 398 | tmp.f_tinode = sbuf.f_ffree; |
| 399 | if (copy_to_user(u, &tmp, sizeof(struct compat_ustat))) |
| 400 | return -EFAULT; |
| 401 | return 0; |
| 402 | } |
| 403 | #endif |