two small patches
cover two small patches
Small patches improving userspace values handling.
Pavel Begunkov (2):
io_uring: fix overflows checks in provide buffers
io_uring: check register restriction afore quiesce
fs/io_uring.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
Signature · 1 line
2.24.0
PATCH 1/2 io_uring: fix overflows checks in provide buffers
Colin reported before possible overflow and sign extension problems in io_provide_buffers_prep(). As Linus pointed out previous attempt did nothing useful, see d81269fecb8ce ("io_uring: fix provide_buffers sign extension").
Do that with help of check_<op>_overflow helpers. And fix struct io_provide_buf::len type, as it doesn't make much sense to keep it signed.
--- fs/io_uring.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/io_uring.c +8 -2
@@ -627,7 +627,7 @@ struct io_splice {struct io_provide_buf {struct file *file;__u64 addr; -__s32 len; +__u32 len;__u32 bgid;__u16 nbufs;__u16 bid;
@@ -3923,7 +3923,7 @@ static int io_remove_buffers(struct io_kiocb *req, unsigned int issue_flags)static int io_provide_buffers_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe) { -unsigned long size; +unsigned long size, tmp_check;struct io_provide_buf *p = &req->pbuf;u64 tmp;
@@ -3937,6 +3937,12 @@ static int io_provide_buffers_prep(struct io_kiocb *req, p->addr =READ_ONCE (sqe->addr); p->len =READ_ONCE (sqe->len); +if (check_mul_overflow ((unsigned long )p->len, (unsigned long )p->nbufs, + &size)) +return -EOVERFLOW ; +if (check_add_overflow ((unsigned long )p->addr, size, &tmp_check)) +return -EOVERFLOW ; + size = (unsigned long )p->len * p->nbufs;if (!access_ok (u64_to_user_ptr (p->addr), size))return -EFAULT ;
Signature · 1 line
2.24.0
PATCH 2/2 io_uring: check register restriction afore quiesce
In reply to Pavel BegunkovMove restriction checks of __io_uring_register() before quiesce, saves from waiting for requests in fail case and simplifies the code a bit. Also add array_index_nospec() for safety
--- fs/io_uring.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
fs/io_uring.c +8 -13
@@ -9764,6 +9764,14 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,if (percpu_ref_is_dying (&ctx->refs))return -ENXIO ; +if (ctx->restricted) { +if (opcode >=IORING_REGISTER_LAST ) +return -EINVAL ; + opcode =array_index_nospec (opcode,IORING_REGISTER_LAST ); +if (!test_bit (opcode, ctx->restrictions.register_op)) +return -EACCES ; + } +if (io_register_op_must_quiesce (opcode)) {percpu_ref_kill (&ctx->refs);
@@ -9792,18 +9800,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, } } -if (ctx->restricted) { -if (opcode >=IORING_REGISTER_LAST ) { - ret = -EINVAL ; - goto out; - } - -if (!test_bit (opcode, ctx->restrictions.register_op)) { - ret = -EACCES ; - goto out; - } - } -switch (opcode) {case IORING_REGISTER_BUFFERS : ret =io_sqe_buffers_register (ctx, arg, nr_args);
@@ -9877,7 +9873,6 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,break ; } -out:if (io_register_op_must_quiesce (opcode)) {/* bring the ctx back to life */ percpu_ref_reinit (&ctx->refs);
Signature · 1 line
2.24.0
Quoted 1 line · Pavel Begunkov
Small patches improving userspace values handling.
imho, those are good for 5.13, as well as look small and clean
Quoted 8 lines
Pavel Begunkov (2):
io_uring: fix overflows checks in provide buffers
io_uring: check register restriction afore quiescefs/io_uring.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
Signature · 1 line
Pavel Begunkov
Quoted 8 lines · Pavel Begunkov
Small patches improving userspace values handling.
Pavel Begunkov (2):
io_uring: fix overflows checks in provide buffers
io_uring: check register restriction afore quiescefs/io_uring.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
Applied, thanks.
Signature · 1 line
Jens Axboe