Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * Copyright (c) 2004-2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
Christoph Hellwig | 62e194e | 2009-01-19 02:03:03 +0100 | [diff] [blame] | 6 | #include <linux/mount.h> |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 7 | #include <linux/fsmap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include "xfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include "xfs_fs.h" |
Darrick J. Wong | 5467b34 | 2019-06-28 19:25:35 -0700 | [diff] [blame] | 10 | #include "xfs_shared.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 11 | #include "xfs_format.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 12 | #include "xfs_log_format.h" |
| 13 | #include "xfs_trans_resv.h" |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 14 | #include "xfs_mount.h" |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 15 | #include "xfs_inode.h" |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 16 | #include "xfs_iwalk.h" |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 17 | #include "xfs_itable.h" |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 18 | #include "xfs_fsops.h" |
sandeen@sandeen.net | 471d591 | 2008-11-25 21:20:10 -0600 | [diff] [blame] | 19 | #include "xfs_rtalloc.h" |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 20 | #include "xfs_attr.h" |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 21 | #include "xfs_ioctl.h" |
David Chinner | a8272ce | 2007-11-23 16:28:09 +1100 | [diff] [blame] | 22 | #include "xfs_ioctl32.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 23 | #include "xfs_trace.h" |
Darrick J. Wong | c368ebc | 2018-01-08 10:51:27 -0800 | [diff] [blame] | 24 | #include "xfs_sb.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 26 | #define _NATIVE_IOC(cmd, type) \ |
| 27 | _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type)) |
| 28 | |
sandeen@sandeen.net | ffae263 | 2008-11-25 21:20:07 -0600 | [diff] [blame] | 29 | #ifdef BROKEN_X86_ALIGNMENT |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 30 | STATIC int |
| 31 | xfs_compat_flock64_copyin( |
| 32 | xfs_flock64_t *bf, |
| 33 | compat_xfs_flock64_t __user *arg32) |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 34 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 35 | if (get_user(bf->l_type, &arg32->l_type) || |
| 36 | get_user(bf->l_whence, &arg32->l_whence) || |
| 37 | get_user(bf->l_start, &arg32->l_start) || |
| 38 | get_user(bf->l_len, &arg32->l_len) || |
| 39 | get_user(bf->l_sysid, &arg32->l_sysid) || |
| 40 | get_user(bf->l_pid, &arg32->l_pid) || |
| 41 | copy_from_user(bf->l_pad, &arg32->l_pad, 4*sizeof(u32))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 42 | return -EFAULT; |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 43 | return 0; |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 44 | } |
| 45 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 46 | STATIC int |
| 47 | xfs_compat_ioc_fsgeometry_v1( |
| 48 | struct xfs_mount *mp, |
| 49 | compat_xfs_fsop_geom_v1_t __user *arg32) |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 50 | { |
Dave Chinner | 1b6d968 | 2019-04-12 07:41:16 -0700 | [diff] [blame] | 51 | struct xfs_fsop_geom fsgeo; |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 52 | |
Eric Sandeen | 9108326 | 2019-05-01 20:26:30 -0700 | [diff] [blame] | 53 | xfs_fs_geometry(&mp->m_sb, &fsgeo, 3); |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 54 | /* The 32-bit variant simply has some padding at the end */ |
| 55 | if (copy_to_user(arg32, &fsgeo, sizeof(struct compat_xfs_fsop_geom_v1))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 56 | return -EFAULT; |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 57 | return 0; |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 58 | } |
| 59 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 60 | STATIC int |
sandeen@sandeen.net | 471d591 | 2008-11-25 21:20:10 -0600 | [diff] [blame] | 61 | xfs_compat_growfs_data_copyin( |
| 62 | struct xfs_growfs_data *in, |
| 63 | compat_xfs_growfs_data_t __user *arg32) |
| 64 | { |
| 65 | if (get_user(in->newblocks, &arg32->newblocks) || |
| 66 | get_user(in->imaxpct, &arg32->imaxpct)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 67 | return -EFAULT; |
sandeen@sandeen.net | 471d591 | 2008-11-25 21:20:10 -0600 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | STATIC int |
| 72 | xfs_compat_growfs_rt_copyin( |
| 73 | struct xfs_growfs_rt *in, |
| 74 | compat_xfs_growfs_rt_t __user *arg32) |
| 75 | { |
| 76 | if (get_user(in->newblocks, &arg32->newblocks) || |
| 77 | get_user(in->extsize, &arg32->extsize)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 78 | return -EFAULT; |
sandeen@sandeen.net | 471d591 | 2008-11-25 21:20:10 -0600 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | STATIC int |
Darrick J. Wong | 8bfe9d1 | 2019-07-03 20:36:26 -0700 | [diff] [blame] | 83 | xfs_fsinumbers_fmt_compat( |
Darrick J. Wong | 5f19c7f | 2019-07-03 20:36:27 -0700 | [diff] [blame] | 84 | struct xfs_ibulk *breq, |
| 85 | const struct xfs_inumbers *ig) |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 86 | { |
Darrick J. Wong | 5f19c7f | 2019-07-03 20:36:27 -0700 | [diff] [blame] | 87 | struct compat_xfs_inogrp __user *p32 = breq->ubuffer; |
| 88 | struct xfs_inogrp ig1; |
| 89 | struct xfs_inogrp *igrp = &ig1; |
| 90 | |
| 91 | xfs_inumbers_to_inogrp(&ig1, ig); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 92 | |
Darrick J. Wong | 677717f | 2019-07-02 09:39:43 -0700 | [diff] [blame] | 93 | if (put_user(igrp->xi_startino, &p32->xi_startino) || |
| 94 | put_user(igrp->xi_alloccount, &p32->xi_alloccount) || |
| 95 | put_user(igrp->xi_allocmask, &p32->xi_allocmask)) |
| 96 | return -EFAULT; |
| 97 | |
| 98 | return xfs_ibulk_advance(breq, sizeof(struct compat_xfs_inogrp)); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 99 | } |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | #else |
Darrick J. Wong | 8bfe9d1 | 2019-07-03 20:36:26 -0700 | [diff] [blame] | 102 | #define xfs_fsinumbers_fmt_compat xfs_fsinumbers_fmt |
sandeen@sandeen.net | e5d412f | 2008-11-25 21:20:17 -0600 | [diff] [blame] | 103 | #endif /* BROKEN_X86_ALIGNMENT */ |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 104 | |
sandeen@sandeen.net | e94fc4a | 2008-11-25 21:20:09 -0600 | [diff] [blame] | 105 | STATIC int |
| 106 | xfs_ioctl32_bstime_copyin( |
| 107 | xfs_bstime_t *bstime, |
| 108 | compat_xfs_bstime_t __user *bstime32) |
| 109 | { |
| 110 | compat_time_t sec32; /* tv_sec differs on 64 vs. 32 */ |
| 111 | |
| 112 | if (get_user(sec32, &bstime32->tv_sec) || |
| 113 | get_user(bstime->tv_nsec, &bstime32->tv_nsec)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 114 | return -EFAULT; |
sandeen@sandeen.net | e94fc4a | 2008-11-25 21:20:09 -0600 | [diff] [blame] | 115 | bstime->tv_sec = sec32; |
| 116 | return 0; |
| 117 | } |
| 118 | |
Darrick J. Wong | 6f71fb6 | 2019-07-03 20:36:25 -0700 | [diff] [blame] | 119 | /* |
| 120 | * struct xfs_bstat has differing alignment on intel, & bstime_t sizes |
| 121 | * everywhere |
| 122 | */ |
sandeen@sandeen.net | e94fc4a | 2008-11-25 21:20:09 -0600 | [diff] [blame] | 123 | STATIC int |
| 124 | xfs_ioctl32_bstat_copyin( |
Darrick J. Wong | 6f71fb6 | 2019-07-03 20:36:25 -0700 | [diff] [blame] | 125 | struct xfs_bstat *bstat, |
| 126 | struct compat_xfs_bstat __user *bstat32) |
sandeen@sandeen.net | e94fc4a | 2008-11-25 21:20:09 -0600 | [diff] [blame] | 127 | { |
| 128 | if (get_user(bstat->bs_ino, &bstat32->bs_ino) || |
| 129 | get_user(bstat->bs_mode, &bstat32->bs_mode) || |
| 130 | get_user(bstat->bs_nlink, &bstat32->bs_nlink) || |
| 131 | get_user(bstat->bs_uid, &bstat32->bs_uid) || |
| 132 | get_user(bstat->bs_gid, &bstat32->bs_gid) || |
| 133 | get_user(bstat->bs_rdev, &bstat32->bs_rdev) || |
| 134 | get_user(bstat->bs_blksize, &bstat32->bs_blksize) || |
| 135 | get_user(bstat->bs_size, &bstat32->bs_size) || |
| 136 | xfs_ioctl32_bstime_copyin(&bstat->bs_atime, &bstat32->bs_atime) || |
| 137 | xfs_ioctl32_bstime_copyin(&bstat->bs_mtime, &bstat32->bs_mtime) || |
| 138 | xfs_ioctl32_bstime_copyin(&bstat->bs_ctime, &bstat32->bs_ctime) || |
| 139 | get_user(bstat->bs_blocks, &bstat32->bs_size) || |
| 140 | get_user(bstat->bs_xflags, &bstat32->bs_size) || |
| 141 | get_user(bstat->bs_extsize, &bstat32->bs_extsize) || |
| 142 | get_user(bstat->bs_extents, &bstat32->bs_extents) || |
| 143 | get_user(bstat->bs_gen, &bstat32->bs_gen) || |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame] | 144 | get_user(bstat->bs_projid_lo, &bstat32->bs_projid_lo) || |
| 145 | get_user(bstat->bs_projid_hi, &bstat32->bs_projid_hi) || |
Dave Chinner | b1d6cc0 | 2014-10-02 09:17:58 +1000 | [diff] [blame] | 146 | get_user(bstat->bs_forkoff, &bstat32->bs_forkoff) || |
sandeen@sandeen.net | e94fc4a | 2008-11-25 21:20:09 -0600 | [diff] [blame] | 147 | get_user(bstat->bs_dmevmask, &bstat32->bs_dmevmask) || |
| 148 | get_user(bstat->bs_dmstate, &bstat32->bs_dmstate) || |
| 149 | get_user(bstat->bs_aextents, &bstat32->bs_aextents)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 150 | return -EFAULT; |
sandeen@sandeen.net | e94fc4a | 2008-11-25 21:20:09 -0600 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 154 | /* XFS_IOC_FSBULKSTAT and friends */ |
| 155 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 156 | STATIC int |
| 157 | xfs_bstime_store_compat( |
| 158 | compat_xfs_bstime_t __user *p32, |
| 159 | const xfs_bstime_t *p) |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 160 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 161 | __s32 sec32; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 162 | |
| 163 | sec32 = p->tv_sec; |
| 164 | if (put_user(sec32, &p32->tv_sec) || |
| 165 | put_user(p->tv_nsec, &p32->tv_nsec)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 166 | return -EFAULT; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 170 | /* Return 0 on success or positive error (to xfs_bulkstat()) */ |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 171 | STATIC int |
Darrick J. Wong | 8bfe9d1 | 2019-07-03 20:36:26 -0700 | [diff] [blame] | 172 | xfs_fsbulkstat_one_fmt_compat( |
Darrick J. Wong | 7035f97 | 2019-07-03 20:36:26 -0700 | [diff] [blame] | 173 | struct xfs_ibulk *breq, |
| 174 | const struct xfs_bulkstat *bstat) |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 175 | { |
Darrick J. Wong | 7035f97 | 2019-07-03 20:36:26 -0700 | [diff] [blame] | 176 | struct compat_xfs_bstat __user *p32 = breq->ubuffer; |
| 177 | struct xfs_bstat bs1; |
| 178 | struct xfs_bstat *buffer = &bs1; |
| 179 | |
| 180 | xfs_bulkstat_to_bstat(breq->mp, &bs1, bstat); |
sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 181 | |
| 182 | if (put_user(buffer->bs_ino, &p32->bs_ino) || |
| 183 | put_user(buffer->bs_mode, &p32->bs_mode) || |
| 184 | put_user(buffer->bs_nlink, &p32->bs_nlink) || |
| 185 | put_user(buffer->bs_uid, &p32->bs_uid) || |
| 186 | put_user(buffer->bs_gid, &p32->bs_gid) || |
| 187 | put_user(buffer->bs_rdev, &p32->bs_rdev) || |
| 188 | put_user(buffer->bs_blksize, &p32->bs_blksize) || |
| 189 | put_user(buffer->bs_size, &p32->bs_size) || |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 190 | xfs_bstime_store_compat(&p32->bs_atime, &buffer->bs_atime) || |
| 191 | xfs_bstime_store_compat(&p32->bs_mtime, &buffer->bs_mtime) || |
| 192 | xfs_bstime_store_compat(&p32->bs_ctime, &buffer->bs_ctime) || |
sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 193 | put_user(buffer->bs_blocks, &p32->bs_blocks) || |
| 194 | put_user(buffer->bs_xflags, &p32->bs_xflags) || |
| 195 | put_user(buffer->bs_extsize, &p32->bs_extsize) || |
| 196 | put_user(buffer->bs_extents, &p32->bs_extents) || |
| 197 | put_user(buffer->bs_gen, &p32->bs_gen) || |
| 198 | put_user(buffer->bs_projid, &p32->bs_projid) || |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame] | 199 | put_user(buffer->bs_projid_hi, &p32->bs_projid_hi) || |
Dave Chinner | b1d6cc0 | 2014-10-02 09:17:58 +1000 | [diff] [blame] | 200 | put_user(buffer->bs_forkoff, &p32->bs_forkoff) || |
sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 201 | put_user(buffer->bs_dmevmask, &p32->bs_dmevmask) || |
| 202 | put_user(buffer->bs_dmstate, &p32->bs_dmstate) || |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 203 | put_user(buffer->bs_aextents, &p32->bs_aextents)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 204 | return -EFAULT; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 205 | |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 206 | return xfs_ibulk_advance(breq, sizeof(struct compat_xfs_bstat)); |
sandeen@sandeen.net | 2ee4fa5 | 2008-11-25 21:20:11 -0600 | [diff] [blame] | 207 | } |
| 208 | |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 209 | /* copied from xfs_ioctl.c */ |
| 210 | STATIC int |
Darrick J. Wong | 8bfe9d1 | 2019-07-03 20:36:26 -0700 | [diff] [blame] | 211 | xfs_compat_ioc_fsbulkstat( |
sandeen@sandeen.net | 2ee4fa5 | 2008-11-25 21:20:11 -0600 | [diff] [blame] | 212 | xfs_mount_t *mp, |
| 213 | unsigned int cmd, |
Darrick J. Wong | 6f71fb6 | 2019-07-03 20:36:25 -0700 | [diff] [blame] | 214 | struct compat_xfs_fsop_bulkreq __user *p32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | u32 addr; |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 217 | struct xfs_fsop_bulkreq bulkreq; |
| 218 | struct xfs_ibulk breq = { |
| 219 | .mp = mp, |
| 220 | .ocount = 0, |
| 221 | }; |
| 222 | xfs_ino_t lastino; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 223 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Nick Bowler | 7ca860e | 2018-12-17 09:35:27 -0800 | [diff] [blame] | 225 | /* |
| 226 | * Output structure handling functions. Depending on the command, |
| 227 | * either the xfs_bstat and xfs_inogrp structures are written out |
| 228 | * to userpace memory via bulkreq.ubuffer. Normally the compat |
| 229 | * functions and structure size are the correct ones to use ... |
| 230 | */ |
Darrick J. Wong | 8bfe9d1 | 2019-07-03 20:36:26 -0700 | [diff] [blame] | 231 | inumbers_fmt_pf inumbers_func = xfs_fsinumbers_fmt_compat; |
| 232 | bulkstat_one_fmt_pf bs_one_func = xfs_fsbulkstat_one_fmt_compat; |
Nick Bowler | 7ca860e | 2018-12-17 09:35:27 -0800 | [diff] [blame] | 233 | |
| 234 | #ifdef CONFIG_X86_X32 |
| 235 | if (in_x32_syscall()) { |
| 236 | /* |
| 237 | * ... but on x32 the input xfs_fsop_bulkreq has pointers |
| 238 | * which must be handled in the "compat" (32-bit) way, while |
| 239 | * the xfs_bstat and xfs_inogrp structures follow native 64- |
| 240 | * bit layout convention. So adjust accordingly, otherwise |
| 241 | * the data written out in compat layout will not match what |
| 242 | * x32 userspace expects. |
| 243 | */ |
Darrick J. Wong | 8bfe9d1 | 2019-07-03 20:36:26 -0700 | [diff] [blame] | 244 | inumbers_func = xfs_fsinumbers_fmt; |
| 245 | bs_one_func = xfs_fsbulkstat_one_fmt; |
Nick Bowler | 7ca860e | 2018-12-17 09:35:27 -0800 | [diff] [blame] | 246 | } |
| 247 | #endif |
| 248 | |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 249 | /* done = 1 if there are more stats to get and if bulkstat */ |
| 250 | /* should be called again (unused here, but used in dmapi) */ |
| 251 | |
| 252 | if (!capable(CAP_SYS_ADMIN)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 253 | return -EPERM; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 254 | |
| 255 | if (XFS_FORCED_SHUTDOWN(mp)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 256 | return -EIO; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 257 | |
| 258 | if (get_user(addr, &p32->lastip)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 259 | return -EFAULT; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 260 | bulkreq.lastip = compat_ptr(addr); |
| 261 | if (get_user(bulkreq.icount, &p32->icount) || |
| 262 | get_user(addr, &p32->ubuffer)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 263 | return -EFAULT; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 264 | bulkreq.ubuffer = compat_ptr(addr); |
| 265 | if (get_user(addr, &p32->ocount)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 266 | return -EFAULT; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 267 | bulkreq.ocount = compat_ptr(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 269 | if (copy_from_user(&lastino, bulkreq.lastip, sizeof(__s64))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 270 | return -EFAULT; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 271 | |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 272 | if (bulkreq.icount <= 0) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 273 | return -EINVAL; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 274 | |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 275 | if (bulkreq.ubuffer == NULL) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 276 | return -EINVAL; |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 277 | |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 278 | breq.ubuffer = bulkreq.ubuffer; |
| 279 | breq.icount = bulkreq.icount; |
sandeen@sandeen.net | af819d2 | 2008-11-25 21:20:13 -0600 | [diff] [blame] | 280 | |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 281 | /* |
| 282 | * FSBULKSTAT_SINGLE expects that *lastip contains the inode number |
| 283 | * that we want to stat. However, FSINUMBERS and FSBULKSTAT expect |
| 284 | * that *lastip contains either zero or the number of the last inode to |
| 285 | * be examined by the previous call and return results starting with |
| 286 | * the next inode after that. The new bulk request back end functions |
| 287 | * take the inode to start with, so we have to compute the startino |
| 288 | * parameter from lastino to maintain correct function. lastino == 0 |
| 289 | * is a special case because it has traditionally meant "first inode |
| 290 | * in filesystem". |
| 291 | */ |
| 292 | if (cmd == XFS_IOC_FSINUMBERS_32) { |
Darrick J. Wong | 677717f | 2019-07-02 09:39:43 -0700 | [diff] [blame] | 293 | breq.startino = lastino ? lastino + 1 : 0; |
| 294 | error = xfs_inumbers(&breq, inumbers_func); |
| 295 | lastino = breq.startino - 1; |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 296 | } else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE_32) { |
| 297 | breq.startino = lastino; |
| 298 | breq.icount = 1; |
| 299 | error = xfs_bulkstat_one(&breq, bs_one_func); |
| 300 | lastino = breq.startino; |
sandeen@sandeen.net | af819d2 | 2008-11-25 21:20:13 -0600 | [diff] [blame] | 301 | } else if (cmd == XFS_IOC_FSBULKSTAT_32) { |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 302 | breq.startino = lastino ? lastino + 1 : 0; |
| 303 | error = xfs_bulkstat(&breq, bs_one_func); |
| 304 | lastino = breq.startino - 1; |
| 305 | } else { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 306 | error = -EINVAL; |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 307 | } |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 308 | if (error) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 309 | return error; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 310 | |
Darrick J. Wong | f16fe3e | 2019-07-02 09:39:39 -0700 | [diff] [blame] | 311 | if (bulkreq.lastip != NULL && |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 312 | copy_to_user(bulkreq.lastip, &lastino, sizeof(xfs_ino_t))) |
Darrick J. Wong | f16fe3e | 2019-07-02 09:39:39 -0700 | [diff] [blame] | 313 | return -EFAULT; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 314 | |
Darrick J. Wong | f16fe3e | 2019-07-02 09:39:39 -0700 | [diff] [blame] | 315 | if (bulkreq.ocount != NULL && |
Darrick J. Wong | 2810bd6 | 2019-07-02 09:39:40 -0700 | [diff] [blame] | 316 | copy_to_user(bulkreq.ocount, &breq.ocount, sizeof(__s32))) |
Darrick J. Wong | f16fe3e | 2019-07-02 09:39:39 -0700 | [diff] [blame] | 317 | return -EFAULT; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 318 | |
| 319 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 321 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 322 | STATIC int |
| 323 | xfs_compat_handlereq_copyin( |
| 324 | xfs_fsop_handlereq_t *hreq, |
| 325 | compat_xfs_fsop_handlereq_t __user *arg32) |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 326 | { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 327 | compat_xfs_fsop_handlereq_t hreq32; |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 328 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 329 | if (copy_from_user(&hreq32, arg32, sizeof(compat_xfs_fsop_handlereq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 330 | return -EFAULT; |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 331 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 332 | hreq->fd = hreq32.fd; |
| 333 | hreq->path = compat_ptr(hreq32.path); |
| 334 | hreq->oflags = hreq32.oflags; |
| 335 | hreq->ihandle = compat_ptr(hreq32.ihandle); |
| 336 | hreq->ihandlen = hreq32.ihandlen; |
| 337 | hreq->ohandle = compat_ptr(hreq32.ohandle); |
| 338 | hreq->ohandlen = compat_ptr(hreq32.ohandlen); |
| 339 | |
| 340 | return 0; |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 341 | } |
| 342 | |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 343 | STATIC struct dentry * |
| 344 | xfs_compat_handlereq_to_dentry( |
| 345 | struct file *parfilp, |
| 346 | compat_xfs_fsop_handlereq_t *hreq) |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 347 | { |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 348 | return xfs_handle_to_dentry(parfilp, |
| 349 | compat_ptr(hreq->ihandle), hreq->ihandlen); |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | STATIC int |
| 353 | xfs_compat_attrlist_by_handle( |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 354 | struct file *parfilp, |
| 355 | void __user *arg) |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 356 | { |
| 357 | int error; |
| 358 | attrlist_cursor_kern_t *cursor; |
Nick Bowler | c456d64 | 2018-12-17 09:35:27 -0800 | [diff] [blame] | 359 | compat_xfs_fsop_attrlist_handlereq_t __user *p = arg; |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 360 | compat_xfs_fsop_attrlist_handlereq_t al_hreq; |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 361 | struct dentry *dentry; |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 362 | char *kbuf; |
| 363 | |
| 364 | if (!capable(CAP_SYS_ADMIN)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 365 | return -EPERM; |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 366 | if (copy_from_user(&al_hreq, arg, |
| 367 | sizeof(compat_xfs_fsop_attrlist_handlereq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 368 | return -EFAULT; |
Dan Carpenter | 31978b5 | 2013-10-31 21:00:10 +0300 | [diff] [blame] | 369 | if (al_hreq.buflen < sizeof(struct attrlist) || |
Jan Tulak | 4e24761 | 2015-10-12 16:02:56 +1100 | [diff] [blame] | 370 | al_hreq.buflen > XFS_XATTR_LIST_MAX) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 371 | return -EINVAL; |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 372 | |
| 373 | /* |
| 374 | * Reject flags, only allow namespaces. |
| 375 | */ |
| 376 | if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 377 | return -EINVAL; |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 378 | |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 379 | dentry = xfs_compat_handlereq_to_dentry(parfilp, &al_hreq.hreq); |
| 380 | if (IS_ERR(dentry)) |
| 381 | return PTR_ERR(dentry); |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 382 | |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 383 | error = -ENOMEM; |
Dave Chinner | fdd3cce | 2013-09-02 20:53:00 +1000 | [diff] [blame] | 384 | kbuf = kmem_zalloc_large(al_hreq.buflen, KM_SLEEP); |
| 385 | if (!kbuf) |
| 386 | goto out_dput; |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 387 | |
| 388 | cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 389 | error = xfs_attr_list(XFS_I(d_inode(dentry)), kbuf, al_hreq.buflen, |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 390 | al_hreq.flags, cursor); |
| 391 | if (error) |
| 392 | goto out_kfree; |
| 393 | |
Nick Bowler | c456d64 | 2018-12-17 09:35:27 -0800 | [diff] [blame] | 394 | if (copy_to_user(&p->pos, cursor, sizeof(attrlist_cursor_kern_t))) { |
| 395 | error = -EFAULT; |
| 396 | goto out_kfree; |
| 397 | } |
| 398 | |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 399 | if (copy_to_user(compat_ptr(al_hreq.buffer), kbuf, al_hreq.buflen)) |
| 400 | error = -EFAULT; |
| 401 | |
Dave Chinner | fdd3cce | 2013-09-02 20:53:00 +1000 | [diff] [blame] | 402 | out_kfree: |
| 403 | kmem_free(kbuf); |
| 404 | out_dput: |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 405 | dput(dentry); |
| 406 | return error; |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 407 | } |
| 408 | |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 409 | STATIC int |
| 410 | xfs_compat_attrmulti_by_handle( |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 411 | struct file *parfilp, |
| 412 | void __user *arg) |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 413 | { |
| 414 | int error; |
| 415 | compat_xfs_attr_multiop_t *ops; |
| 416 | compat_xfs_fsop_attrmulti_handlereq_t am_hreq; |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 417 | struct dentry *dentry; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 418 | unsigned int i, size; |
Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 419 | unsigned char *attr_name; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 420 | |
| 421 | if (!capable(CAP_SYS_ADMIN)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 422 | return -EPERM; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 423 | if (copy_from_user(&am_hreq, arg, |
| 424 | sizeof(compat_xfs_fsop_attrmulti_handlereq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 425 | return -EFAULT; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 426 | |
Zhitong Wang | fda168c | 2010-03-23 09:51:22 +1100 | [diff] [blame] | 427 | /* overflow check */ |
| 428 | if (am_hreq.opcount >= INT_MAX / sizeof(compat_xfs_attr_multiop_t)) |
| 429 | return -E2BIG; |
| 430 | |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 431 | dentry = xfs_compat_handlereq_to_dentry(parfilp, &am_hreq.hreq); |
| 432 | if (IS_ERR(dentry)) |
| 433 | return PTR_ERR(dentry); |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 434 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 435 | error = -E2BIG; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 436 | size = am_hreq.opcount * sizeof(compat_xfs_attr_multiop_t); |
| 437 | if (!size || size > 16 * PAGE_SIZE) |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 438 | goto out_dput; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 439 | |
Li Zefan | 0e639bd | 2009-04-08 15:08:04 +0800 | [diff] [blame] | 440 | ops = memdup_user(compat_ptr(am_hreq.ops), size); |
| 441 | if (IS_ERR(ops)) { |
Brian Foster | 4d94902 | 2015-01-22 10:04:24 +1100 | [diff] [blame] | 442 | error = PTR_ERR(ops); |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 443 | goto out_dput; |
Li Zefan | 0e639bd | 2009-04-08 15:08:04 +0800 | [diff] [blame] | 444 | } |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 445 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 446 | error = -ENOMEM; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 447 | attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL); |
| 448 | if (!attr_name) |
| 449 | goto out_kfree_ops; |
| 450 | |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 451 | error = 0; |
| 452 | for (i = 0; i < am_hreq.opcount; i++) { |
Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 453 | ops[i].am_error = strncpy_from_user((char *)attr_name, |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 454 | compat_ptr(ops[i].am_attrname), |
| 455 | MAXNAMELEN); |
| 456 | if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 457 | error = -ERANGE; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 458 | if (ops[i].am_error < 0) |
| 459 | break; |
| 460 | |
| 461 | switch (ops[i].am_opcode) { |
| 462 | case ATTR_OP_GET: |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 463 | ops[i].am_error = xfs_attrmulti_attr_get( |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 464 | d_inode(dentry), attr_name, |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 465 | compat_ptr(ops[i].am_attrvalue), |
| 466 | &ops[i].am_length, ops[i].am_flags); |
| 467 | break; |
| 468 | case ATTR_OP_SET: |
Al Viro | a561be7 | 2011-11-23 11:57:51 -0500 | [diff] [blame] | 469 | ops[i].am_error = mnt_want_write_file(parfilp); |
Christoph Hellwig | 62e194e | 2009-01-19 02:03:03 +0100 | [diff] [blame] | 470 | if (ops[i].am_error) |
| 471 | break; |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 472 | ops[i].am_error = xfs_attrmulti_attr_set( |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 473 | d_inode(dentry), attr_name, |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 474 | compat_ptr(ops[i].am_attrvalue), |
| 475 | ops[i].am_length, ops[i].am_flags); |
Al Viro | 2a79f17 | 2011-12-09 08:06:57 -0500 | [diff] [blame] | 476 | mnt_drop_write_file(parfilp); |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 477 | break; |
| 478 | case ATTR_OP_REMOVE: |
Al Viro | a561be7 | 2011-11-23 11:57:51 -0500 | [diff] [blame] | 479 | ops[i].am_error = mnt_want_write_file(parfilp); |
Christoph Hellwig | 62e194e | 2009-01-19 02:03:03 +0100 | [diff] [blame] | 480 | if (ops[i].am_error) |
| 481 | break; |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 482 | ops[i].am_error = xfs_attrmulti_attr_remove( |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 483 | d_inode(dentry), attr_name, |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 484 | ops[i].am_flags); |
Al Viro | 2a79f17 | 2011-12-09 08:06:57 -0500 | [diff] [blame] | 485 | mnt_drop_write_file(parfilp); |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 486 | break; |
| 487 | default: |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 488 | ops[i].am_error = -EINVAL; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
| 492 | if (copy_to_user(compat_ptr(am_hreq.ops), ops, size)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 493 | error = -EFAULT; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 494 | |
| 495 | kfree(attr_name); |
| 496 | out_kfree_ops: |
| 497 | kfree(ops); |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 498 | out_dput: |
| 499 | dput(dentry); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 500 | return error; |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 501 | } |
| 502 | |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 503 | STATIC int |
| 504 | xfs_compat_fssetdm_by_handle( |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 505 | struct file *parfilp, |
| 506 | void __user *arg) |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 507 | { |
| 508 | int error; |
| 509 | struct fsdmidata fsd; |
| 510 | compat_xfs_fsop_setdm_handlereq_t dmhreq; |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 511 | struct dentry *dentry; |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 512 | |
| 513 | if (!capable(CAP_MKNOD)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 514 | return -EPERM; |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 515 | if (copy_from_user(&dmhreq, arg, |
| 516 | sizeof(compat_xfs_fsop_setdm_handlereq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 517 | return -EFAULT; |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 518 | |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 519 | dentry = xfs_compat_handlereq_to_dentry(parfilp, &dmhreq.hreq); |
| 520 | if (IS_ERR(dentry)) |
| 521 | return PTR_ERR(dentry); |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 522 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 523 | if (IS_IMMUTABLE(d_inode(dentry)) || IS_APPEND(d_inode(dentry))) { |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 524 | error = -EPERM; |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 525 | goto out; |
| 526 | } |
| 527 | |
| 528 | if (copy_from_user(&fsd, compat_ptr(dmhreq.data), sizeof(fsd))) { |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 529 | error = -EFAULT; |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 530 | goto out; |
| 531 | } |
| 532 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 533 | error = xfs_set_dmattrs(XFS_I(d_inode(dentry)), fsd.fsd_dmevmask, |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 534 | fsd.fsd_dmstate); |
| 535 | |
| 536 | out: |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 537 | dput(dentry); |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 538 | return error; |
| 539 | } |
| 540 | |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 541 | long |
| 542 | xfs_file_compat_ioctl( |
| 543 | struct file *filp, |
| 544 | unsigned cmd, |
| 545 | unsigned long p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 547 | struct inode *inode = file_inode(filp); |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 548 | struct xfs_inode *ip = XFS_I(inode); |
| 549 | struct xfs_mount *mp = ip->i_mount; |
| 550 | void __user *arg = (void __user *)p; |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 551 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Christoph Hellwig | cca28fb | 2010-06-24 11:57:09 +1000 | [diff] [blame] | 553 | trace_xfs_file_compat_ioctl(ip); |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | switch (cmd) { |
sandeen@sandeen.net | e5d412f | 2008-11-25 21:20:17 -0600 | [diff] [blame] | 556 | /* No size or alignment issues on any arch */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | case XFS_IOC_DIOINFO: |
Dave Chinner | 1b6d968 | 2019-04-12 07:41:16 -0700 | [diff] [blame] | 558 | case XFS_IOC_FSGEOMETRY_V4: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | case XFS_IOC_FSGEOMETRY: |
Darrick J. Wong | 7cd5006 | 2019-04-12 07:41:17 -0700 | [diff] [blame] | 560 | case XFS_IOC_AG_GEOMETRY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | case XFS_IOC_FSGETXATTR: |
| 562 | case XFS_IOC_FSSETXATTR: |
| 563 | case XFS_IOC_FSGETXATTRA: |
| 564 | case XFS_IOC_FSSETDM: |
| 565 | case XFS_IOC_GETBMAP: |
| 566 | case XFS_IOC_GETBMAPA: |
| 567 | case XFS_IOC_GETBMAPX: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | case XFS_IOC_FSCOUNTS: |
| 569 | case XFS_IOC_SET_RESBLKS: |
| 570 | case XFS_IOC_GET_RESBLKS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | case XFS_IOC_FSGROWFSLOG: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | case XFS_IOC_GOINGDOWN: |
| 573 | case XFS_IOC_ERROR_INJECTION: |
| 574 | case XFS_IOC_ERROR_CLEARALL: |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 575 | case FS_IOC_GETFSMAP: |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 576 | case XFS_IOC_SCRUB_METADATA: |
Darrick J. Wong | 0448b6f | 2019-07-03 20:36:27 -0700 | [diff] [blame] | 577 | case XFS_IOC_BULKSTAT: |
Darrick J. Wong | fba9760 | 2019-07-03 20:36:28 -0700 | [diff] [blame] | 578 | case XFS_IOC_INUMBERS: |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 579 | return xfs_file_ioctl(filp, cmd, p); |
Nick Bowler | a9d25bd | 2018-12-17 09:35:27 -0800 | [diff] [blame] | 580 | #if !defined(BROKEN_X86_ALIGNMENT) || defined(CONFIG_X86_X32) |
| 581 | /* |
| 582 | * These are handled fine if no alignment issues. To support x32 |
| 583 | * which uses native 64-bit alignment we must emit these cases in |
| 584 | * addition to the ia-32 compat set below. |
| 585 | */ |
sandeen@sandeen.net | e5d412f | 2008-11-25 21:20:17 -0600 | [diff] [blame] | 586 | case XFS_IOC_ALLOCSP: |
| 587 | case XFS_IOC_FREESP: |
| 588 | case XFS_IOC_RESVSP: |
| 589 | case XFS_IOC_UNRESVSP: |
| 590 | case XFS_IOC_ALLOCSP64: |
| 591 | case XFS_IOC_FREESP64: |
| 592 | case XFS_IOC_RESVSP64: |
| 593 | case XFS_IOC_UNRESVSP64: |
| 594 | case XFS_IOC_FSGEOMETRY_V1: |
| 595 | case XFS_IOC_FSGROWFSDATA: |
| 596 | case XFS_IOC_FSGROWFSRT: |
Dave Chinner | 4472235 | 2010-08-24 12:02:11 +1000 | [diff] [blame] | 597 | case XFS_IOC_ZERO_RANGE: |
Nick Bowler | a9d25bd | 2018-12-17 09:35:27 -0800 | [diff] [blame] | 598 | #ifdef CONFIG_X86_X32 |
| 599 | /* |
| 600 | * x32 special: this gets a different cmd number from the ia-32 compat |
| 601 | * case below; the associated data will match native 64-bit alignment. |
| 602 | */ |
| 603 | case XFS_IOC_SWAPEXT: |
| 604 | #endif |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 605 | return xfs_file_ioctl(filp, cmd, p); |
Nick Bowler | a9d25bd | 2018-12-17 09:35:27 -0800 | [diff] [blame] | 606 | #endif |
| 607 | #if defined(BROKEN_X86_ALIGNMENT) |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 608 | case XFS_IOC_ALLOCSP_32: |
| 609 | case XFS_IOC_FREESP_32: |
| 610 | case XFS_IOC_ALLOCSP64_32: |
| 611 | case XFS_IOC_FREESP64_32: |
| 612 | case XFS_IOC_RESVSP_32: |
| 613 | case XFS_IOC_UNRESVSP_32: |
| 614 | case XFS_IOC_RESVSP64_32: |
Christoph Hellwig | 8c1fdd0 | 2011-04-21 13:21:03 +0000 | [diff] [blame] | 615 | case XFS_IOC_UNRESVSP64_32: |
| 616 | case XFS_IOC_ZERO_RANGE_32: { |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 617 | struct xfs_flock64 bf; |
| 618 | |
| 619 | if (xfs_compat_flock64_copyin(&bf, arg)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 620 | return -EFAULT; |
Eric Sandeen | 526c420 | 2005-09-05 08:25:06 +1000 | [diff] [blame] | 621 | cmd = _NATIVE_IOC(cmd, struct xfs_flock64); |
Christoph Hellwig | 8f3e205 | 2016-07-20 11:29:35 +1000 | [diff] [blame] | 622 | return xfs_ioc_space(filp, cmd, &bf); |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 623 | } |
Michal Marek | 547e00c | 2007-07-11 11:09:57 +1000 | [diff] [blame] | 624 | case XFS_IOC_FSGEOMETRY_V1_32: |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 625 | return xfs_compat_ioc_fsgeometry_v1(mp, arg); |
sandeen@sandeen.net | 471d591 | 2008-11-25 21:20:10 -0600 | [diff] [blame] | 626 | case XFS_IOC_FSGROWFSDATA_32: { |
| 627 | struct xfs_growfs_data in; |
| 628 | |
| 629 | if (xfs_compat_growfs_data_copyin(&in, arg)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 630 | return -EFAULT; |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 631 | error = mnt_want_write_file(filp); |
| 632 | if (error) |
| 633 | return error; |
sandeen@sandeen.net | 471d591 | 2008-11-25 21:20:10 -0600 | [diff] [blame] | 634 | error = xfs_growfs_data(mp, &in); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 635 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 636 | return error; |
sandeen@sandeen.net | 471d591 | 2008-11-25 21:20:10 -0600 | [diff] [blame] | 637 | } |
| 638 | case XFS_IOC_FSGROWFSRT_32: { |
| 639 | struct xfs_growfs_rt in; |
| 640 | |
| 641 | if (xfs_compat_growfs_rt_copyin(&in, arg)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 642 | return -EFAULT; |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 643 | error = mnt_want_write_file(filp); |
| 644 | if (error) |
| 645 | return error; |
sandeen@sandeen.net | 471d591 | 2008-11-25 21:20:10 -0600 | [diff] [blame] | 646 | error = xfs_growfs_rt(mp, &in); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 647 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 648 | return error; |
sandeen@sandeen.net | 471d591 | 2008-11-25 21:20:10 -0600 | [diff] [blame] | 649 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | #endif |
sandeen@sandeen.net | e5d412f | 2008-11-25 21:20:17 -0600 | [diff] [blame] | 651 | /* long changes size, but xfs only copiese out 32 bits */ |
| 652 | case XFS_IOC_GETXFLAGS_32: |
| 653 | case XFS_IOC_SETXFLAGS_32: |
| 654 | case XFS_IOC_GETVERSION_32: |
| 655 | cmd = _NATIVE_IOC(cmd, long); |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 656 | return xfs_file_ioctl(filp, cmd, p); |
Christoph Hellwig | 3725867 | 2009-09-01 14:03:08 -0400 | [diff] [blame] | 657 | case XFS_IOC_SWAPEXT_32: { |
sandeen@sandeen.net | e5d412f | 2008-11-25 21:20:17 -0600 | [diff] [blame] | 658 | struct xfs_swapext sxp; |
| 659 | struct compat_xfs_swapext __user *sxu = arg; |
| 660 | |
| 661 | /* Bulk copy in up to the sx_stat field, then copy bstat */ |
| 662 | if (copy_from_user(&sxp, sxu, |
| 663 | offsetof(struct xfs_swapext, sx_stat)) || |
| 664 | xfs_ioctl32_bstat_copyin(&sxp.sx_stat, &sxu->sx_stat)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 665 | return -EFAULT; |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 666 | error = mnt_want_write_file(filp); |
| 667 | if (error) |
| 668 | return error; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 669 | error = xfs_ioc_swapext(&sxp); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 670 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 671 | return error; |
sandeen@sandeen.net | e5d412f | 2008-11-25 21:20:17 -0600 | [diff] [blame] | 672 | } |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 673 | case XFS_IOC_FSBULKSTAT_32: |
| 674 | case XFS_IOC_FSBULKSTAT_SINGLE_32: |
| 675 | case XFS_IOC_FSINUMBERS_32: |
Darrick J. Wong | 8bfe9d1 | 2019-07-03 20:36:26 -0700 | [diff] [blame] | 676 | return xfs_compat_ioc_fsbulkstat(mp, cmd, arg); |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 677 | case XFS_IOC_FD_TO_HANDLE_32: |
| 678 | case XFS_IOC_PATH_TO_HANDLE_32: |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 679 | case XFS_IOC_PATH_TO_FSHANDLE_32: { |
| 680 | struct xfs_fsop_handlereq hreq; |
| 681 | |
| 682 | if (xfs_compat_handlereq_copyin(&hreq, arg)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 683 | return -EFAULT; |
Michal Marek | 1fa503d | 2007-07-11 11:10:09 +1000 | [diff] [blame] | 684 | cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq); |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 685 | return xfs_find_handle(cmd, &hreq); |
| 686 | } |
| 687 | case XFS_IOC_OPEN_BY_HANDLE_32: { |
| 688 | struct xfs_fsop_handlereq hreq; |
| 689 | |
| 690 | if (xfs_compat_handlereq_copyin(&hreq, arg)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 691 | return -EFAULT; |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 692 | return xfs_open_by_handle(filp, &hreq); |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 693 | } |
| 694 | case XFS_IOC_READLINK_BY_HANDLE_32: { |
| 695 | struct xfs_fsop_handlereq hreq; |
| 696 | |
| 697 | if (xfs_compat_handlereq_copyin(&hreq, arg)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 698 | return -EFAULT; |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 699 | return xfs_readlink_by_handle(filp, &hreq); |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 700 | } |
sandeen@sandeen.net | ebeecd2 | 2008-11-25 21:20:14 -0600 | [diff] [blame] | 701 | case XFS_IOC_ATTRLIST_BY_HANDLE_32: |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 702 | return xfs_compat_attrlist_by_handle(filp, arg); |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 703 | case XFS_IOC_ATTRMULTI_BY_HANDLE_32: |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 704 | return xfs_compat_attrmulti_by_handle(filp, arg); |
sandeen@sandeen.net | 710d62a | 2008-11-25 21:20:16 -0600 | [diff] [blame] | 705 | case XFS_IOC_FSSETDM_BY_HANDLE_32: |
Christoph Hellwig | ab596ad | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 706 | return xfs_compat_fssetdm_by_handle(filp, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | default: |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 708 | return -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |