Skip to content

Commit d3f05a4

Browse files
committed
Merge tag 'io_uring-6.3-2023-04-06' of git://git.kernel.dk/linux
Pull io_uring fixes from Jens Axboe: "Just two minor fixes for provided buffers - one where we could potentially leak a buffer, and one where the returned values was off-by-one in some cases" * tag 'io_uring-6.3-2023-04-06' of git://git.kernel.dk/linux: io_uring: fix memory leak when removing provided buffers io_uring: fix return value when removing provided buffers
2 parents 973ad54 + b4a72c0 commit d3f05a4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

io_uring/io_uring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2789,8 +2789,8 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
27892789
io_eventfd_unregister(ctx);
27902790
io_alloc_cache_free(&ctx->apoll_cache, io_apoll_cache_free);
27912791
io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free);
2792-
mutex_unlock(&ctx->uring_lock);
27932792
io_destroy_buffers(ctx);
2793+
mutex_unlock(&ctx->uring_lock);
27942794
if (ctx->sq_creds)
27952795
put_cred(ctx->sq_creds);
27962796
if (ctx->submitter_task)

io_uring/kbuf.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,18 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx,
228228
return i;
229229
}
230230

231-
/* the head kbuf is the list itself */
231+
/* protects io_buffers_cache */
232+
lockdep_assert_held(&ctx->uring_lock);
233+
232234
while (!list_empty(&bl->buf_list)) {
233235
struct io_buffer *nxt;
234236

235237
nxt = list_first_entry(&bl->buf_list, struct io_buffer, list);
236-
list_del(&nxt->list);
238+
list_move(&nxt->list, &ctx->io_buffers_cache);
237239
if (++i == nbufs)
238240
return i;
239241
cond_resched();
240242
}
241-
i++;
242243

243244
return i;
244245
}

0 commit comments

Comments
 (0)