Skip to content

Commit 43454e8

Browse files
committed
Merge tag 'io_uring-6.12-20241004' of git://git.kernel.dk/linux
Pull io_uring fixes from Jens Axboe: - Fix an error path memory leak, if one part fails to allocate. Obviously not something that'll generally hit without error injection. - Fix an io_req_flags_t cast to make sparse happier. - Improve the recv multishot termination. Not a bug now, but could be one in the future. This makes it do the same thing that recvmsg does in terms of when to terminate a request or not. * tag 'io_uring-6.12-20241004' of git://git.kernel.dk/linux: io_uring/net: harden multishot termination case for recv io_uring: fix casts to io_req_flags_t io_uring: fix memory leak when cache init fail
2 parents e02f08e + c314094 commit 43454e8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

io_uring/io_uring.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
321321
sizeof(struct io_kiocb));
322322
ret |= io_futex_cache_init(ctx);
323323
if (ret)
324-
goto err;
324+
goto free_ref;
325325
init_completion(&ctx->ref_comp);
326326
xa_init_flags(&ctx->personalities, XA_FLAGS_ALLOC1);
327327
mutex_init(&ctx->uring_lock);
@@ -349,6 +349,9 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
349349
io_napi_init(ctx);
350350

351351
return ctx;
352+
353+
free_ref:
354+
percpu_ref_exit(&ctx->refs);
352355
err:
353356
io_alloc_cache_free(&ctx->rsrc_node_cache, kfree);
354357
io_alloc_cache_free(&ctx->apoll_cache, kfree);
@@ -2038,7 +2041,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
20382041
req->opcode = opcode = READ_ONCE(sqe->opcode);
20392042
/* same numerical values with corresponding REQ_F_*, safe to copy */
20402043
sqe_flags = READ_ONCE(sqe->flags);
2041-
req->flags = (io_req_flags_t) sqe_flags;
2044+
req->flags = (__force io_req_flags_t) sqe_flags;
20422045
req->cqe.user_data = READ_ONCE(sqe->user_data);
20432046
req->file = NULL;
20442047
req->rsrc_node = NULL;

io_uring/net.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
11331133
int ret, min_ret = 0;
11341134
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
11351135
size_t len = sr->len;
1136+
bool mshot_finished;
11361137

11371138
if (!(req->flags & REQ_F_POLLED) &&
11381139
(sr->flags & IORING_RECVSEND_POLL_FIRST))
@@ -1187,14 +1188,15 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
11871188
req_set_fail(req);
11881189
}
11891190

1191+
mshot_finished = ret <= 0;
11901192
if (ret > 0)
11911193
ret += sr->done_io;
11921194
else if (sr->done_io)
11931195
ret = sr->done_io;
11941196
else
11951197
io_kbuf_recycle(req, issue_flags);
11961198

1197-
if (!io_recv_finish(req, &ret, kmsg, ret <= 0, issue_flags))
1199+
if (!io_recv_finish(req, &ret, kmsg, mshot_finished, issue_flags))
11981200
goto retry_multishot;
11991201

12001202
return ret;

0 commit comments

Comments
 (0)