xfs ioctl handler cleanups
Hi all,
I've been annoyed at the KASAN stack usage warnings in xfs_file_ioctl again recently, so let's sort this out properly by splitting each ioctl handler into a separate, well-named helper. We already do that for most, but this series completes it.
PATCH 1/16 xfs: remove an outdated comment above xfs_file_ioctl
The return code sign flipping at the method boundary is long gone in XFS, so remove this comment documenting an exception from it.
--- fs/xfs/xfs_ioctl.c | 6 ------ 1 file changed, 6 deletions(-)
fs/xfs/xfs_ioctl.c +0 -6
@@ -1209,12 +1209,6 @@ xfs_ioctl_fs_counts(#define XFS_IOC_ALLOCSP64 _IOW ('X', 36, struct xfs_flock64)#define XFS_IOC_FREESP64 _IOW ('X', 37, struct xfs_flock64) -/* -* Note: some of the ioctl's return positive numbers as a -* byte count indicating success, such as readlink_by_handle. -* So we don't "sign flip" like most other routines. This means -* true errors need to be returned as a negative value. -*/ long xfs_file_ioctl( struct file *filp,
Signature · 1 line
2.53.0
Re: [PATCH 01/16] xfs: remove an outdated comment above xfs_file_ioctl
Quoted 4 lines · Christoph Hellwig
The return code sign flipping at the method boundary is long gone in XFS, so remove this comment documenting an exception from it.
Applied to for-next, thanks!
[01/16] xfs: remove an outdated comment above xfs_file_ioctl
commit: d7cf5c006dc3fcc9171939da88fcf6539d37bca5
[02/16] xfs: rename xfs_ioc_swapext to xfs_swapext
commit: fbbf446c322a5e20aa6ecdfacf02b9446df4800d
[03/16] xfs: rename xfs_ioctl_fs_counts to xfs_ioc_fs_counts
commit: 098a0ee1b45f0f09d77b517a9e34ecdada13c9aa
[04/16] xfs: rename xfs_ioctl_getset_resblocks to xfs_ioc_getset_resblocks
commit: 6c015db4e9d9bf562a1dda59f71dbb7822c0e4e4
[05/16] xfs: split out the handler for XFS_IOC_DIOINFO
commit: 4b18c2835c83f9002484d3af8362b31d0d374eae
[06/16] xfs: split out the handlers for XFS_IOC_.*HANDLE
commit: 80e352a27758e0666a63c85feeb3277466853a1e
[07/16] xfs: split out the handler for XFS_IOC_SWAPEXT
commit: 45af54ac546a39f0fb40a6332cd4b71170b72e41
[08/16] xfs: split out the handlers for XFS_IOC_FSGROWFS*
commit: 7c98c4461679b22639f72207b8a917c6af516402
[09/16] xfs: split out the handler for XFS_IOC_GOINGDOWN
commit: 319acdc8b39e6a4563e273a7710977caca184061
[10/16] xfs: split out the handler for XFS_IOC_ERROR_INJECTION
commit: a443db96c14b617647e4465fa612162256be39ef
[11/16] xfs: split out the handler for XFS_IOC_FREE_EOFBLOCKS
commit: 2b7755e216c7be0f3ac6e74ad3778b90afea8c4c
[12/16] xfs: split out the handlers for XFS_IOC_FSGROWFS_*_32
commit: 3368d51225e86fb58a527e2d216653194cb6d009
[13/16] xfs: cleanup XFS_IOC_GETVERSION_32 handling
commit: b193b5f5b12402ddcd77a3208743fecc91c0cb0e
[14/16] xfs: split out the handlers for XFS_IOC_SWAPEXT_32
commit: af563225303d1c747db0edeb14b28172b23d767e
[15/16] xfs: split out the handlers for XFS_IOC_*_BY_HANDLE_32
commit: 490ada21265049883c3f64f825df3798bd4a655d
[16/16] xfs: remove an extra cast in xfs_file_compat_ioctl
commit: 0a57de878fcceb65abd67947ddd053ac6b9d573bBest regards,
Signature · 1 line
Carlos Maiolino <[email protected]>
PATCH 2/16 xfs: rename xfs_ioc_swapext to xfs_swapext
In reply to Christoph HellwigThe usual convention is that the ioc_ prefix is used for direct ioctl handlers that take a user pointer. The current xfs_ioc_swapext does not fit that pattern, so rename it.
--- fs/xfs/xfs_ioctl.c | 8 ++++---- fs/xfs/xfs_ioctl.h | 4 +--- fs/xfs/xfs_ioctl32.c | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-)
fs/xfs/xfs_ioctl.c +4 -4
@@ -962,10 +962,10 @@ xfs_ioc_getbmap( }int -xfs_ioc_swapext ( -xfs_swapext_t *sxp) +xfs_swapext ( +struct xfs_swapext *sxp) { -xfs_inode_t *ip, *tip; +struct xfs_inode *ip, *tip;/* Pull information for the target fd */ CLASS (fd, f)((int )sxp->sx_fdtarget);
@@ -1341,7 +1341,7 @@ xfs_file_ioctl( error =mnt_want_write_file (filp);if (error)return error; - error =xfs_ioc_swapext (&sxp); + error =xfs_swapext (&sxp);mnt_drop_write_file (filp);return error; }
fs/xfs/xfs_ioctl.h +1 -3
@@ -10,9 +10,7 @@ struct xfs_bstat;struct xfs_ibulk ;struct xfs_inogrp ; -int -xfs_ioc_swapext ( -xfs_swapext_t *sxp); +int xfs_swapext (struct xfs_swapext *sxp);extern int xfs_fileattr_get(
fs/xfs/xfs_ioctl32.c +1 -1
@@ -475,7 +475,7 @@ xfs_file_compat_ioctl( error =mnt_want_write_file (filp);if (error)return error; - error =xfs_ioc_swapext (&sxp); + error =xfs_swapext (&sxp);mnt_drop_write_file (filp);return error; }
Signature · 1 line
2.53.0
PATCH 3/16 xfs: rename xfs_ioctl_fs_counts to xfs_ioc_fs_counts
In reply to Christoph HellwigMatch the naming scheme of most other ioctl handlers.
--- fs/xfs/xfs_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_ioctl.c +2 -2
@@ -1183,7 +1183,7 @@ xfs_ioctl_getset_resblocks( }static int -xfs_ioctl_fs_counts ( +xfs_ioc_fs_counts (struct xfs_mount *mp,struct xfs_fsop_counts __user *uarg) {
@@ -1347,7 +1347,7 @@ xfs_file_ioctl( }case XFS_IOC_FSCOUNTS : -return xfs_ioctl_fs_counts (mp, arg); +return xfs_ioc_fs_counts (mp, arg);case XFS_IOC_SET_RESBLKS :case XFS_IOC_GET_RESBLKS :
Signature · 1 line
2.53.0
PATCH 4/16 xfs: rename xfs_ioctl_getset_resblocks to xfs_ioc_getset_resblocks
In reply to Christoph HellwigMatch the naming scheme of most other ioctl handlers.
--- fs/xfs/xfs_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_ioctl.c +2 -2
@@ -1144,7 +1144,7 @@ xfs_fs_eofblocks_from_user( }static int -xfs_ioctl_getset_resblocks ( +xfs_ioc_getset_resblocks (struct file *filp,unsigned int cmd,void __user *arg)
@@ -1351,7 +1351,7 @@ xfs_file_ioctl(case XFS_IOC_SET_RESBLKS :case XFS_IOC_GET_RESBLKS : -return xfs_ioctl_getset_resblocks (filp, cmd, arg); +return xfs_ioc_getset_resblocks (filp, cmd, arg);case XFS_IOC_FSGROWFSDATA : {struct xfs_growfs_data in;
Signature · 1 line
2.53.0
PATCH 5/16 xfs: split out the handler for XFS_IOC_DIOINFO
In reply to Christoph HellwigSplit out a helper for XFS_IOC_DIOINFO to keep the stack variables out of xfs_file_ioctl and to clean up the main ioctl handler flow.
--- fs/xfs/xfs_ioctl.c | 47 +++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)
fs/xfs/xfs_ioctl.c +28 -19
@@ -1200,6 +1200,32 @@ xfs_ioc_fs_counts(return 0 ; } +static int +xfs_ioc_dioinfo ( +struct file *file, +void __user *arg) +{ +struct kstat st; +struct dioattr da; +int error; + + error =vfs_getattr (&file->f_path, &st,STATX_DIOALIGN ,0 ); +if (error) +return error; + +/* +* Some userspace directly feeds the return value to posix_memalign, +* which fails for values that are smaller than the pointer size. +* Round up the value to not break userspace. +*/ + da.d_mem =roundup (st.dio_mem_align,sizeof (void *)); + da.d_miniosz = st.dio_offset_align; + da.d_maxiosz =INT_MAX & ~(da.d_miniosz -1 ); +if (copy_to_user (arg, &da,sizeof (da))) +return -EFAULT ; +return 0 ; +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them.
@@ -1238,26 +1264,9 @@ xfs_file_ioctl("%s should use fallocate; XFS_IOC_{ALLOC,FREE}SP ioctl unsupported" , current->comm);return -ENOTTY ; -case XFS_IOC_DIOINFO : { -struct kstat st; -struct dioattr da; - - error =vfs_getattr (&filp->f_path, &st,STATX_DIOALIGN ,0 ); -if (error) -return error; -/* -* Some userspace directly feeds the return value to -* posix_memalign, which fails for values that are smaller than -* the pointer size. Round up the value to not break userspace. -*/ - da.d_mem =roundup (st.dio_mem_align,sizeof (void *)); - da.d_miniosz = st.dio_offset_align; - da.d_maxiosz =INT_MAX & ~(da.d_miniosz -1 ); -if (copy_to_user (arg, &da,sizeof (da))) -return -EFAULT ; -return 0 ; - } +case XFS_IOC_DIOINFO : +return xfs_ioc_dioinfo (filp, arg);case XFS_IOC_FSBULKSTAT_SINGLE :case XFS_IOC_FSBULKSTAT :
Signature · 1 line
2.53.0
PATCH 6/16 xfs: split out the handlers for XFS_IOC_.*HANDLE
In reply to Christoph HellwigSplit out helpers for XFS_IOC_.*HANDLE to keep the stack variables out of xfs_file_ioctl and to clean up the main ioctl handler flow.
--- fs/xfs/xfs_ioctl.c | 65 ++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 23 deletions(-)
fs/xfs/xfs_ioctl.c +42 -23
@@ -1226,6 +1226,42 @@ xfs_ioc_dioinfo(return 0 ; } +static int +xfs_ioc_find_handle ( +unsigned int cmd, +void __user *arg) +{ +struct xfs_fsop_handlereq hreq; + +if (copy_from_user (&hreq, arg,sizeof (hreq))) +return -EFAULT ; +return xfs_find_handle (cmd, &hreq); +} + +static int +xfs_ioc_open_by_handle ( +struct file *file, +void __user *arg) +{ +struct xfs_fsop_handlereq hreq; + +if (copy_from_user (&hreq, arg,sizeof (hreq))) +return -EFAULT ; +return xfs_open_by_handle (file, &hreq); +} + +static int +xfs_ioc_readlink_by_handle ( +struct file *file, +void __user *arg) +{ +struct xfs_fsop_handlereq hreq; + +if (copy_from_user (&hreq, arg,sizeof (hreq))) +return -EFAULT ; +return xfs_readlink_by_handle (file, &hreq); +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them.
@@ -1314,31 +1350,14 @@ xfs_file_ioctl(case XFS_IOC_FD_TO_HANDLE :case XFS_IOC_PATH_TO_HANDLE : -case XFS_IOC_PATH_TO_FSHANDLE : { -xfs_fsop_handlereq_t hreq; - -if (copy_from_user (&hreq, arg,sizeof (hreq))) -return -EFAULT ; -return xfs_find_handle (cmd, &hreq); - } -case XFS_IOC_OPEN_BY_HANDLE : { -xfs_fsop_handlereq_t hreq; - -if (copy_from_user (&hreq, arg,sizeof (xfs_fsop_handlereq_t))) -return -EFAULT ; -return xfs_open_by_handle (filp, &hreq); - } - -case XFS_IOC_READLINK_BY_HANDLE : { -xfs_fsop_handlereq_t hreq; - -if (copy_from_user (&hreq, arg,sizeof (xfs_fsop_handlereq_t))) -return -EFAULT ; -return xfs_readlink_by_handle (filp, &hreq); - } +case XFS_IOC_PATH_TO_FSHANDLE : +return xfs_ioc_find_handle (cmd, arg); +case XFS_IOC_OPEN_BY_HANDLE : +return xfs_ioc_open_by_handle (filp, arg); +case XFS_IOC_READLINK_BY_HANDLE : +return xfs_ioc_readlink_by_handle (filp, arg);case XFS_IOC_ATTRLIST_BY_HANDLE :return xfs_attrlist_by_handle (filp, arg); -case XFS_IOC_ATTRMULTI_BY_HANDLE :return xfs_attrmulti_by_handle (filp, arg);
Signature · 1 line
2.53.0
PATCH 7/16 xfs: split out the handler for XFS_IOC_SWAPEXT
In reply to Christoph HellwigSplit out a helper for XFS_IOC_SWAPEXT to keep the stack variables out of xfs_file_ioctl and to clean up the main ioctl handler flow.
--- fs/xfs/xfs_ioctl.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-)
fs/xfs/xfs_ioctl.c +21 -12
@@ -1262,6 +1262,25 @@ xfs_ioc_readlink_by_handle(return xfs_readlink_by_handle (file, &hreq); } +static int +xfs_ioc_swapext ( +struct file *file, +void __user *arg) +{ +struct xfs_swapext sxp; +int error; + +if (copy_from_user (&sxp, arg,sizeof (sxp))) +return -EFAULT ; + + error =mnt_want_write_file (file); +if (error) +return error; + error =xfs_swapext (&sxp); +mnt_drop_write_file (file); +return error; +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them.
@@ -1361,18 +1380,8 @@ xfs_file_ioctl(case XFS_IOC_ATTRMULTI_BY_HANDLE :return xfs_attrmulti_by_handle (filp, arg); -case XFS_IOC_SWAPEXT : { -struct xfs_swapext sxp; - -if (copy_from_user (&sxp, arg,sizeof (xfs_swapext_t))) -return -EFAULT ; - error =mnt_want_write_file (filp); -if (error) -return error; - error =xfs_swapext (&sxp); -mnt_drop_write_file (filp); -return error; - } +case XFS_IOC_SWAPEXT : +return xfs_ioc_swapext (filp, arg);case XFS_IOC_FSCOUNTS :return xfs_ioc_fs_counts (mp, arg);
Signature · 1 line
2.53.0
PATCH 8/16 xfs: split out the handlers for XFS_IOC_FSGROWFS*
In reply to Christoph HellwigSplit out helpers for XFS_IOC_FSGROWFS* to keep the stack variables out of xfs_file_ioctl and to clean up the main ioctl handler flow.
--- fs/xfs/xfs_ioctl.c | 107 ++++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 41 deletions(-)
fs/xfs/xfs_ioctl.c +66 -41
@@ -1281,6 +1281,66 @@ xfs_ioc_swapext(return error; } +static int +xfs_ioc_growfs_data ( +struct file *file, +struct xfs_mount *mp, +void __user *arg) +{ +struct xfs_growfs_data in; +int error; + +if (copy_from_user (&in, arg,sizeof (in))) +return -EFAULT ; + + error =mnt_want_write_file (file); +if (error) +return error; + error =xfs_growfs_data (mp, &in); +mnt_drop_write_file (file); +return error; +} + +static int +xfs_ioc_growfs_log ( +struct file *file, +struct xfs_mount *mp, +void __user *arg) +{ +struct xfs_growfs_log in; +int error; + +if (copy_from_user (&in, arg,sizeof (in))) +return -EFAULT ; + + error =mnt_want_write_file (file); +if (error) +return error; + error =xfs_growfs_log (mp, &in); +mnt_drop_write_file (file); +return error; +} + +static int +xfs_ioc_growfs_rt ( +struct file *file, +struct xfs_mount *mp, +void __user *arg) +{ +struct xfs_growfs_rt in; +int error; + +if (copy_from_user (&in, arg,sizeof (in))) +return -EFAULT ; + + error =mnt_want_write_file (file); +if (error) +return error; + error =xfs_growfs_rt (mp, &in); +mnt_drop_write_file (file); +return error; +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them.
@@ -1390,47 +1450,12 @@ xfs_file_ioctl(case XFS_IOC_GET_RESBLKS :return xfs_ioc_getset_resblocks (filp, cmd, arg); -case XFS_IOC_FSGROWFSDATA : { -struct xfs_growfs_data in; - -if (copy_from_user (&in, arg,sizeof (in))) -return -EFAULT ; - - error =mnt_want_write_file (filp); -if (error) -return error; - error =xfs_growfs_data (mp, &in); -mnt_drop_write_file (filp); -return error; - } - -case XFS_IOC_FSGROWFSLOG : { -struct xfs_growfs_log in; - -if (copy_from_user (&in, arg,sizeof (in))) -return -EFAULT ; - - error =mnt_want_write_file (filp); -if (error) -return error; - error =xfs_growfs_log (mp, &in); -mnt_drop_write_file (filp); -return error; - } - -case XFS_IOC_FSGROWFSRT : { -xfs_growfs_rt_t in; - -if (copy_from_user (&in, arg,sizeof (in))) -return -EFAULT ; - - error =mnt_want_write_file (filp); -if (error) -return error; - error =xfs_growfs_rt (mp, &in); -mnt_drop_write_file (filp); -return error; - } +case XFS_IOC_FSGROWFSDATA : +return xfs_ioc_growfs_data (filp, mp, arg); +case XFS_IOC_FSGROWFSLOG : +return xfs_ioc_growfs_log (filp, mp, arg); +case XFS_IOC_FSGROWFSRT : +return xfs_ioc_growfs_rt (filp, mp, arg);case XFS_IOC_GOINGDOWN : {uint32_t in;
Signature · 1 line
2.53.0
PATCH 9/16 xfs: split out the handler for XFS_IOC_GOINGDOWN
In reply to Christoph HellwigSplit out a helper for XFS_IOC_GOINGDOWN to keep the stack variables out of xfs_file_ioctl and to clean up the main ioctl handler flow.
--- fs/xfs/xfs_ioctl.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
fs/xfs/xfs_ioctl.c +16 -12
@@ -1341,6 +1341,20 @@ xfs_ioc_growfs_rt(return error; } +static int +xfs_ioc_goingdown ( +struct xfs_mount *mp, +uint32_t __user *arg) +{ +uint32_t in; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; +if (get_user (in, arg)) +return -EFAULT ; +return xfs_fs_goingdown (mp, in); +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them.
@@ -1457,18 +1471,8 @@ xfs_file_ioctl(case XFS_IOC_FSGROWFSRT :return xfs_ioc_growfs_rt (filp, mp, arg); -case XFS_IOC_GOINGDOWN : { -uint32_t in; - -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; - -if (get_user (in, (uint32_t __user *)arg)) -return -EFAULT ; - -return xfs_fs_goingdown (mp, in); - } - +case XFS_IOC_GOINGDOWN : +return xfs_ioc_goingdown (mp, arg);case XFS_IOC_ERROR_INJECTION : {xfs_error_injection_t in;
Signature · 1 line
2.53.0
PATCH 10/16 xfs: split out the handler for XFS_IOC_ERROR_INJECTION
In reply to Christoph HellwigSplit out a helper for XFS_IOC_ERROR_INJECTION to keep the stack variables out of xfs_file_ioctl and to clean up the main ioctl handler flow.
--- fs/xfs/xfs_ioctl.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
fs/xfs/xfs_ioctl.c +16 -13
@@ -1355,6 +1355,20 @@ xfs_ioc_goingdown(return xfs_fs_goingdown (mp, in); } +static int +xfs_ioc_error_injection ( +struct xfs_mount *mp, +struct xfs_error_injection __user *arg) +{ +struct xfs_error_injection in; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; +if (copy_from_user (&in, arg,sizeof (in))) +return -EFAULT ; +return xfs_errortag_add (mp, in.errtag); +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them.
@@ -1473,22 +1487,11 @@ xfs_file_ioctl(case XFS_IOC_GOINGDOWN :return xfs_ioc_goingdown (mp, arg); -case XFS_IOC_ERROR_INJECTION : { -xfs_error_injection_t in; - -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; - -if (copy_from_user (&in, arg,sizeof (in))) -return -EFAULT ; - -return xfs_errortag_add (mp, in.errtag); - } - +case XFS_IOC_ERROR_INJECTION : +return xfs_ioc_error_injection (mp, arg);case XFS_IOC_ERROR_CLEARALL :if (!capable (CAP_SYS_ADMIN ))return -EPERM ; -return xfs_errortag_clearall (mp);case XFS_IOC_FREE_EOFBLOCKS : {
Signature · 1 line
2.53.0
PATCH 11/16 xfs: split out the handler for XFS_IOC_FREE_EOFBLOCKS
In reply to Christoph HellwigSplit out a helper for XFS_IOC_FREE_EOFBLOCKS to keep the stack variables out of xfs_file_ioctl and to clean up the main ioctl handler flow.
--- fs/xfs/xfs_ioctl.c | 52 ++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 23 deletions(-)
fs/xfs/xfs_ioctl.c +29 -23
@@ -1369,6 +1369,33 @@ xfs_ioc_error_injection(return xfs_errortag_add (mp, in.errtag); } +static int +xfs_ioc_free_eofblocks ( +struct xfs_mount *mp, +struct xfs_fs_eofblocks __user *arg) +{ +struct xfs_fs_eofblocks eofb; +struct xfs_icwalk icw; +int error; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; +if (xfs_is_readonly (mp)) +return -EROFS ; + +if (copy_from_user (&eofb, arg,sizeof (eofb))) +return -EFAULT ; + + error =xfs_fs_eofblocks_from_user (&eofb, &icw); +if (error) +return error; + +trace_xfs_ioc_free_eofblocks (mp, &icw, _RET_IP_); + +guard (super_write)(mp->m_super); +return xfs_blockgc_free_space (mp, &icw); +} +/* * These long-unused ioctls were removed from the official ioctl API in 5.17, * but retain these definitions so that we can log warnings about them.
@@ -1388,7 +1415,6 @@ xfs_file_ioctl(struct xfs_inode *ip =XFS_I (inode);struct xfs_mount *mp = ip->i_mount;void __user *arg = (void __user *)p; -int error;trace_xfs_file_ioctl (ip);
@@ -1494,28 +1520,8 @@ xfs_file_ioctl(return -EPERM ;return xfs_errortag_clearall (mp); -case XFS_IOC_FREE_EOFBLOCKS : { -struct xfs_fs_eofblocks eofb; -struct xfs_icwalk icw; - -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; - -if (xfs_is_readonly (mp)) -return -EROFS ; - -if (copy_from_user (&eofb, arg,sizeof (eofb))) -return -EFAULT ; - - error =xfs_fs_eofblocks_from_user (&eofb, &icw); -if (error) -return error; - -trace_xfs_ioc_free_eofblocks (mp, &icw, _RET_IP_); - -guard (super_write)(mp->m_super); -return xfs_blockgc_free_space (mp, &icw); - } +case XFS_IOC_FREE_EOFBLOCKS : +return xfs_ioc_free_eofblocks (mp, arg);case XFS_IOC_EXCHANGE_RANGE :return xfs_ioc_exchange_range (filp, arg);
Signature · 1 line
2.53.0
PATCH 12/16 xfs: split out the handlers for XFS_IOC_FSGROWFS_*_32
In reply to Christoph HellwigSplit out helpers for XFS_IOC_FSGROWFS_*_32 to keep the stack variables out of xfs_file_compat_ioctl and to clean up the main compat ioctl handler flow.
--- fs/xfs/xfs_ioctl32.c | 76 ++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 38 deletions(-)
fs/xfs/xfs_ioctl32.c +38 -38
@@ -44,26 +44,46 @@ xfs_compat_ioc_fsgeometry_v1(return 0 ; } -STATIC int -xfs_compat_growfs_data_copyin ( -struct xfs_growfs_data *in, -compat_xfs_growfs_data_t __user *arg32) +static int +xfs_compat_ioc_growfs_data ( +struct file *file, +struct xfs_mount *mp, +struct compat_xfs_growfs_data __user *arg32) { -if (get_user (in->newblocks, &arg32->newblocks) || -get_user (in->imaxpct, &arg32->imaxpct)) +struct xfs_growfs_data in = { }; +int error; + +if (get_user (in.newblocks, &arg32->newblocks) || +get_user (in.imaxpct, &arg32->imaxpct))return -EFAULT ; -return 0 ; + + error =mnt_want_write_file (file); +if (error) +return error; + error =xfs_growfs_data (mp, &in); +mnt_drop_write_file (file); +return error; } -STATIC int -xfs_compat_growfs_rt_copyin ( -struct xfs_growfs_rt *in, -compat_xfs_growfs_rt_t __user *arg32) +static int +xfs_compat_ioc_growfs_rt ( +struct file *file, +struct xfs_mount *mp, +struct compat_xfs_growfs_rt __user *arg32) { -if (get_user (in->newblocks, &arg32->newblocks) || -get_user (in->extsize, &arg32->extsize)) +struct xfs_growfs_rt in = {}; +int error; + +if (get_user (in.newblocks, &arg32->newblocks) || +get_user (in.extsize, &arg32->extsize))return -EFAULT ; -return 0 ; + + error =mnt_want_write_file (file); +if (error) +return error; + error =xfs_growfs_rt (mp, &in); +mnt_drop_write_file (file); +return error; }STATIC int
@@ -434,30 +454,10 @@ xfs_file_compat_ioctl(#if defined(BROKEN_X86_ALIGNMENT )case XFS_IOC_FSGEOMETRY_V1_32 :return xfs_compat_ioc_fsgeometry_v1 (ip->i_mount, arg); -case XFS_IOC_FSGROWFSDATA_32 : { -struct xfs_growfs_data in; - -if (xfs_compat_growfs_data_copyin (&in, arg)) -return -EFAULT ; - error =mnt_want_write_file (filp); -if (error) -return error; - error =xfs_growfs_data (ip->i_mount, &in); -mnt_drop_write_file (filp); -return error; - } -case XFS_IOC_FSGROWFSRT_32 : { -struct xfs_growfs_rt in; - -if (xfs_compat_growfs_rt_copyin (&in, arg)) -return -EFAULT ; - error =mnt_want_write_file (filp); -if (error) -return error; - error =xfs_growfs_rt (ip->i_mount, &in); -mnt_drop_write_file (filp); -return error; - } +case XFS_IOC_FSGROWFSDATA_32 : +return xfs_compat_ioc_growfs_data (filp, ip->i_mount, arg); +case XFS_IOC_FSGROWFSRT_32 : +return xfs_compat_ioc_growfs_rt (filp, ip->i_mount, arg);#endif /* long changes size, but xfs only copiese out 32 bits */ case XFS_IOC_GETVERSION_32 :
Signature · 1 line
2.53.0
PATCH 13/16 xfs: cleanup XFS_IOC_GETVERSION_32 handling
In reply to Christoph HellwigMove the cmd assignment into the function call, fix a spelling error in the comment and move the comment next to the call.
--- fs/xfs/xfs_ioctl32.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/xfs/xfs_ioctl32.c +2 -3
@@ -459,10 +459,9 @@ xfs_file_compat_ioctl(case XFS_IOC_FSGROWFSRT_32 :return xfs_compat_ioc_growfs_rt (filp, ip->i_mount, arg);#endif -/* long changes size, but xfs only copiese out 32 bits */ case XFS_IOC_GETVERSION_32 : - cmd =_NATIVE_IOC (cmd, long); -return xfs_file_ioctl (filp, cmd, p); +/* long changes size, but xfs only copies out 32 bits */ +return xfs_file_ioctl (filp,_NATIVE_IOC (cmd, long), p);case XFS_IOC_SWAPEXT_32 : {struct xfs_swapext sxp;struct compat_xfs_swapext __user *sxu = arg;
Signature · 1 line
2.53.0
PATCH 14/16 xfs: split out the handlers for XFS_IOC_SWAPEXT_32
In reply to Christoph HellwigSplit out a helper for XFS_IOC_SWAPEXT_32 to keep the stack variables out of xfs_file_compat_ioctl and to clean up the main compat ioctl handler flow.
--- fs/xfs/xfs_ioctl32.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-)
fs/xfs/xfs_ioctl32.c +23 -17
@@ -158,6 +158,27 @@ xfs_ioctl32_bstat_copyin(return 0 ; } +static int +xfs_compat_ioc_swapext ( +struct file *file, +struct compat_xfs_swapext __user *sxu) +{ +struct xfs_swapext sxp; +int error; + +/* Bulk copy in up to the sx_stat field, then copy bstat */ +if (copy_from_user (&sxp, sxu, offsetof(struct xfs_swapext , sx_stat)) || +xfs_ioctl32_bstat_copyin (&sxp.sx_stat, &sxu->sx_stat)) +return -EFAULT ; + + error =mnt_want_write_file (file); +if (error) +return error; + error =xfs_swapext (&sxp); +mnt_drop_write_file (file); +return error; +} +/* XFS_IOC_FSBULKSTAT and friends */ STATIC int
@@ -446,7 +467,6 @@ xfs_file_compat_ioctl(struct inode *inode =file_inode (filp);struct xfs_inode *ip =XFS_I (inode);void __user *arg =compat_ptr (p); -int error;trace_xfs_file_compat_ioctl (ip);
@@ -462,22 +482,8 @@ xfs_file_compat_ioctl(case XFS_IOC_GETVERSION_32 :/* long changes size, but xfs only copies out 32 bits */ return xfs_file_ioctl (filp,_NATIVE_IOC (cmd, long), p); -case XFS_IOC_SWAPEXT_32 : { -struct xfs_swapext sxp; -struct compat_xfs_swapext __user *sxu = arg; - -/* Bulk copy in up to the sx_stat field, then copy bstat */ -if (copy_from_user (&sxp, sxu, - offsetof(struct xfs_swapext , sx_stat)) || -xfs_ioctl32_bstat_copyin (&sxp.sx_stat, &sxu->sx_stat)) -return -EFAULT ; - error =mnt_want_write_file (filp); -if (error) -return error; - error =xfs_swapext (&sxp); -mnt_drop_write_file (filp); -return error; - } +case XFS_IOC_SWAPEXT_32 : +return xfs_compat_ioc_swapext (filp, arg);case XFS_IOC_FSBULKSTAT_32 :case XFS_IOC_FSBULKSTAT_SINGLE_32 :case XFS_IOC_FSINUMBERS_32 :
Signature · 1 line
2.53.0
PATCH 15/16 xfs: split out the handlers for XFS_IOC_*_BY_HANDLE_32
In reply to Christoph HellwigSplit out helpers for XFS_IOC_*_BY_HANDLE_32 to keep the stack variables out of xfs_file_compat_ioctl and to clean up the main compat ioctl handler flow.
--- fs/xfs/xfs_ioctl32.c | 65 +++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 22 deletions(-)
fs/xfs/xfs_ioctl32.c +43 -22
@@ -379,6 +379,43 @@ xfs_compat_handlereq_to_dentry( compat_ptr(hreq->ihandle), hreq->ihandlen); } +static int +xfs_compat_ioc_find_handle ( +unsigned int cmd, +void __user *arg) +{ +struct xfs_fsop_handlereq hreq; + +if (xfs_compat_handlereq_copyin (&hreq, arg)) +return -EFAULT ; + return xfs_find_handle(_NATIVE_IOC(cmd, struct xfs_fsop_handlereq), + &hreq); +} + +static int +xfs_compat_ioc_open_by_handle ( +struct file *file, +void __user *arg) +{ +struct xfs_fsop_handlereq hreq; + +if (xfs_compat_handlereq_copyin (&hreq, arg)) +return -EFAULT ; +return xfs_open_by_handle (file, &hreq); +} + +static int +xfs_compat_ioc_readlink_by_handle ( +struct file *file, +void __user *arg) +{ +struct xfs_fsop_handlereq hreq; + +if (xfs_compat_handlereq_copyin (&hreq, arg)) +return -EFAULT ; +return xfs_readlink_by_handle (file, &hreq); +} + STATIC int xfs_compat_attrlist_by_handle( struct file *parfilp,
@@ -490,28 +527,12 @@ xfs_file_compat_ioctl(return xfs_compat_ioc_fsbulkstat (filp, cmd, arg);case XFS_IOC_FD_TO_HANDLE_32 :case XFS_IOC_PATH_TO_HANDLE_32 : -case XFS_IOC_PATH_TO_FSHANDLE_32 : { -struct xfs_fsop_handlereq hreq; - -if (xfs_compat_handlereq_copyin (&hreq, arg)) -return -EFAULT ; - cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq); -return xfs_find_handle (cmd, &hreq); - } -case XFS_IOC_OPEN_BY_HANDLE_32 : { -struct xfs_fsop_handlereq hreq; - -if (xfs_compat_handlereq_copyin (&hreq, arg)) -return -EFAULT ; -return xfs_open_by_handle (filp, &hreq); - } -case XFS_IOC_READLINK_BY_HANDLE_32 : { -struct xfs_fsop_handlereq hreq; - -if (xfs_compat_handlereq_copyin (&hreq, arg)) -return -EFAULT ; -return xfs_readlink_by_handle (filp, &hreq); - } +case XFS_IOC_PATH_TO_FSHANDLE_32 : +return xfs_compat_ioc_find_handle (cmd, arg); +case XFS_IOC_OPEN_BY_HANDLE_32 : +return xfs_compat_ioc_open_by_handle (filp, arg); +case XFS_IOC_READLINK_BY_HANDLE_32 : +return xfs_compat_ioc_readlink_by_handle (filp, arg);case XFS_IOC_ATTRLIST_BY_HANDLE_32 :return xfs_compat_attrlist_by_handle (filp, arg);case XFS_IOC_ATTRMULTI_BY_HANDLE_32 :
Signature · 1 line
2.53.0
PATCH 16/16 xfs: remove an extra cast in xfs_file_compat_ioctl
In reply to Christoph HellwigThe ioctl argument is already available as an unsigned long in the p variable, so use that directly instead of casting back from p, which has the same value but was casted to a void pointer before.
--- fs/xfs/xfs_ioctl32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_ioctl32.c +1 -1
@@ -539,6 +539,6 @@ xfs_file_compat_ioctl(return xfs_compat_attrmulti_by_handle (filp, arg);default :/* try the native version */ -return xfs_file_ioctl (filp, cmd, (unsigned long )arg); +return xfs_file_ioctl (filp, cmd, p); } }
Signature · 1 line
2.53.0
Darrick J. Wong
Reviewed-byQuoted 6 lines · Christoph Hellwig
Hi all,
I've been annoyed at the KASAN stack usage warnings in
xfs_file_ioctlagain recently, so let's sort this out properly by splitting each ioctl handler into a separate, well-named helper. We already do that for most, but this series completes it.
The whole series looks fine to me:
--D