xfs_ioctl32.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. /*
  2. * Copyright (c) 2004-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <linux/compat.h>
  19. #include <linux/ioctl.h>
  20. #include <asm/uaccess.h>
  21. #include "xfs.h"
  22. #include "xfs_fs.h"
  23. #include "xfs_bit.h"
  24. #include "xfs_log.h"
  25. #include "xfs_inum.h"
  26. #include "xfs_trans.h"
  27. #include "xfs_sb.h"
  28. #include "xfs_ag.h"
  29. #include "xfs_dir2.h"
  30. #include "xfs_dmapi.h"
  31. #include "xfs_mount.h"
  32. #include "xfs_bmap_btree.h"
  33. #include "xfs_attr_sf.h"
  34. #include "xfs_dir2_sf.h"
  35. #include "xfs_vnode.h"
  36. #include "xfs_dinode.h"
  37. #include "xfs_inode.h"
  38. #include "xfs_itable.h"
  39. #include "xfs_error.h"
  40. #include "xfs_dfrag.h"
  41. #include "xfs_vnodeops.h"
  42. #include "xfs_fsops.h"
  43. #include "xfs_alloc.h"
  44. #include "xfs_rtalloc.h"
  45. #include "xfs_attr.h"
  46. #include "xfs_ioctl.h"
  47. #include "xfs_ioctl32.h"
  48. #define _NATIVE_IOC(cmd, type) \
  49. _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
  50. #ifdef BROKEN_X86_ALIGNMENT
  51. STATIC int
  52. xfs_compat_flock64_copyin(
  53. xfs_flock64_t *bf,
  54. compat_xfs_flock64_t __user *arg32)
  55. {
  56. if (get_user(bf->l_type, &arg32->l_type) ||
  57. get_user(bf->l_whence, &arg32->l_whence) ||
  58. get_user(bf->l_start, &arg32->l_start) ||
  59. get_user(bf->l_len, &arg32->l_len) ||
  60. get_user(bf->l_sysid, &arg32->l_sysid) ||
  61. get_user(bf->l_pid, &arg32->l_pid) ||
  62. copy_from_user(bf->l_pad, &arg32->l_pad, 4*sizeof(u32)))
  63. return -XFS_ERROR(EFAULT);
  64. return 0;
  65. }
  66. STATIC int
  67. xfs_compat_ioc_fsgeometry_v1(
  68. struct xfs_mount *mp,
  69. compat_xfs_fsop_geom_v1_t __user *arg32)
  70. {
  71. xfs_fsop_geom_t fsgeo;
  72. int error;
  73. error = xfs_fs_geometry(mp, &fsgeo, 3);
  74. if (error)
  75. return -error;
  76. /* The 32-bit variant simply has some padding at the end */
  77. if (copy_to_user(arg32, &fsgeo, sizeof(struct compat_xfs_fsop_geom_v1)))
  78. return -XFS_ERROR(EFAULT);
  79. return 0;
  80. }
  81. STATIC int
  82. xfs_compat_growfs_data_copyin(
  83. struct xfs_growfs_data *in,
  84. compat_xfs_growfs_data_t __user *arg32)
  85. {
  86. if (get_user(in->newblocks, &arg32->newblocks) ||
  87. get_user(in->imaxpct, &arg32->imaxpct))
  88. return -XFS_ERROR(EFAULT);
  89. return 0;
  90. }
  91. STATIC int
  92. xfs_compat_growfs_rt_copyin(
  93. struct xfs_growfs_rt *in,
  94. compat_xfs_growfs_rt_t __user *arg32)
  95. {
  96. if (get_user(in->newblocks, &arg32->newblocks) ||
  97. get_user(in->extsize, &arg32->extsize))
  98. return -XFS_ERROR(EFAULT);
  99. return 0;
  100. }
  101. STATIC int
  102. xfs_inumbers_fmt_compat(
  103. void __user *ubuffer,
  104. const xfs_inogrp_t *buffer,
  105. long count,
  106. long *written)
  107. {
  108. compat_xfs_inogrp_t __user *p32 = ubuffer;
  109. long i;
  110. for (i = 0; i < count; i++) {
  111. if (put_user(buffer[i].xi_startino, &p32[i].xi_startino) ||
  112. put_user(buffer[i].xi_alloccount, &p32[i].xi_alloccount) ||
  113. put_user(buffer[i].xi_allocmask, &p32[i].xi_allocmask))
  114. return -XFS_ERROR(EFAULT);
  115. }
  116. *written = count * sizeof(*p32);
  117. return 0;
  118. }
  119. #else
  120. #define xfs_inumbers_fmt_compat xfs_inumbers_fmt
  121. #endif /* BROKEN_X86_ALIGNMENT */
  122. STATIC int
  123. xfs_ioctl32_bstime_copyin(
  124. xfs_bstime_t *bstime,
  125. compat_xfs_bstime_t __user *bstime32)
  126. {
  127. compat_time_t sec32; /* tv_sec differs on 64 vs. 32 */
  128. if (get_user(sec32, &bstime32->tv_sec) ||
  129. get_user(bstime->tv_nsec, &bstime32->tv_nsec))
  130. return -XFS_ERROR(EFAULT);
  131. bstime->tv_sec = sec32;
  132. return 0;
  133. }
  134. /* xfs_bstat_t has differing alignment on intel, & bstime_t sizes everywhere */
  135. STATIC int
  136. xfs_ioctl32_bstat_copyin(
  137. xfs_bstat_t *bstat,
  138. compat_xfs_bstat_t __user *bstat32)
  139. {
  140. if (get_user(bstat->bs_ino, &bstat32->bs_ino) ||
  141. get_user(bstat->bs_mode, &bstat32->bs_mode) ||
  142. get_user(bstat->bs_nlink, &bstat32->bs_nlink) ||
  143. get_user(bstat->bs_uid, &bstat32->bs_uid) ||
  144. get_user(bstat->bs_gid, &bstat32->bs_gid) ||
  145. get_user(bstat->bs_rdev, &bstat32->bs_rdev) ||
  146. get_user(bstat->bs_blksize, &bstat32->bs_blksize) ||
  147. get_user(bstat->bs_size, &bstat32->bs_size) ||
  148. xfs_ioctl32_bstime_copyin(&bstat->bs_atime, &bstat32->bs_atime) ||
  149. xfs_ioctl32_bstime_copyin(&bstat->bs_mtime, &bstat32->bs_mtime) ||
  150. xfs_ioctl32_bstime_copyin(&bstat->bs_ctime, &bstat32->bs_ctime) ||
  151. get_user(bstat->bs_blocks, &bstat32->bs_size) ||
  152. get_user(bstat->bs_xflags, &bstat32->bs_size) ||
  153. get_user(bstat->bs_extsize, &bstat32->bs_extsize) ||
  154. get_user(bstat->bs_extents, &bstat32->bs_extents) ||
  155. get_user(bstat->bs_gen, &bstat32->bs_gen) ||
  156. get_user(bstat->bs_projid, &bstat32->bs_projid) ||
  157. get_user(bstat->bs_dmevmask, &bstat32->bs_dmevmask) ||
  158. get_user(bstat->bs_dmstate, &bstat32->bs_dmstate) ||
  159. get_user(bstat->bs_aextents, &bstat32->bs_aextents))
  160. return -XFS_ERROR(EFAULT);
  161. return 0;
  162. }
  163. /* XFS_IOC_FSBULKSTAT and friends */
  164. STATIC int
  165. xfs_bstime_store_compat(
  166. compat_xfs_bstime_t __user *p32,
  167. const xfs_bstime_t *p)
  168. {
  169. __s32 sec32;
  170. sec32 = p->tv_sec;
  171. if (put_user(sec32, &p32->tv_sec) ||
  172. put_user(p->tv_nsec, &p32->tv_nsec))
  173. return -XFS_ERROR(EFAULT);
  174. return 0;
  175. }
  176. /* Return 0 on success or positive error (to xfs_bulkstat()) */
  177. STATIC int
  178. xfs_bulkstat_one_fmt_compat(
  179. void __user *ubuffer,
  180. int ubsize,
  181. int *ubused,
  182. const xfs_bstat_t *buffer)
  183. {
  184. compat_xfs_bstat_t __user *p32 = ubuffer;
  185. if (ubsize < sizeof(*p32))
  186. return XFS_ERROR(ENOMEM);
  187. if (put_user(buffer->bs_ino, &p32->bs_ino) ||
  188. put_user(buffer->bs_mode, &p32->bs_mode) ||
  189. put_user(buffer->bs_nlink, &p32->bs_nlink) ||
  190. put_user(buffer->bs_uid, &p32->bs_uid) ||
  191. put_user(buffer->bs_gid, &p32->bs_gid) ||
  192. put_user(buffer->bs_rdev, &p32->bs_rdev) ||
  193. put_user(buffer->bs_blksize, &p32->bs_blksize) ||
  194. put_user(buffer->bs_size, &p32->bs_size) ||
  195. xfs_bstime_store_compat(&p32->bs_atime, &buffer->bs_atime) ||
  196. xfs_bstime_store_compat(&p32->bs_mtime, &buffer->bs_mtime) ||
  197. xfs_bstime_store_compat(&p32->bs_ctime, &buffer->bs_ctime) ||
  198. put_user(buffer->bs_blocks, &p32->bs_blocks) ||
  199. put_user(buffer->bs_xflags, &p32->bs_xflags) ||
  200. put_user(buffer->bs_extsize, &p32->bs_extsize) ||
  201. put_user(buffer->bs_extents, &p32->bs_extents) ||
  202. put_user(buffer->bs_gen, &p32->bs_gen) ||
  203. put_user(buffer->bs_projid, &p32->bs_projid) ||
  204. put_user(buffer->bs_dmevmask, &p32->bs_dmevmask) ||
  205. put_user(buffer->bs_dmstate, &p32->bs_dmstate) ||
  206. put_user(buffer->bs_aextents, &p32->bs_aextents))
  207. return XFS_ERROR(EFAULT);
  208. if (ubused)
  209. *ubused = sizeof(*p32);
  210. return 0;
  211. }
  212. STATIC int
  213. xfs_bulkstat_one_compat(
  214. xfs_mount_t *mp, /* mount point for filesystem */
  215. xfs_ino_t ino, /* inode number to get data for */
  216. void __user *buffer, /* buffer to place output in */
  217. int ubsize, /* size of buffer */
  218. void *private_data, /* my private data */
  219. xfs_daddr_t bno, /* starting bno of inode cluster */
  220. int *ubused, /* bytes used by me */
  221. void *dibuff, /* on-disk inode buffer */
  222. int *stat) /* BULKSTAT_RV_... */
  223. {
  224. return xfs_bulkstat_one_int(mp, ino, buffer, ubsize,
  225. xfs_bulkstat_one_fmt_compat, bno,
  226. ubused, dibuff, stat);
  227. }
  228. /* copied from xfs_ioctl.c */
  229. STATIC int
  230. xfs_compat_ioc_bulkstat(
  231. xfs_mount_t *mp,
  232. unsigned int cmd,
  233. compat_xfs_fsop_bulkreq_t __user *p32)
  234. {
  235. u32 addr;
  236. xfs_fsop_bulkreq_t bulkreq;
  237. int count; /* # of records returned */
  238. xfs_ino_t inlast; /* last inode number */
  239. int done;
  240. int error;
  241. /* done = 1 if there are more stats to get and if bulkstat */
  242. /* should be called again (unused here, but used in dmapi) */
  243. if (!capable(CAP_SYS_ADMIN))
  244. return -XFS_ERROR(EPERM);
  245. if (XFS_FORCED_SHUTDOWN(mp))
  246. return -XFS_ERROR(EIO);
  247. if (get_user(addr, &p32->lastip))
  248. return -XFS_ERROR(EFAULT);
  249. bulkreq.lastip = compat_ptr(addr);
  250. if (get_user(bulkreq.icount, &p32->icount) ||
  251. get_user(addr, &p32->ubuffer))
  252. return -XFS_ERROR(EFAULT);
  253. bulkreq.ubuffer = compat_ptr(addr);
  254. if (get_user(addr, &p32->ocount))
  255. return -XFS_ERROR(EFAULT);
  256. bulkreq.ocount = compat_ptr(addr);
  257. if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
  258. return -XFS_ERROR(EFAULT);
  259. if ((count = bulkreq.icount) <= 0)
  260. return -XFS_ERROR(EINVAL);
  261. if (bulkreq.ubuffer == NULL)
  262. return -XFS_ERROR(EINVAL);
  263. if (cmd == XFS_IOC_FSINUMBERS_32) {
  264. error = xfs_inumbers(mp, &inlast, &count,
  265. bulkreq.ubuffer, xfs_inumbers_fmt_compat);
  266. } else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE_32) {
  267. int res;
  268. error = xfs_bulkstat_one_compat(mp, inlast, bulkreq.ubuffer,
  269. sizeof(compat_xfs_bstat_t),
  270. NULL, 0, NULL, NULL, &res);
  271. } else if (cmd == XFS_IOC_FSBULKSTAT_32) {
  272. error = xfs_bulkstat(mp, &inlast, &count,
  273. xfs_bulkstat_one_compat, NULL,
  274. sizeof(compat_xfs_bstat_t), bulkreq.ubuffer,
  275. BULKSTAT_FG_QUICK, &done);
  276. } else
  277. error = XFS_ERROR(EINVAL);
  278. if (error)
  279. return -error;
  280. if (bulkreq.ocount != NULL) {
  281. if (copy_to_user(bulkreq.lastip, &inlast,
  282. sizeof(xfs_ino_t)))
  283. return -XFS_ERROR(EFAULT);
  284. if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
  285. return -XFS_ERROR(EFAULT);
  286. }
  287. return 0;
  288. }
  289. STATIC int
  290. xfs_compat_handlereq_copyin(
  291. xfs_fsop_handlereq_t *hreq,
  292. compat_xfs_fsop_handlereq_t __user *arg32)
  293. {
  294. compat_xfs_fsop_handlereq_t hreq32;
  295. if (copy_from_user(&hreq32, arg32, sizeof(compat_xfs_fsop_handlereq_t)))
  296. return -XFS_ERROR(EFAULT);
  297. hreq->fd = hreq32.fd;
  298. hreq->path = compat_ptr(hreq32.path);
  299. hreq->oflags = hreq32.oflags;
  300. hreq->ihandle = compat_ptr(hreq32.ihandle);
  301. hreq->ihandlen = hreq32.ihandlen;
  302. hreq->ohandle = compat_ptr(hreq32.ohandle);
  303. hreq->ohandlen = compat_ptr(hreq32.ohandlen);
  304. return 0;
  305. }
  306. /*
  307. * Convert userspace handle data into inode.
  308. *
  309. * We use the fact that all the fsop_handlereq ioctl calls have a data
  310. * structure argument whose first component is always a xfs_fsop_handlereq_t,
  311. * so we can pass that sub structure into this handy, shared routine.
  312. *
  313. * If no error, caller must always iput the returned inode.
  314. */
  315. STATIC int
  316. xfs_vget_fsop_handlereq_compat(
  317. xfs_mount_t *mp,
  318. struct inode *parinode, /* parent inode pointer */
  319. compat_xfs_fsop_handlereq_t *hreq,
  320. struct inode **inode)
  321. {
  322. void __user *hanp;
  323. size_t hlen;
  324. xfs_fid_t *xfid;
  325. xfs_handle_t *handlep;
  326. xfs_handle_t handle;
  327. xfs_inode_t *ip;
  328. xfs_ino_t ino;
  329. __u32 igen;
  330. int error;
  331. /*
  332. * Only allow handle opens under a directory.
  333. */
  334. if (!S_ISDIR(parinode->i_mode))
  335. return XFS_ERROR(ENOTDIR);
  336. hanp = compat_ptr(hreq->ihandle);
  337. hlen = hreq->ihandlen;
  338. handlep = &handle;
  339. if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep))
  340. return XFS_ERROR(EINVAL);
  341. if (copy_from_user(handlep, hanp, hlen))
  342. return XFS_ERROR(EFAULT);
  343. if (hlen < sizeof(*handlep))
  344. memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen);
  345. if (hlen > sizeof(handlep->ha_fsid)) {
  346. if (handlep->ha_fid.fid_len !=
  347. (hlen - sizeof(handlep->ha_fsid) -
  348. sizeof(handlep->ha_fid.fid_len)) ||
  349. handlep->ha_fid.fid_pad)
  350. return XFS_ERROR(EINVAL);
  351. }
  352. /*
  353. * Crack the handle, obtain the inode # & generation #
  354. */
  355. xfid = (struct xfs_fid *)&handlep->ha_fid;
  356. if (xfid->fid_len == sizeof(*xfid) - sizeof(xfid->fid_len)) {
  357. ino = xfid->fid_ino;
  358. igen = xfid->fid_gen;
  359. } else {
  360. return XFS_ERROR(EINVAL);
  361. }
  362. /*
  363. * Get the XFS inode, building a Linux inode to go with it.
  364. */
  365. error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
  366. if (error)
  367. return error;
  368. if (ip == NULL)
  369. return XFS_ERROR(EIO);
  370. if (ip->i_d.di_gen != igen) {
  371. xfs_iput_new(ip, XFS_ILOCK_SHARED);
  372. return XFS_ERROR(ENOENT);
  373. }
  374. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  375. *inode = VFS_I(ip);
  376. return 0;
  377. }
  378. STATIC int
  379. xfs_compat_attrlist_by_handle(
  380. xfs_mount_t *mp,
  381. void __user *arg,
  382. struct inode *parinode)
  383. {
  384. int error;
  385. attrlist_cursor_kern_t *cursor;
  386. compat_xfs_fsop_attrlist_handlereq_t al_hreq;
  387. struct inode *inode;
  388. char *kbuf;
  389. if (!capable(CAP_SYS_ADMIN))
  390. return -XFS_ERROR(EPERM);
  391. if (copy_from_user(&al_hreq, arg,
  392. sizeof(compat_xfs_fsop_attrlist_handlereq_t)))
  393. return -XFS_ERROR(EFAULT);
  394. if (al_hreq.buflen > XATTR_LIST_MAX)
  395. return -XFS_ERROR(EINVAL);
  396. /*
  397. * Reject flags, only allow namespaces.
  398. */
  399. if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE))
  400. return -XFS_ERROR(EINVAL);
  401. error = xfs_vget_fsop_handlereq_compat(mp, parinode, &al_hreq.hreq,
  402. &inode);
  403. if (error)
  404. goto out;
  405. kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
  406. if (!kbuf)
  407. goto out_vn_rele;
  408. cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
  409. error = xfs_attr_list(XFS_I(inode), kbuf, al_hreq.buflen,
  410. al_hreq.flags, cursor);
  411. if (error)
  412. goto out_kfree;
  413. if (copy_to_user(compat_ptr(al_hreq.buffer), kbuf, al_hreq.buflen))
  414. error = -EFAULT;
  415. out_kfree:
  416. kfree(kbuf);
  417. out_vn_rele:
  418. iput(inode);
  419. out:
  420. return -error;
  421. }
  422. STATIC int
  423. xfs_compat_attrmulti_by_handle(
  424. xfs_mount_t *mp,
  425. void __user *arg,
  426. struct inode *parinode)
  427. {
  428. int error;
  429. compat_xfs_attr_multiop_t *ops;
  430. compat_xfs_fsop_attrmulti_handlereq_t am_hreq;
  431. struct inode *inode;
  432. unsigned int i, size;
  433. char *attr_name;
  434. if (!capable(CAP_SYS_ADMIN))
  435. return -XFS_ERROR(EPERM);
  436. if (copy_from_user(&am_hreq, arg,
  437. sizeof(compat_xfs_fsop_attrmulti_handlereq_t)))
  438. return -XFS_ERROR(EFAULT);
  439. error = xfs_vget_fsop_handlereq_compat(mp, parinode, &am_hreq.hreq,
  440. &inode);
  441. if (error)
  442. goto out;
  443. error = E2BIG;
  444. size = am_hreq.opcount * sizeof(compat_xfs_attr_multiop_t);
  445. if (!size || size > 16 * PAGE_SIZE)
  446. goto out_vn_rele;
  447. error = ENOMEM;
  448. ops = kmalloc(size, GFP_KERNEL);
  449. if (!ops)
  450. goto out_vn_rele;
  451. error = EFAULT;
  452. if (copy_from_user(ops, compat_ptr(am_hreq.ops), size))
  453. goto out_kfree_ops;
  454. attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
  455. if (!attr_name)
  456. goto out_kfree_ops;
  457. error = 0;
  458. for (i = 0; i < am_hreq.opcount; i++) {
  459. ops[i].am_error = strncpy_from_user(attr_name,
  460. compat_ptr(ops[i].am_attrname),
  461. MAXNAMELEN);
  462. if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
  463. error = -ERANGE;
  464. if (ops[i].am_error < 0)
  465. break;
  466. switch (ops[i].am_opcode) {
  467. case ATTR_OP_GET:
  468. ops[i].am_error = xfs_attrmulti_attr_get(inode,
  469. attr_name,
  470. compat_ptr(ops[i].am_attrvalue),
  471. &ops[i].am_length, ops[i].am_flags);
  472. break;
  473. case ATTR_OP_SET:
  474. ops[i].am_error = xfs_attrmulti_attr_set(inode,
  475. attr_name,
  476. compat_ptr(ops[i].am_attrvalue),
  477. ops[i].am_length, ops[i].am_flags);
  478. break;
  479. case ATTR_OP_REMOVE:
  480. ops[i].am_error = xfs_attrmulti_attr_remove(inode,
  481. attr_name, ops[i].am_flags);
  482. break;
  483. default:
  484. ops[i].am_error = EINVAL;
  485. }
  486. }
  487. if (copy_to_user(compat_ptr(am_hreq.ops), ops, size))
  488. error = XFS_ERROR(EFAULT);
  489. kfree(attr_name);
  490. out_kfree_ops:
  491. kfree(ops);
  492. out_vn_rele:
  493. iput(inode);
  494. out:
  495. return -error;
  496. }
  497. STATIC int
  498. xfs_compat_fssetdm_by_handle(
  499. xfs_mount_t *mp,
  500. void __user *arg,
  501. struct inode *parinode)
  502. {
  503. int error;
  504. struct fsdmidata fsd;
  505. compat_xfs_fsop_setdm_handlereq_t dmhreq;
  506. struct inode *inode;
  507. if (!capable(CAP_MKNOD))
  508. return -XFS_ERROR(EPERM);
  509. if (copy_from_user(&dmhreq, arg,
  510. sizeof(compat_xfs_fsop_setdm_handlereq_t)))
  511. return -XFS_ERROR(EFAULT);
  512. error = xfs_vget_fsop_handlereq_compat(mp, parinode, &dmhreq.hreq,
  513. &inode);
  514. if (error)
  515. return -error;
  516. if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
  517. error = -XFS_ERROR(EPERM);
  518. goto out;
  519. }
  520. if (copy_from_user(&fsd, compat_ptr(dmhreq.data), sizeof(fsd))) {
  521. error = -XFS_ERROR(EFAULT);
  522. goto out;
  523. }
  524. error = -xfs_set_dmattrs(XFS_I(inode), fsd.fsd_dmevmask,
  525. fsd.fsd_dmstate);
  526. out:
  527. iput(inode);
  528. return error;
  529. }
  530. long
  531. xfs_file_compat_ioctl(
  532. struct file *filp,
  533. unsigned cmd,
  534. unsigned long p)
  535. {
  536. struct inode *inode = filp->f_path.dentry->d_inode;
  537. struct xfs_inode *ip = XFS_I(inode);
  538. struct xfs_mount *mp = ip->i_mount;
  539. void __user *arg = (void __user *)p;
  540. int ioflags = 0;
  541. int error;
  542. if (filp->f_mode & FMODE_NOCMTIME)
  543. ioflags |= IO_INVIS;
  544. xfs_itrace_entry(ip);
  545. switch (cmd) {
  546. /* No size or alignment issues on any arch */
  547. case XFS_IOC_DIOINFO:
  548. case XFS_IOC_FSGEOMETRY:
  549. case XFS_IOC_FSGETXATTR:
  550. case XFS_IOC_FSSETXATTR:
  551. case XFS_IOC_FSGETXATTRA:
  552. case XFS_IOC_FSSETDM:
  553. case XFS_IOC_GETBMAP:
  554. case XFS_IOC_GETBMAPA:
  555. case XFS_IOC_GETBMAPX:
  556. case XFS_IOC_FSCOUNTS:
  557. case XFS_IOC_SET_RESBLKS:
  558. case XFS_IOC_GET_RESBLKS:
  559. case XFS_IOC_FSGROWFSLOG:
  560. case XFS_IOC_FREEZE:
  561. case XFS_IOC_THAW:
  562. case XFS_IOC_GOINGDOWN:
  563. case XFS_IOC_ERROR_INJECTION:
  564. case XFS_IOC_ERROR_CLEARALL:
  565. return xfs_file_ioctl(filp, cmd, p);
  566. #ifndef BROKEN_X86_ALIGNMENT
  567. /* These are handled fine if no alignment issues */
  568. case XFS_IOC_ALLOCSP:
  569. case XFS_IOC_FREESP:
  570. case XFS_IOC_RESVSP:
  571. case XFS_IOC_UNRESVSP:
  572. case XFS_IOC_ALLOCSP64:
  573. case XFS_IOC_FREESP64:
  574. case XFS_IOC_RESVSP64:
  575. case XFS_IOC_UNRESVSP64:
  576. case XFS_IOC_FSGEOMETRY_V1:
  577. case XFS_IOC_FSGROWFSDATA:
  578. case XFS_IOC_FSGROWFSRT:
  579. return xfs_file_ioctl(filp, cmd, p);
  580. #else
  581. case XFS_IOC_ALLOCSP_32:
  582. case XFS_IOC_FREESP_32:
  583. case XFS_IOC_ALLOCSP64_32:
  584. case XFS_IOC_FREESP64_32:
  585. case XFS_IOC_RESVSP_32:
  586. case XFS_IOC_UNRESVSP_32:
  587. case XFS_IOC_RESVSP64_32:
  588. case XFS_IOC_UNRESVSP64_32: {
  589. struct xfs_flock64 bf;
  590. if (xfs_compat_flock64_copyin(&bf, arg))
  591. return -XFS_ERROR(EFAULT);
  592. cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
  593. return xfs_ioc_space(ip, inode, filp, ioflags, cmd, &bf);
  594. }
  595. case XFS_IOC_FSGEOMETRY_V1_32:
  596. return xfs_compat_ioc_fsgeometry_v1(mp, arg);
  597. case XFS_IOC_FSGROWFSDATA_32: {
  598. struct xfs_growfs_data in;
  599. if (xfs_compat_growfs_data_copyin(&in, arg))
  600. return -XFS_ERROR(EFAULT);
  601. error = xfs_growfs_data(mp, &in);
  602. return -error;
  603. }
  604. case XFS_IOC_FSGROWFSRT_32: {
  605. struct xfs_growfs_rt in;
  606. if (xfs_compat_growfs_rt_copyin(&in, arg))
  607. return -XFS_ERROR(EFAULT);
  608. error = xfs_growfs_rt(mp, &in);
  609. return -error;
  610. }
  611. #endif
  612. /* long changes size, but xfs only copiese out 32 bits */
  613. case XFS_IOC_GETXFLAGS_32:
  614. case XFS_IOC_SETXFLAGS_32:
  615. case XFS_IOC_GETVERSION_32:
  616. cmd = _NATIVE_IOC(cmd, long);
  617. return xfs_file_ioctl(filp, cmd, p);
  618. case XFS_IOC_SWAPEXT: {
  619. struct xfs_swapext sxp;
  620. struct compat_xfs_swapext __user *sxu = arg;
  621. /* Bulk copy in up to the sx_stat field, then copy bstat */
  622. if (copy_from_user(&sxp, sxu,
  623. offsetof(struct xfs_swapext, sx_stat)) ||
  624. xfs_ioctl32_bstat_copyin(&sxp.sx_stat, &sxu->sx_stat))
  625. return -XFS_ERROR(EFAULT);
  626. error = xfs_swapext(&sxp);
  627. return -error;
  628. }
  629. case XFS_IOC_FSBULKSTAT_32:
  630. case XFS_IOC_FSBULKSTAT_SINGLE_32:
  631. case XFS_IOC_FSINUMBERS_32:
  632. return xfs_compat_ioc_bulkstat(mp, cmd, arg);
  633. case XFS_IOC_FD_TO_HANDLE_32:
  634. case XFS_IOC_PATH_TO_HANDLE_32:
  635. case XFS_IOC_PATH_TO_FSHANDLE_32: {
  636. struct xfs_fsop_handlereq hreq;
  637. if (xfs_compat_handlereq_copyin(&hreq, arg))
  638. return -XFS_ERROR(EFAULT);
  639. cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq);
  640. return xfs_find_handle(cmd, &hreq);
  641. }
  642. case XFS_IOC_OPEN_BY_HANDLE_32: {
  643. struct xfs_fsop_handlereq hreq;
  644. if (xfs_compat_handlereq_copyin(&hreq, arg))
  645. return -XFS_ERROR(EFAULT);
  646. return xfs_open_by_handle(mp, &hreq, filp, inode);
  647. }
  648. case XFS_IOC_READLINK_BY_HANDLE_32: {
  649. struct xfs_fsop_handlereq hreq;
  650. if (xfs_compat_handlereq_copyin(&hreq, arg))
  651. return -XFS_ERROR(EFAULT);
  652. return xfs_readlink_by_handle(mp, &hreq, inode);
  653. }
  654. case XFS_IOC_ATTRLIST_BY_HANDLE_32:
  655. return xfs_compat_attrlist_by_handle(mp, arg, inode);
  656. case XFS_IOC_ATTRMULTI_BY_HANDLE_32:
  657. return xfs_compat_attrmulti_by_handle(mp, arg, inode);
  658. case XFS_IOC_FSSETDM_BY_HANDLE_32:
  659. return xfs_compat_fssetdm_by_handle(mp, arg, inode);
  660. default:
  661. return -XFS_ERROR(ENOIOCTLCMD);
  662. }
  663. }