提交 eb241c74 编写于 作者: C Christoph Hellwig 提交者: Darrick J. Wong

xfs: lift buffer allocation into xfs_ioc_attr_list

Lift the buffer allocation from the two callers into xfs_ioc_attr_list.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NDave Chinner <dchinner@redhat.com>
Reviewed-by: NChandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: NDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: NDarrick J. Wong <darrick.wong@oracle.com>
上级 f6046319
...@@ -352,13 +352,14 @@ xfs_ioc_attr_put_listent( ...@@ -352,13 +352,14 @@ xfs_ioc_attr_put_listent(
int int
xfs_ioc_attr_list( xfs_ioc_attr_list(
struct xfs_inode *dp, struct xfs_inode *dp,
char *buffer, void __user *ubuf,
int bufsize, int bufsize,
int flags, int flags,
struct attrlist_cursor_kern *cursor) struct attrlist_cursor_kern *cursor)
{ {
struct xfs_attr_list_context context; struct xfs_attr_list_context context;
struct xfs_attrlist *alist; struct xfs_attrlist *alist;
void *buffer;
int error; int error;
if (bufsize < sizeof(struct xfs_attrlist) || if (bufsize < sizeof(struct xfs_attrlist) ||
...@@ -382,11 +383,9 @@ xfs_ioc_attr_list( ...@@ -382,11 +383,9 @@ xfs_ioc_attr_list(
(cursor->hashval || cursor->blkno || cursor->offset)) (cursor->hashval || cursor->blkno || cursor->offset))
return -EINVAL; return -EINVAL;
/* buffer = kmem_zalloc_large(bufsize, 0);
* Check for a properly aligned buffer. if (!buffer)
*/ return -ENOMEM;
if (((long)buffer) & (sizeof(int)-1))
return -EFAULT;
/* /*
* Initialize the output buffer. * Initialize the output buffer.
...@@ -407,7 +406,13 @@ xfs_ioc_attr_list( ...@@ -407,7 +406,13 @@ xfs_ioc_attr_list(
alist->al_offset[0] = context.bufsize; alist->al_offset[0] = context.bufsize;
error = xfs_attr_list(&context); error = xfs_attr_list(&context);
ASSERT(error <= 0); if (error)
goto out_free;
if (copy_to_user(ubuf, buffer, bufsize))
error = -EFAULT;
out_free:
kmem_free(buffer);
return error; return error;
} }
...@@ -421,7 +426,6 @@ xfs_attrlist_by_handle( ...@@ -421,7 +426,6 @@ xfs_attrlist_by_handle(
struct xfs_fsop_attrlist_handlereq __user *p = arg; struct xfs_fsop_attrlist_handlereq __user *p = arg;
xfs_fsop_attrlist_handlereq_t al_hreq; xfs_fsop_attrlist_handlereq_t al_hreq;
struct dentry *dentry; struct dentry *dentry;
char *kbuf;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
...@@ -432,26 +436,15 @@ xfs_attrlist_by_handle( ...@@ -432,26 +436,15 @@ xfs_attrlist_by_handle(
if (IS_ERR(dentry)) if (IS_ERR(dentry))
return PTR_ERR(dentry); return PTR_ERR(dentry);
kbuf = kmem_zalloc_large(al_hreq.buflen, 0);
if (!kbuf)
goto out_dput;
cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
error = xfs_ioc_attr_list(XFS_I(d_inode(dentry)), kbuf, al_hreq.buflen, error = xfs_ioc_attr_list(XFS_I(d_inode(dentry)), al_hreq.buffer,
al_hreq.flags, cursor); al_hreq.buflen, al_hreq.flags, cursor);
if (error) if (error)
goto out_kfree; goto out_dput;
if (copy_to_user(&p->pos, cursor, sizeof(attrlist_cursor_kern_t))) {
error = -EFAULT;
goto out_kfree;
}
if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen)) if (copy_to_user(&p->pos, cursor, sizeof(attrlist_cursor_kern_t)))
error = -EFAULT; error = -EFAULT;
out_kfree:
kmem_free(kbuf);
out_dput: out_dput:
dput(dentry); dput(dentry);
return error; return error;
......
...@@ -39,7 +39,7 @@ xfs_readlink_by_handle( ...@@ -39,7 +39,7 @@ xfs_readlink_by_handle(
int xfs_ioc_attrmulti_one(struct file *parfilp, struct inode *inode, int xfs_ioc_attrmulti_one(struct file *parfilp, struct inode *inode,
uint32_t opcode, void __user *uname, void __user *value, uint32_t opcode, void __user *uname, void __user *value,
uint32_t *len, uint32_t flags); uint32_t *len, uint32_t flags);
int xfs_ioc_attr_list(struct xfs_inode *dp, char *buffer, int bufsize, int xfs_ioc_attr_list(struct xfs_inode *dp, void __user *ubuf, int bufsize,
int flags, struct attrlist_cursor_kern *cursor); int flags, struct attrlist_cursor_kern *cursor);
extern struct dentry * extern struct dentry *
......
...@@ -359,7 +359,6 @@ xfs_compat_attrlist_by_handle( ...@@ -359,7 +359,6 @@ xfs_compat_attrlist_by_handle(
compat_xfs_fsop_attrlist_handlereq_t __user *p = arg; compat_xfs_fsop_attrlist_handlereq_t __user *p = arg;
compat_xfs_fsop_attrlist_handlereq_t al_hreq; compat_xfs_fsop_attrlist_handlereq_t al_hreq;
struct dentry *dentry; struct dentry *dentry;
char *kbuf;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
...@@ -371,27 +370,16 @@ xfs_compat_attrlist_by_handle( ...@@ -371,27 +370,16 @@ xfs_compat_attrlist_by_handle(
if (IS_ERR(dentry)) if (IS_ERR(dentry))
return PTR_ERR(dentry); return PTR_ERR(dentry);
error = -ENOMEM;
kbuf = kmem_zalloc_large(al_hreq.buflen, 0);
if (!kbuf)
goto out_dput;
cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
error = xfs_ioc_attr_list(XFS_I(d_inode(dentry)), kbuf, al_hreq.buflen, error = xfs_ioc_attr_list(XFS_I(d_inode(dentry)),
al_hreq.flags, cursor); compat_ptr(al_hreq.buffer), al_hreq.buflen,
al_hreq.flags, cursor);
if (error) if (error)
goto out_kfree; goto out_dput;
if (copy_to_user(&p->pos, cursor, sizeof(attrlist_cursor_kern_t))) {
error = -EFAULT;
goto out_kfree;
}
if (copy_to_user(compat_ptr(al_hreq.buffer), kbuf, al_hreq.buflen)) if (copy_to_user(&p->pos, cursor, sizeof(attrlist_cursor_kern_t)))
error = -EFAULT; error = -EFAULT;
out_kfree:
kmem_free(kbuf);
out_dput: out_dput:
dput(dentry); dput(dentry);
return error; return error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册