Skip to content

Commit bd74048

Browse files
committed
io_uring: set ctx sq/cq entry count earlier
If we hit an earlier error path in io_uring_create(), then we will have accounted memory, but not set ctx->{sq,cq}_entries yet. Then when the ring is torn down in error, we use those values to unaccount the memory. Ensure we set the ctx entries before we're able to hit a potential error path. Cc: [email protected] Reported-by: Tomáš Chaloupka <[email protected]> Tested-by: Tomáš Chaloupka <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 2dd2111 commit bd74048

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/io_uring.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8193,6 +8193,10 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx,
81938193
struct io_rings *rings;
81948194
size_t size, sq_array_offset;
81958195

8196+
/* make sure these are sane, as we already accounted them */
8197+
ctx->sq_entries = p->sq_entries;
8198+
ctx->cq_entries = p->cq_entries;
8199+
81968200
size = rings_size(p->sq_entries, p->cq_entries, &sq_array_offset);
81978201
if (size == SIZE_MAX)
81988202
return -EOVERFLOW;
@@ -8209,8 +8213,6 @@ static int io_allocate_scq_urings(struct io_ring_ctx *ctx,
82098213
rings->cq_ring_entries = p->cq_entries;
82108214
ctx->sq_mask = rings->sq_ring_mask;
82118215
ctx->cq_mask = rings->cq_ring_mask;
8212-
ctx->sq_entries = rings->sq_ring_entries;
8213-
ctx->cq_entries = rings->cq_ring_entries;
82148216

82158217
size = array_size(sizeof(struct io_uring_sqe), p->sq_entries);
82168218
if (size == SIZE_MAX) {

0 commit comments

Comments
 (0)