Skip to content

Commit 95af849

Browse files
author
Al Viro
committed
aio: shift copyin of iocb into io_submit_one()
Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent d2988bd commit 95af849

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

‎fs/aio.c‎

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,22 +1720,26 @@ static ssize_t aio_poll(struct aio_kiocb *aiocb, struct iocb *iocb)
17201720
}
17211721

17221722
static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
1723-
struct iocb *iocb, bool compat)
1723+
bool compat)
17241724
{
17251725
struct aio_kiocb *req;
1726+
struct iocb iocb;
17261727
ssize_t ret;
17271728

1729+
if (unlikely(copy_from_user(&iocb, user_iocb, sizeof(iocb))))
1730+
return -EFAULT;
1731+
17281732
/* enforce forwards compatibility on users */
1729-
if (unlikely(iocb->aio_reserved2)) {
1733+
if (unlikely(iocb.aio_reserved2)) {
17301734
pr_debug("EINVAL: reserve field set\n");
17311735
return -EINVAL;
17321736
}
17331737

17341738
/* prevent overflows */
17351739
if (unlikely(
1736-
(iocb->aio_buf != (unsigned long)iocb->aio_buf) ||
1737-
(iocb->aio_nbytes != (size_t)iocb->aio_nbytes) ||
1738-
((ssize_t)iocb->aio_nbytes < 0)
1740+
(iocb.aio_buf != (unsigned long)iocb.aio_buf) ||
1741+
(iocb.aio_nbytes != (size_t)iocb.aio_nbytes) ||
1742+
((ssize_t)iocb.aio_nbytes < 0)
17391743
)) {
17401744
pr_debug("EINVAL: overflow check\n");
17411745
return -EINVAL;
@@ -1745,14 +1749,14 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
17451749
if (unlikely(!req))
17461750
return -EAGAIN;
17471751

1748-
if (iocb->aio_flags & IOCB_FLAG_RESFD) {
1752+
if (iocb.aio_flags & IOCB_FLAG_RESFD) {
17491753
/*
17501754
* If the IOCB_FLAG_RESFD flag of aio_flags is set, get an
17511755
* instance of the file* now. The file descriptor must be
17521756
* an eventfd() fd, and will be signaled for each completed
17531757
* event using the eventfd_signal() function.
17541758
*/
1755-
req->ki_eventfd = eventfd_ctx_fdget((int) iocb->aio_resfd);
1759+
req->ki_eventfd = eventfd_ctx_fdget((int) iocb.aio_resfd);
17561760
if (IS_ERR(req->ki_eventfd)) {
17571761
ret = PTR_ERR(req->ki_eventfd);
17581762
req->ki_eventfd = NULL;
@@ -1767,32 +1771,32 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
17671771
}
17681772

17691773
req->ki_user_iocb = user_iocb;
1770-
req->ki_user_data = iocb->aio_data;
1774+
req->ki_user_data = iocb.aio_data;
17711775

1772-
switch (iocb->aio_lio_opcode) {
1776+
switch (iocb.aio_lio_opcode) {
17731777
case IOCB_CMD_PREAD:
1774-
ret = aio_read(&req->rw, iocb, false, compat);
1778+
ret = aio_read(&req->rw, &iocb, false, compat);
17751779
break;
17761780
case IOCB_CMD_PWRITE:
1777-
ret = aio_write(&req->rw, iocb, false, compat);
1781+
ret = aio_write(&req->rw, &iocb, false, compat);
17781782
break;
17791783
case IOCB_CMD_PREADV:
1780-
ret = aio_read(&req->rw, iocb, true, compat);
1784+
ret = aio_read(&req->rw, &iocb, true, compat);
17811785
break;
17821786
case IOCB_CMD_PWRITEV:
1783-
ret = aio_write(&req->rw, iocb, true, compat);
1787+
ret = aio_write(&req->rw, &iocb, true, compat);
17841788
break;
17851789
case IOCB_CMD_FSYNC:
1786-
ret = aio_fsync(&req->fsync, iocb, false);
1790+
ret = aio_fsync(&req->fsync, &iocb, false);
17871791
break;
17881792
case IOCB_CMD_FDSYNC:
1789-
ret = aio_fsync(&req->fsync, iocb, true);
1793+
ret = aio_fsync(&req->fsync, &iocb, true);
17901794
break;
17911795
case IOCB_CMD_POLL:
1792-
ret = aio_poll(req, iocb);
1796+
ret = aio_poll(req, &iocb);
17931797
break;
17941798
default:
1795-
pr_debug("invalid aio operation %d\n", iocb->aio_lio_opcode);
1799+
pr_debug("invalid aio operation %d\n", iocb.aio_lio_opcode);
17961800
ret = -EINVAL;
17971801
break;
17981802
}
@@ -1845,19 +1849,13 @@ static long do_io_submit(aio_context_t ctx_id, long nr,
18451849
*/
18461850
for (i=0; i<nr; i++) {
18471851
struct iocb __user *user_iocb;
1848-
struct iocb tmp;
18491852

18501853
if (unlikely(__get_user(user_iocb, iocbpp + i))) {
18511854
ret = -EFAULT;
18521855
break;
18531856
}
18541857

1855-
if (unlikely(copy_from_user(&tmp, user_iocb, sizeof(tmp)))) {
1856-
ret = -EFAULT;
1857-
break;
1858-
}
1859-
1860-
ret = io_submit_one(ctx, user_iocb, &tmp, compat);
1858+
ret = io_submit_one(ctx, user_iocb, compat);
18611859
if (ret)
18621860
break;
18631861
}

0 commit comments

Comments
 (0)