]>
Commit | Line | Data |
---|---|---|
0b61f8a4 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* |
7b718769 NS |
3 | * Copyright (c) 2004-2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
1da177e4 | 5 | */ |
1da177e4 | 6 | #include <linux/compat.h> |
1da177e4 | 7 | #include <linux/ioctl.h> |
62e194ec | 8 | #include <linux/mount.h> |
5a0e3ad6 | 9 | #include <linux/slab.h> |
7c0f6ba6 | 10 | #include <linux/uaccess.h> |
e89c0413 | 11 | #include <linux/fsmap.h> |
1da177e4 | 12 | #include "xfs.h" |
1da177e4 | 13 | #include "xfs_fs.h" |
a4fbe6ab | 14 | #include "xfs_format.h" |
239880ef DC |
15 | #include "xfs_log_format.h" |
16 | #include "xfs_trans_resv.h" | |
faa63e95 | 17 | #include "xfs_mount.h" |
faa63e95 MM |
18 | #include "xfs_inode.h" |
19 | #include "xfs_itable.h" | |
20 | #include "xfs_error.h" | |
d5547f9f | 21 | #include "xfs_fsops.h" |
471d5910 | 22 | #include "xfs_alloc.h" |
23 | #include "xfs_rtalloc.h" | |
ebeecd2b | 24 | #include "xfs_attr.h" |
d5547f9f | 25 | #include "xfs_ioctl.h" |
a8272ce0 | 26 | #include "xfs_ioctl32.h" |
0b1b213f | 27 | #include "xfs_trace.h" |
c368ebcd | 28 | #include "xfs_sb.h" |
1da177e4 | 29 | |
526c420c ES |
30 | #define _NATIVE_IOC(cmd, type) \ |
31 | _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type)) | |
32 | ||
ffae263a | 33 | #ifdef BROKEN_X86_ALIGNMENT |
d5547f9f | 34 | STATIC int |
35 | xfs_compat_flock64_copyin( | |
36 | xfs_flock64_t *bf, | |
37 | compat_xfs_flock64_t __user *arg32) | |
526c420c | 38 | { |
d5547f9f | 39 | if (get_user(bf->l_type, &arg32->l_type) || |
40 | get_user(bf->l_whence, &arg32->l_whence) || | |
41 | get_user(bf->l_start, &arg32->l_start) || | |
42 | get_user(bf->l_len, &arg32->l_len) || | |
43 | get_user(bf->l_sysid, &arg32->l_sysid) || | |
44 | get_user(bf->l_pid, &arg32->l_pid) || | |
45 | copy_from_user(bf->l_pad, &arg32->l_pad, 4*sizeof(u32))) | |
b474c7ae | 46 | return -EFAULT; |
d5547f9f | 47 | return 0; |
526c420c ES |
48 | } |
49 | ||
d5547f9f | 50 | STATIC int |
51 | xfs_compat_ioc_fsgeometry_v1( | |
52 | struct xfs_mount *mp, | |
53 | compat_xfs_fsop_geom_v1_t __user *arg32) | |
547e00c3 | 54 | { |
d5547f9f | 55 | xfs_fsop_geom_t fsgeo; |
56 | int error; | |
547e00c3 | 57 | |
ac503a4c | 58 | error = xfs_fs_geometry(&mp->m_sb, &fsgeo, 3); |
d5547f9f | 59 | if (error) |
2451337d | 60 | return error; |
d5547f9f | 61 | /* The 32-bit variant simply has some padding at the end */ |
62 | if (copy_to_user(arg32, &fsgeo, sizeof(struct compat_xfs_fsop_geom_v1))) | |
b474c7ae | 63 | return -EFAULT; |
d5547f9f | 64 | return 0; |
547e00c3 MM |
65 | } |
66 | ||
471d5910 | 67 | STATIC int |
68 | xfs_compat_growfs_data_copyin( | |
69 | struct xfs_growfs_data *in, | |
70 | compat_xfs_growfs_data_t __user *arg32) | |
71 | { | |
72 | if (get_user(in->newblocks, &arg32->newblocks) || | |
73 | get_user(in->imaxpct, &arg32->imaxpct)) | |
b474c7ae | 74 | return -EFAULT; |
471d5910 | 75 | return 0; |
76 | } | |
77 | ||
78 | STATIC int | |
79 | xfs_compat_growfs_rt_copyin( | |
80 | struct xfs_growfs_rt *in, | |
81 | compat_xfs_growfs_rt_t __user *arg32) | |
82 | { | |
83 | if (get_user(in->newblocks, &arg32->newblocks) || | |
84 | get_user(in->extsize, &arg32->extsize)) | |
b474c7ae | 85 | return -EFAULT; |
471d5910 | 86 | return 0; |
87 | } | |
88 | ||
d5547f9f | 89 | STATIC int |
90 | xfs_inumbers_fmt_compat( | |
91 | void __user *ubuffer, | |
549fa006 | 92 | const struct xfs_inogrp *buffer, |
d5547f9f | 93 | long count, |
94 | long *written) | |
faa63e95 | 95 | { |
d5547f9f | 96 | compat_xfs_inogrp_t __user *p32 = ubuffer; |
97 | long i; | |
faa63e95 MM |
98 | |
99 | for (i = 0; i < count; i++) { | |
100 | if (put_user(buffer[i].xi_startino, &p32[i].xi_startino) || | |
101 | put_user(buffer[i].xi_alloccount, &p32[i].xi_alloccount) || | |
102 | put_user(buffer[i].xi_allocmask, &p32[i].xi_allocmask)) | |
b474c7ae | 103 | return -EFAULT; |
faa63e95 MM |
104 | } |
105 | *written = count * sizeof(*p32); | |
106 | return 0; | |
107 | } | |
108 | ||
1da177e4 | 109 | #else |
faa63e95 | 110 | #define xfs_inumbers_fmt_compat xfs_inumbers_fmt |
e5d412f1 | 111 | #endif /* BROKEN_X86_ALIGNMENT */ |
faa63e95 | 112 | |
e94fc4a4 | 113 | STATIC int |
114 | xfs_ioctl32_bstime_copyin( | |
115 | xfs_bstime_t *bstime, | |
116 | compat_xfs_bstime_t __user *bstime32) | |
117 | { | |
118 | compat_time_t sec32; /* tv_sec differs on 64 vs. 32 */ | |
119 | ||
120 | if (get_user(sec32, &bstime32->tv_sec) || | |
121 | get_user(bstime->tv_nsec, &bstime32->tv_nsec)) | |
b474c7ae | 122 | return -EFAULT; |
e94fc4a4 | 123 | bstime->tv_sec = sec32; |
124 | return 0; | |
125 | } | |
126 | ||
127 | /* xfs_bstat_t has differing alignment on intel, & bstime_t sizes everywhere */ | |
128 | STATIC int | |
129 | xfs_ioctl32_bstat_copyin( | |
130 | xfs_bstat_t *bstat, | |
131 | compat_xfs_bstat_t __user *bstat32) | |
132 | { | |
133 | if (get_user(bstat->bs_ino, &bstat32->bs_ino) || | |
134 | get_user(bstat->bs_mode, &bstat32->bs_mode) || | |
135 | get_user(bstat->bs_nlink, &bstat32->bs_nlink) || | |
136 | get_user(bstat->bs_uid, &bstat32->bs_uid) || | |
137 | get_user(bstat->bs_gid, &bstat32->bs_gid) || | |
138 | get_user(bstat->bs_rdev, &bstat32->bs_rdev) || | |
139 | get_user(bstat->bs_blksize, &bstat32->bs_blksize) || | |
140 | get_user(bstat->bs_size, &bstat32->bs_size) || | |
141 | xfs_ioctl32_bstime_copyin(&bstat->bs_atime, &bstat32->bs_atime) || | |
142 | xfs_ioctl32_bstime_copyin(&bstat->bs_mtime, &bstat32->bs_mtime) || | |
143 | xfs_ioctl32_bstime_copyin(&bstat->bs_ctime, &bstat32->bs_ctime) || | |
144 | get_user(bstat->bs_blocks, &bstat32->bs_size) || | |
145 | get_user(bstat->bs_xflags, &bstat32->bs_size) || | |
146 | get_user(bstat->bs_extsize, &bstat32->bs_extsize) || | |
147 | get_user(bstat->bs_extents, &bstat32->bs_extents) || | |
148 | get_user(bstat->bs_gen, &bstat32->bs_gen) || | |
6743099c AM |
149 | get_user(bstat->bs_projid_lo, &bstat32->bs_projid_lo) || |
150 | get_user(bstat->bs_projid_hi, &bstat32->bs_projid_hi) || | |
b1d6cc02 | 151 | get_user(bstat->bs_forkoff, &bstat32->bs_forkoff) || |
e94fc4a4 | 152 | get_user(bstat->bs_dmevmask, &bstat32->bs_dmevmask) || |
153 | get_user(bstat->bs_dmstate, &bstat32->bs_dmstate) || | |
154 | get_user(bstat->bs_aextents, &bstat32->bs_aextents)) | |
b474c7ae | 155 | return -EFAULT; |
e94fc4a4 | 156 | return 0; |
157 | } | |
158 | ||
faa63e95 MM |
159 | /* XFS_IOC_FSBULKSTAT and friends */ |
160 | ||
d5547f9f | 161 | STATIC int |
162 | xfs_bstime_store_compat( | |
163 | compat_xfs_bstime_t __user *p32, | |
164 | const xfs_bstime_t *p) | |
faa63e95 | 165 | { |
d5547f9f | 166 | __s32 sec32; |
faa63e95 MM |
167 | |
168 | sec32 = p->tv_sec; | |
169 | if (put_user(sec32, &p32->tv_sec) || | |
170 | put_user(p->tv_nsec, &p32->tv_nsec)) | |
b474c7ae | 171 | return -EFAULT; |
faa63e95 MM |
172 | return 0; |
173 | } | |
174 | ||
65fbaf24 | 175 | /* Return 0 on success or positive error (to xfs_bulkstat()) */ |
d5547f9f | 176 | STATIC int |
177 | xfs_bulkstat_one_fmt_compat( | |
faa63e95 | 178 | void __user *ubuffer, |
65fbaf24 | 179 | int ubsize, |
180 | int *ubused, | |
faa63e95 MM |
181 | const xfs_bstat_t *buffer) |
182 | { | |
d5547f9f | 183 | compat_xfs_bstat_t __user *p32 = ubuffer; |
faa63e95 | 184 | |
65fbaf24 | 185 | if (ubsize < sizeof(*p32)) |
2451337d | 186 | return -ENOMEM; |
65fbaf24 | 187 | |
188 | if (put_user(buffer->bs_ino, &p32->bs_ino) || | |
189 | put_user(buffer->bs_mode, &p32->bs_mode) || | |
190 | put_user(buffer->bs_nlink, &p32->bs_nlink) || | |
191 | put_user(buffer->bs_uid, &p32->bs_uid) || | |
192 | put_user(buffer->bs_gid, &p32->bs_gid) || | |
193 | put_user(buffer->bs_rdev, &p32->bs_rdev) || | |
194 | put_user(buffer->bs_blksize, &p32->bs_blksize) || | |
195 | put_user(buffer->bs_size, &p32->bs_size) || | |
faa63e95 MM |
196 | xfs_bstime_store_compat(&p32->bs_atime, &buffer->bs_atime) || |
197 | xfs_bstime_store_compat(&p32->bs_mtime, &buffer->bs_mtime) || | |
198 | xfs_bstime_store_compat(&p32->bs_ctime, &buffer->bs_ctime) || | |
65fbaf24 | 199 | put_user(buffer->bs_blocks, &p32->bs_blocks) || |
200 | put_user(buffer->bs_xflags, &p32->bs_xflags) || | |
201 | put_user(buffer->bs_extsize, &p32->bs_extsize) || | |
202 | put_user(buffer->bs_extents, &p32->bs_extents) || | |
203 | put_user(buffer->bs_gen, &p32->bs_gen) || | |
204 | put_user(buffer->bs_projid, &p32->bs_projid) || | |
6743099c | 205 | put_user(buffer->bs_projid_hi, &p32->bs_projid_hi) || |
b1d6cc02 | 206 | put_user(buffer->bs_forkoff, &p32->bs_forkoff) || |
65fbaf24 | 207 | put_user(buffer->bs_dmevmask, &p32->bs_dmevmask) || |
208 | put_user(buffer->bs_dmstate, &p32->bs_dmstate) || | |
faa63e95 | 209 | put_user(buffer->bs_aextents, &p32->bs_aextents)) |
2451337d | 210 | return -EFAULT; |
65fbaf24 | 211 | if (ubused) |
212 | *ubused = sizeof(*p32); | |
213 | return 0; | |
faa63e95 MM |
214 | } |
215 | ||
2ee4fa5c | 216 | STATIC int |
217 | xfs_bulkstat_one_compat( | |
218 | xfs_mount_t *mp, /* mount point for filesystem */ | |
219 | xfs_ino_t ino, /* inode number to get data for */ | |
220 | void __user *buffer, /* buffer to place output in */ | |
221 | int ubsize, /* size of buffer */ | |
2ee4fa5c | 222 | int *ubused, /* bytes used by me */ |
2ee4fa5c | 223 | int *stat) /* BULKSTAT_RV_... */ |
224 | { | |
225 | return xfs_bulkstat_one_int(mp, ino, buffer, ubsize, | |
7b6259e7 | 226 | xfs_bulkstat_one_fmt_compat, |
7dce11db | 227 | ubused, stat); |
2ee4fa5c | 228 | } |
229 | ||
faa63e95 MM |
230 | /* copied from xfs_ioctl.c */ |
231 | STATIC int | |
2ee4fa5c | 232 | xfs_compat_ioc_bulkstat( |
233 | xfs_mount_t *mp, | |
234 | unsigned int cmd, | |
235 | compat_xfs_fsop_bulkreq_t __user *p32) | |
1da177e4 | 236 | { |
1da177e4 | 237 | u32 addr; |
faa63e95 MM |
238 | xfs_fsop_bulkreq_t bulkreq; |
239 | int count; /* # of records returned */ | |
240 | xfs_ino_t inlast; /* last inode number */ | |
241 | int done; | |
242 | int error; | |
243 | ||
7ca860e3 NB |
244 | /* |
245 | * Output structure handling functions. Depending on the command, | |
246 | * either the xfs_bstat and xfs_inogrp structures are written out | |
247 | * to userpace memory via bulkreq.ubuffer. Normally the compat | |
248 | * functions and structure size are the correct ones to use ... | |
249 | */ | |
250 | inumbers_fmt_pf inumbers_func = xfs_inumbers_fmt_compat; | |
251 | bulkstat_one_pf bs_one_func = xfs_bulkstat_one_compat; | |
252 | size_t bs_one_size = sizeof(struct compat_xfs_bstat); | |
253 | ||
254 | #ifdef CONFIG_X86_X32 | |
255 | if (in_x32_syscall()) { | |
256 | /* | |
257 | * ... but on x32 the input xfs_fsop_bulkreq has pointers | |
258 | * which must be handled in the "compat" (32-bit) way, while | |
259 | * the xfs_bstat and xfs_inogrp structures follow native 64- | |
260 | * bit layout convention. So adjust accordingly, otherwise | |
261 | * the data written out in compat layout will not match what | |
262 | * x32 userspace expects. | |
263 | */ | |
264 | inumbers_func = xfs_inumbers_fmt; | |
265 | bs_one_func = xfs_bulkstat_one; | |
266 | bs_one_size = sizeof(struct xfs_bstat); | |
267 | } | |
268 | #endif | |
269 | ||
faa63e95 MM |
270 | /* done = 1 if there are more stats to get and if bulkstat */ |
271 | /* should be called again (unused here, but used in dmapi) */ | |
1da177e4 | 272 | |
faa63e95 | 273 | if (!capable(CAP_SYS_ADMIN)) |
b474c7ae | 274 | return -EPERM; |
faa63e95 MM |
275 | |
276 | if (XFS_FORCED_SHUTDOWN(mp)) | |
b474c7ae | 277 | return -EIO; |
faa63e95 MM |
278 | |
279 | if (get_user(addr, &p32->lastip)) | |
b474c7ae | 280 | return -EFAULT; |
faa63e95 MM |
281 | bulkreq.lastip = compat_ptr(addr); |
282 | if (get_user(bulkreq.icount, &p32->icount) || | |
283 | get_user(addr, &p32->ubuffer)) | |
b474c7ae | 284 | return -EFAULT; |
faa63e95 MM |
285 | bulkreq.ubuffer = compat_ptr(addr); |
286 | if (get_user(addr, &p32->ocount)) | |
b474c7ae | 287 | return -EFAULT; |
faa63e95 | 288 | bulkreq.ocount = compat_ptr(addr); |
1da177e4 | 289 | |
faa63e95 | 290 | if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64))) |
b474c7ae | 291 | return -EFAULT; |
faa63e95 MM |
292 | |
293 | if ((count = bulkreq.icount) <= 0) | |
b474c7ae | 294 | return -EINVAL; |
faa63e95 | 295 | |
cd57e594 | 296 | if (bulkreq.ubuffer == NULL) |
b474c7ae | 297 | return -EINVAL; |
cd57e594 | 298 | |
af819d27 | 299 | if (cmd == XFS_IOC_FSINUMBERS_32) { |
faa63e95 | 300 | error = xfs_inumbers(mp, &inlast, &count, |
7ca860e3 | 301 | bulkreq.ubuffer, inumbers_func); |
af819d27 | 302 | } else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE_32) { |
303 | int res; | |
304 | ||
7ca860e3 NB |
305 | error = bs_one_func(mp, inlast, bulkreq.ubuffer, |
306 | bs_one_size, NULL, &res); | |
af819d27 | 307 | } else if (cmd == XFS_IOC_FSBULKSTAT_32) { |
faa63e95 | 308 | error = xfs_bulkstat(mp, &inlast, &count, |
7ca860e3 | 309 | bs_one_func, bs_one_size, |
7dce11db | 310 | bulkreq.ubuffer, &done); |
af819d27 | 311 | } else |
2451337d | 312 | error = -EINVAL; |
faa63e95 | 313 | if (error) |
2451337d | 314 | return error; |
faa63e95 MM |
315 | |
316 | if (bulkreq.ocount != NULL) { | |
317 | if (copy_to_user(bulkreq.lastip, &inlast, | |
318 | sizeof(xfs_ino_t))) | |
b474c7ae | 319 | return -EFAULT; |
faa63e95 MM |
320 | |
321 | if (copy_to_user(bulkreq.ocount, &count, sizeof(count))) | |
b474c7ae | 322 | return -EFAULT; |
faa63e95 MM |
323 | } |
324 | ||
325 | return 0; | |
1da177e4 | 326 | } |
faa63e95 | 327 | |
d5547f9f | 328 | STATIC int |
329 | xfs_compat_handlereq_copyin( | |
330 | xfs_fsop_handlereq_t *hreq, | |
331 | compat_xfs_fsop_handlereq_t __user *arg32) | |
1fa503df | 332 | { |
d5547f9f | 333 | compat_xfs_fsop_handlereq_t hreq32; |
334 | ||
335 | if (copy_from_user(&hreq32, arg32, sizeof(compat_xfs_fsop_handlereq_t))) | |
b474c7ae | 336 | return -EFAULT; |
d5547f9f | 337 | |
338 | hreq->fd = hreq32.fd; | |
339 | hreq->path = compat_ptr(hreq32.path); | |
340 | hreq->oflags = hreq32.oflags; | |
341 | hreq->ihandle = compat_ptr(hreq32.ihandle); | |
342 | hreq->ihandlen = hreq32.ihandlen; | |
343 | hreq->ohandle = compat_ptr(hreq32.ohandle); | |
344 | hreq->ohandlen = compat_ptr(hreq32.ohandlen); | |
345 | ||
346 | return 0; | |
1fa503df MM |
347 | } |
348 | ||
ab596ad8 CH |
349 | STATIC struct dentry * |
350 | xfs_compat_handlereq_to_dentry( | |
351 | struct file *parfilp, | |
352 | compat_xfs_fsop_handlereq_t *hreq) | |
ebeecd2b | 353 | { |
ab596ad8 CH |
354 | return xfs_handle_to_dentry(parfilp, |
355 | compat_ptr(hreq->ihandle), hreq->ihandlen); | |
ebeecd2b | 356 | } |
357 | ||
358 | STATIC int | |
359 | xfs_compat_attrlist_by_handle( | |
ab596ad8 CH |
360 | struct file *parfilp, |
361 | void __user *arg) | |
ebeecd2b | 362 | { |
363 | int error; | |
364 | attrlist_cursor_kern_t *cursor; | |
c456d644 | 365 | compat_xfs_fsop_attrlist_handlereq_t __user *p = arg; |
ebeecd2b | 366 | compat_xfs_fsop_attrlist_handlereq_t al_hreq; |
ab596ad8 | 367 | struct dentry *dentry; |
ebeecd2b | 368 | char *kbuf; |
369 | ||
370 | if (!capable(CAP_SYS_ADMIN)) | |
b474c7ae | 371 | return -EPERM; |
ebeecd2b | 372 | if (copy_from_user(&al_hreq, arg, |
373 | sizeof(compat_xfs_fsop_attrlist_handlereq_t))) | |
b474c7ae | 374 | return -EFAULT; |
31978b5c | 375 | if (al_hreq.buflen < sizeof(struct attrlist) || |
4e247614 | 376 | al_hreq.buflen > XFS_XATTR_LIST_MAX) |
b474c7ae | 377 | return -EINVAL; |
ebeecd2b | 378 | |
379 | /* | |
380 | * Reject flags, only allow namespaces. | |
381 | */ | |
382 | if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE)) | |
b474c7ae | 383 | return -EINVAL; |
ebeecd2b | 384 | |
ab596ad8 CH |
385 | dentry = xfs_compat_handlereq_to_dentry(parfilp, &al_hreq.hreq); |
386 | if (IS_ERR(dentry)) | |
387 | return PTR_ERR(dentry); | |
ebeecd2b | 388 | |
ab596ad8 | 389 | error = -ENOMEM; |
fdd3ccee DC |
390 | kbuf = kmem_zalloc_large(al_hreq.buflen, KM_SLEEP); |
391 | if (!kbuf) | |
392 | goto out_dput; | |
ebeecd2b | 393 | |
394 | cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; | |
2b0143b5 | 395 | error = xfs_attr_list(XFS_I(d_inode(dentry)), kbuf, al_hreq.buflen, |
ebeecd2b | 396 | al_hreq.flags, cursor); |
397 | if (error) | |
398 | goto out_kfree; | |
399 | ||
c456d644 NB |
400 | if (copy_to_user(&p->pos, cursor, sizeof(attrlist_cursor_kern_t))) { |
401 | error = -EFAULT; | |
402 | goto out_kfree; | |
403 | } | |
404 | ||
ebeecd2b | 405 | if (copy_to_user(compat_ptr(al_hreq.buffer), kbuf, al_hreq.buflen)) |
406 | error = -EFAULT; | |
407 | ||
fdd3ccee DC |
408 | out_kfree: |
409 | kmem_free(kbuf); | |
410 | out_dput: | |
ab596ad8 CH |
411 | dput(dentry); |
412 | return error; | |
ebeecd2b | 413 | } |
414 | ||
28750975 | 415 | STATIC int |
416 | xfs_compat_attrmulti_by_handle( | |
ab596ad8 CH |
417 | struct file *parfilp, |
418 | void __user *arg) | |
28750975 | 419 | { |
420 | int error; | |
421 | compat_xfs_attr_multiop_t *ops; | |
422 | compat_xfs_fsop_attrmulti_handlereq_t am_hreq; | |
ab596ad8 | 423 | struct dentry *dentry; |
28750975 | 424 | unsigned int i, size; |
a9273ca5 | 425 | unsigned char *attr_name; |
28750975 | 426 | |
427 | if (!capable(CAP_SYS_ADMIN)) | |
b474c7ae | 428 | return -EPERM; |
28750975 | 429 | if (copy_from_user(&am_hreq, arg, |
430 | sizeof(compat_xfs_fsop_attrmulti_handlereq_t))) | |
b474c7ae | 431 | return -EFAULT; |
28750975 | 432 | |
fda168c2 ZW |
433 | /* overflow check */ |
434 | if (am_hreq.opcount >= INT_MAX / sizeof(compat_xfs_attr_multiop_t)) | |
435 | return -E2BIG; | |
436 | ||
ab596ad8 CH |
437 | dentry = xfs_compat_handlereq_to_dentry(parfilp, &am_hreq.hreq); |
438 | if (IS_ERR(dentry)) | |
439 | return PTR_ERR(dentry); | |
28750975 | 440 | |
2451337d | 441 | error = -E2BIG; |
28750975 | 442 | size = am_hreq.opcount * sizeof(compat_xfs_attr_multiop_t); |
443 | if (!size || size > 16 * PAGE_SIZE) | |
ab596ad8 | 444 | goto out_dput; |
28750975 | 445 | |
0e639bde LZ |
446 | ops = memdup_user(compat_ptr(am_hreq.ops), size); |
447 | if (IS_ERR(ops)) { | |
4d949021 | 448 | error = PTR_ERR(ops); |
ab596ad8 | 449 | goto out_dput; |
0e639bde | 450 | } |
28750975 | 451 | |
2451337d | 452 | error = -ENOMEM; |
28750975 | 453 | attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL); |
454 | if (!attr_name) | |
455 | goto out_kfree_ops; | |
456 | ||
28750975 | 457 | error = 0; |
458 | for (i = 0; i < am_hreq.opcount; i++) { | |
a9273ca5 | 459 | ops[i].am_error = strncpy_from_user((char *)attr_name, |
28750975 | 460 | compat_ptr(ops[i].am_attrname), |
461 | MAXNAMELEN); | |
462 | if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN) | |
2451337d | 463 | error = -ERANGE; |
28750975 | 464 | if (ops[i].am_error < 0) |
465 | break; | |
466 | ||
467 | switch (ops[i].am_opcode) { | |
468 | case ATTR_OP_GET: | |
ab596ad8 | 469 | ops[i].am_error = xfs_attrmulti_attr_get( |
2b0143b5 | 470 | d_inode(dentry), attr_name, |
28750975 | 471 | compat_ptr(ops[i].am_attrvalue), |
472 | &ops[i].am_length, ops[i].am_flags); | |
473 | break; | |
474 | case ATTR_OP_SET: | |
a561be71 | 475 | ops[i].am_error = mnt_want_write_file(parfilp); |
62e194ec CH |
476 | if (ops[i].am_error) |
477 | break; | |
ab596ad8 | 478 | ops[i].am_error = xfs_attrmulti_attr_set( |
2b0143b5 | 479 | d_inode(dentry), attr_name, |
28750975 | 480 | compat_ptr(ops[i].am_attrvalue), |
481 | ops[i].am_length, ops[i].am_flags); | |
2a79f17e | 482 | mnt_drop_write_file(parfilp); |
28750975 | 483 | break; |
484 | case ATTR_OP_REMOVE: | |
a561be71 | 485 | ops[i].am_error = mnt_want_write_file(parfilp); |
62e194ec CH |
486 | if (ops[i].am_error) |
487 | break; | |
ab596ad8 | 488 | ops[i].am_error = xfs_attrmulti_attr_remove( |
2b0143b5 | 489 | d_inode(dentry), attr_name, |
ab596ad8 | 490 | ops[i].am_flags); |
2a79f17e | 491 | mnt_drop_write_file(parfilp); |
28750975 | 492 | break; |
493 | default: | |
2451337d | 494 | ops[i].am_error = -EINVAL; |
28750975 | 495 | } |
496 | } | |
497 | ||
498 | if (copy_to_user(compat_ptr(am_hreq.ops), ops, size)) | |
2451337d | 499 | error = -EFAULT; |
28750975 | 500 | |
501 | kfree(attr_name); | |
502 | out_kfree_ops: | |
503 | kfree(ops); | |
ab596ad8 CH |
504 | out_dput: |
505 | dput(dentry); | |
2451337d | 506 | return error; |
28750975 | 507 | } |
508 | ||
710d62aa | 509 | STATIC int |
510 | xfs_compat_fssetdm_by_handle( | |
ab596ad8 CH |
511 | struct file *parfilp, |
512 | void __user *arg) | |
710d62aa | 513 | { |
514 | int error; | |
515 | struct fsdmidata fsd; | |
516 | compat_xfs_fsop_setdm_handlereq_t dmhreq; | |
ab596ad8 | 517 | struct dentry *dentry; |
710d62aa | 518 | |
519 | if (!capable(CAP_MKNOD)) | |
b474c7ae | 520 | return -EPERM; |
710d62aa | 521 | if (copy_from_user(&dmhreq, arg, |
522 | sizeof(compat_xfs_fsop_setdm_handlereq_t))) | |
b474c7ae | 523 | return -EFAULT; |
710d62aa | 524 | |
ab596ad8 CH |
525 | dentry = xfs_compat_handlereq_to_dentry(parfilp, &dmhreq.hreq); |
526 | if (IS_ERR(dentry)) | |
527 | return PTR_ERR(dentry); | |
710d62aa | 528 | |
2b0143b5 | 529 | if (IS_IMMUTABLE(d_inode(dentry)) || IS_APPEND(d_inode(dentry))) { |
b474c7ae | 530 | error = -EPERM; |
710d62aa | 531 | goto out; |
532 | } | |
533 | ||
534 | if (copy_from_user(&fsd, compat_ptr(dmhreq.data), sizeof(fsd))) { | |
b474c7ae | 535 | error = -EFAULT; |
710d62aa | 536 | goto out; |
537 | } | |
538 | ||
2b0143b5 | 539 | error = xfs_set_dmattrs(XFS_I(d_inode(dentry)), fsd.fsd_dmevmask, |
710d62aa | 540 | fsd.fsd_dmstate); |
541 | ||
542 | out: | |
ab596ad8 | 543 | dput(dentry); |
710d62aa | 544 | return error; |
545 | } | |
546 | ||
4d4be482 CH |
547 | long |
548 | xfs_file_compat_ioctl( | |
549 | struct file *filp, | |
550 | unsigned cmd, | |
551 | unsigned long p) | |
1da177e4 | 552 | { |
496ad9aa | 553 | struct inode *inode = file_inode(filp); |
4d4be482 CH |
554 | struct xfs_inode *ip = XFS_I(inode); |
555 | struct xfs_mount *mp = ip->i_mount; | |
556 | void __user *arg = (void __user *)p; | |
4d4be482 CH |
557 | int error; |
558 | ||
cca28fb8 | 559 | trace_xfs_file_compat_ioctl(ip); |
1da177e4 LT |
560 | |
561 | switch (cmd) { | |
e5d412f1 | 562 | /* No size or alignment issues on any arch */ |
1da177e4 | 563 | case XFS_IOC_DIOINFO: |
1da177e4 | 564 | case XFS_IOC_FSGEOMETRY: |
1da177e4 LT |
565 | case XFS_IOC_FSGETXATTR: |
566 | case XFS_IOC_FSSETXATTR: | |
567 | case XFS_IOC_FSGETXATTRA: | |
568 | case XFS_IOC_FSSETDM: | |
569 | case XFS_IOC_GETBMAP: | |
570 | case XFS_IOC_GETBMAPA: | |
571 | case XFS_IOC_GETBMAPX: | |
1da177e4 LT |
572 | case XFS_IOC_FSCOUNTS: |
573 | case XFS_IOC_SET_RESBLKS: | |
574 | case XFS_IOC_GET_RESBLKS: | |
1da177e4 | 575 | case XFS_IOC_FSGROWFSLOG: |
1da177e4 LT |
576 | case XFS_IOC_GOINGDOWN: |
577 | case XFS_IOC_ERROR_INJECTION: | |
578 | case XFS_IOC_ERROR_CLEARALL: | |
e89c0413 | 579 | case FS_IOC_GETFSMAP: |
36fd6e86 | 580 | case XFS_IOC_SCRUB_METADATA: |
4d4be482 | 581 | return xfs_file_ioctl(filp, cmd, p); |
a9d25bde NB |
582 | #if !defined(BROKEN_X86_ALIGNMENT) || defined(CONFIG_X86_X32) |
583 | /* | |
584 | * These are handled fine if no alignment issues. To support x32 | |
585 | * which uses native 64-bit alignment we must emit these cases in | |
586 | * addition to the ia-32 compat set below. | |
587 | */ | |
e5d412f1 | 588 | case XFS_IOC_ALLOCSP: |
589 | case XFS_IOC_FREESP: | |
590 | case XFS_IOC_RESVSP: | |
591 | case XFS_IOC_UNRESVSP: | |
592 | case XFS_IOC_ALLOCSP64: | |
593 | case XFS_IOC_FREESP64: | |
594 | case XFS_IOC_RESVSP64: | |
595 | case XFS_IOC_UNRESVSP64: | |
596 | case XFS_IOC_FSGEOMETRY_V1: | |
597 | case XFS_IOC_FSGROWFSDATA: | |
598 | case XFS_IOC_FSGROWFSRT: | |
44722352 | 599 | case XFS_IOC_ZERO_RANGE: |
a9d25bde NB |
600 | #ifdef CONFIG_X86_X32 |
601 | /* | |
602 | * x32 special: this gets a different cmd number from the ia-32 compat | |
603 | * case below; the associated data will match native 64-bit alignment. | |
604 | */ | |
605 | case XFS_IOC_SWAPEXT: | |
606 | #endif | |
4d4be482 | 607 | return xfs_file_ioctl(filp, cmd, p); |
a9d25bde NB |
608 | #endif |
609 | #if defined(BROKEN_X86_ALIGNMENT) | |
526c420c ES |
610 | case XFS_IOC_ALLOCSP_32: |
611 | case XFS_IOC_FREESP_32: | |
612 | case XFS_IOC_ALLOCSP64_32: | |
613 | case XFS_IOC_FREESP64_32: | |
614 | case XFS_IOC_RESVSP_32: | |
615 | case XFS_IOC_UNRESVSP_32: | |
616 | case XFS_IOC_RESVSP64_32: | |
8c1fdd0b CH |
617 | case XFS_IOC_UNRESVSP64_32: |
618 | case XFS_IOC_ZERO_RANGE_32: { | |
d5547f9f | 619 | struct xfs_flock64 bf; |
620 | ||
621 | if (xfs_compat_flock64_copyin(&bf, arg)) | |
b474c7ae | 622 | return -EFAULT; |
526c420c | 623 | cmd = _NATIVE_IOC(cmd, struct xfs_flock64); |
8f3e2058 | 624 | return xfs_ioc_space(filp, cmd, &bf); |
d5547f9f | 625 | } |
547e00c3 | 626 | case XFS_IOC_FSGEOMETRY_V1_32: |
d5547f9f | 627 | return xfs_compat_ioc_fsgeometry_v1(mp, arg); |
471d5910 | 628 | case XFS_IOC_FSGROWFSDATA_32: { |
629 | struct xfs_growfs_data in; | |
630 | ||
631 | if (xfs_compat_growfs_data_copyin(&in, arg)) | |
b474c7ae | 632 | return -EFAULT; |
d9457dc0 JK |
633 | error = mnt_want_write_file(filp); |
634 | if (error) | |
635 | return error; | |
471d5910 | 636 | error = xfs_growfs_data(mp, &in); |
d9457dc0 | 637 | mnt_drop_write_file(filp); |
2451337d | 638 | return error; |
471d5910 | 639 | } |
640 | case XFS_IOC_FSGROWFSRT_32: { | |
641 | struct xfs_growfs_rt in; | |
642 | ||
643 | if (xfs_compat_growfs_rt_copyin(&in, arg)) | |
b474c7ae | 644 | return -EFAULT; |
d9457dc0 JK |
645 | error = mnt_want_write_file(filp); |
646 | if (error) | |
647 | return error; | |
471d5910 | 648 | error = xfs_growfs_rt(mp, &in); |
d9457dc0 | 649 | mnt_drop_write_file(filp); |
2451337d | 650 | return error; |
471d5910 | 651 | } |
1da177e4 | 652 | #endif |
e5d412f1 | 653 | /* long changes size, but xfs only copiese out 32 bits */ |
654 | case XFS_IOC_GETXFLAGS_32: | |
655 | case XFS_IOC_SETXFLAGS_32: | |
656 | case XFS_IOC_GETVERSION_32: | |
657 | cmd = _NATIVE_IOC(cmd, long); | |
4d4be482 | 658 | return xfs_file_ioctl(filp, cmd, p); |
3725867d | 659 | case XFS_IOC_SWAPEXT_32: { |
e5d412f1 | 660 | struct xfs_swapext sxp; |
661 | struct compat_xfs_swapext __user *sxu = arg; | |
662 | ||
663 | /* Bulk copy in up to the sx_stat field, then copy bstat */ | |
664 | if (copy_from_user(&sxp, sxu, | |
665 | offsetof(struct xfs_swapext, sx_stat)) || | |
666 | xfs_ioctl32_bstat_copyin(&sxp.sx_stat, &sxu->sx_stat)) | |
b474c7ae | 667 | return -EFAULT; |
d9457dc0 JK |
668 | error = mnt_want_write_file(filp); |
669 | if (error) | |
670 | return error; | |
a133d952 | 671 | error = xfs_ioc_swapext(&sxp); |
d9457dc0 | 672 | mnt_drop_write_file(filp); |
2451337d | 673 | return error; |
e5d412f1 | 674 | } |
faa63e95 MM |
675 | case XFS_IOC_FSBULKSTAT_32: |
676 | case XFS_IOC_FSBULKSTAT_SINGLE_32: | |
677 | case XFS_IOC_FSINUMBERS_32: | |
2ee4fa5c | 678 | return xfs_compat_ioc_bulkstat(mp, cmd, arg); |
1fa503df MM |
679 | case XFS_IOC_FD_TO_HANDLE_32: |
680 | case XFS_IOC_PATH_TO_HANDLE_32: | |
d5547f9f | 681 | case XFS_IOC_PATH_TO_FSHANDLE_32: { |
682 | struct xfs_fsop_handlereq hreq; | |
683 | ||
684 | if (xfs_compat_handlereq_copyin(&hreq, arg)) | |
b474c7ae | 685 | return -EFAULT; |
1fa503df | 686 | cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq); |
d5547f9f | 687 | return xfs_find_handle(cmd, &hreq); |
688 | } | |
689 | case XFS_IOC_OPEN_BY_HANDLE_32: { | |
690 | struct xfs_fsop_handlereq hreq; | |
691 | ||
692 | if (xfs_compat_handlereq_copyin(&hreq, arg)) | |
b474c7ae | 693 | return -EFAULT; |
ab596ad8 | 694 | return xfs_open_by_handle(filp, &hreq); |
d5547f9f | 695 | } |
696 | case XFS_IOC_READLINK_BY_HANDLE_32: { | |
697 | struct xfs_fsop_handlereq hreq; | |
698 | ||
699 | if (xfs_compat_handlereq_copyin(&hreq, arg)) | |
b474c7ae | 700 | return -EFAULT; |
ab596ad8 | 701 | return xfs_readlink_by_handle(filp, &hreq); |
d5547f9f | 702 | } |
ebeecd2b | 703 | case XFS_IOC_ATTRLIST_BY_HANDLE_32: |
ab596ad8 | 704 | return xfs_compat_attrlist_by_handle(filp, arg); |
28750975 | 705 | case XFS_IOC_ATTRMULTI_BY_HANDLE_32: |
ab596ad8 | 706 | return xfs_compat_attrmulti_by_handle(filp, arg); |
710d62aa | 707 | case XFS_IOC_FSSETDM_BY_HANDLE_32: |
ab596ad8 | 708 | return xfs_compat_fssetdm_by_handle(filp, arg); |
1da177e4 | 709 | default: |
b474c7ae | 710 | return -ENOIOCTLCMD; |
1da177e4 | 711 | } |
1da177e4 | 712 | } |