From 2282a9e65177b425aaab4d8228f98f5c09fc778a Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 26 Feb 2020 17:30:31 -0800 Subject: xfs: use strndup_user in XFS_IOC_ATTRMULTI_BY_HANDLE Simplify the user copy code by using strndup_user. This means that we now do one memory allocation per operation instead of one per ioctl, but memory allocations are cheap compared to the actual file system operations. Also the error for an invalid path is now EINVAL or EFAULT instead of the previous odd and undocumented ERANGE. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: Chandan Rajendra Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_ioctl32.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'fs/xfs/xfs_ioctl32.c') diff --git a/fs/xfs/xfs_ioctl32.c b/fs/xfs/xfs_ioctl32.c index e085f304e539..936c2f62fb6c 100644 --- a/fs/xfs/xfs_ioctl32.c +++ b/fs/xfs/xfs_ioctl32.c @@ -445,11 +445,6 @@ xfs_compat_attrmulti_by_handle( goto out_dput; } - error = -ENOMEM; - attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL); - if (!attr_name) - goto out_kfree_ops; - error = 0; for (i = 0; i < am_hreq.opcount; i++) { if ((ops[i].am_flags & ATTR_ROOT) && @@ -459,13 +454,12 @@ xfs_compat_attrmulti_by_handle( } ops[i].am_flags &= ~ATTR_KERNEL_FLAGS; - ops[i].am_error = strncpy_from_user((char *)attr_name, - compat_ptr(ops[i].am_attrname), + attr_name = strndup_user(compat_ptr(ops[i].am_attrname), MAXNAMELEN); - if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN) - error = -ERANGE; - if (ops[i].am_error < 0) + if (IS_ERR(attr_name)) { + ops[i].am_error = PTR_ERR(attr_name); break; + } switch (ops[i].am_opcode) { case ATTR_OP_GET: @@ -496,13 +490,12 @@ xfs_compat_attrmulti_by_handle( default: ops[i].am_error = -EINVAL; } + kfree(attr_name); } if (copy_to_user(compat_ptr(am_hreq.ops), ops, size)) error = -EFAULT; - kfree(attr_name); - out_kfree_ops: kfree(ops); out_dput: dput(dentry); -- cgit v1.2.3