Skip to content

Commit cf3770e

Browse files
Colin Ian Kingaxboe
authored andcommitted
io_uring: Fix premature return from loop and memory leak
Currently the -EINVAL error return path is leaking memory allocated to data. Fix this by not returning immediately but instead setting the error return variable to -EINVAL and breaking out of the loop. Kudos to Pavel Begunkov for suggesting a correct fix. Signed-off-by: Colin Ian King <colin.king@canonical.com> Reviewed-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/20210429104602.62676-1-colin.king@canonical.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 47b228c commit cf3770e

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

fs/io_uring.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8417,8 +8417,10 @@ static int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
84178417
ret = io_buffer_validate(&iov);
84188418
if (ret)
84198419
break;
8420-
if (!iov.iov_base && tag)
8421-
return -EINVAL;
8420+
if (!iov.iov_base && tag) {
8421+
ret = -EINVAL;
8422+
break;
8423+
}
84228424

84238425
ret = io_sqe_buffer_register(ctx, &iov, &ctx->user_bufs[i],
84248426
&last_hpage);
@@ -8468,8 +8470,10 @@ static int __io_sqe_buffers_update(struct io_ring_ctx *ctx,
84688470
err = io_buffer_validate(&iov);
84698471
if (err)
84708472
break;
8471-
if (!iov.iov_base && tag)
8472-
return -EINVAL;
8473+
if (!iov.iov_base && tag) {
8474+
err = -EINVAL;
8475+
break;
8476+
}
84738477
err = io_sqe_buffer_register(ctx, &iov, &imu, &last_hpage);
84748478
if (err)
84758479
break;

0 commit comments

Comments
 (0)