Skip to content

Commit f74441e

Browse files
committed
io_uring: account locked memory before potential error case
The tear down path will always unaccount the memory, so ensure that we have accounted it before hitting any of them. Reported-by: Tomáš Chaloupka <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent bd74048 commit f74441e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

fs/io_uring.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8341,6 +8341,16 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,
83418341
ctx->user = user;
83428342
ctx->creds = get_current_cred();
83438343

8344+
/*
8345+
* Account memory _before_ installing the file descriptor. Once
8346+
* the descriptor is installed, it can get closed at any time. Also
8347+
* do this before hitting the general error path, as ring freeing
8348+
* will un-account as well.
8349+
*/
8350+
io_account_mem(ctx, ring_pages(p->sq_entries, p->cq_entries),
8351+
ACCT_LOCKED);
8352+
ctx->limit_mem = limit_mem;
8353+
83448354
ret = io_allocate_scq_urings(ctx, p);
83458355
if (ret)
83468356
goto err;
@@ -8377,14 +8387,6 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,
83778387
goto err;
83788388
}
83798389

8380-
/*
8381-
* Account memory _before_ installing the file descriptor. Once
8382-
* the descriptor is installed, it can get closed at any time.
8383-
*/
8384-
io_account_mem(ctx, ring_pages(p->sq_entries, p->cq_entries),
8385-
ACCT_LOCKED);
8386-
ctx->limit_mem = limit_mem;
8387-
83888390
/*
83898391
* Install ring fd as the very last thing, so we don't risk someone
83908392
* having closed it before we finish setup

0 commit comments

Comments
 (0)