Skip to content

Commit 2e02f9e

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: improve regbuf iov validation
Deduplicate io_buffer_validate() calls by moving the checks into io_sqe_buffer_register(). Now we also don't need special handling in io_buffer_validate() passing through buffer removal requests. I also was using it as a cleanup before some other changes. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 046fcc8 commit 2e02f9e

1 file changed

Lines changed: 10 additions & 21 deletions

File tree

io_uring/rsrc.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,6 @@ int io_validate_user_buf_range(u64 uaddr, u64 ulen)
9696
return 0;
9797
}
9898

99-
static int io_buffer_validate(struct iovec *iov)
100-
{
101-
/*
102-
* Don't impose further limits on the size and buffer
103-
* constraints here, we'll -EINVAL later when IO is
104-
* submitted if they are wrong.
105-
*/
106-
if (!iov->iov_base)
107-
return iov->iov_len ? -EFAULT : 0;
108-
109-
return io_validate_user_buf_range((unsigned long)iov->iov_base,
110-
iov->iov_len);
111-
}
112-
11399
static void io_release_ubuf(void *priv)
114100
{
115101
struct io_mapped_ubuf *imu = priv;
@@ -319,9 +305,6 @@ static int __io_sqe_buffers_update(struct io_ring_ctx *ctx,
319305
err = -EFAULT;
320306
break;
321307
}
322-
err = io_buffer_validate(iov);
323-
if (err)
324-
break;
325308
node = io_sqe_buffer_register(ctx, iov, &last_hpage);
326309
if (IS_ERR(node)) {
327310
err = PTR_ERR(node);
@@ -790,8 +773,17 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
790773
struct io_imu_folio_data data;
791774
bool coalesced = false;
792775

793-
if (!iov->iov_base)
776+
if (!iov->iov_base) {
777+
if (iov->iov_len)
778+
return ERR_PTR(-EFAULT);
779+
/* remove the buffer without installing a new one */
794780
return NULL;
781+
}
782+
783+
ret = io_validate_user_buf_range((unsigned long)iov->iov_base,
784+
iov->iov_len);
785+
if (ret)
786+
return ERR_PTR(ret);
795787

796788
node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER);
797789
if (!node)
@@ -897,9 +889,6 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
897889
ret = PTR_ERR(iov);
898890
break;
899891
}
900-
ret = io_buffer_validate(iov);
901-
if (ret)
902-
break;
903892
if (ctx->compat)
904893
arg += sizeof(struct compat_iovec);
905894
else

0 commit comments

Comments
 (0)