Skip to content

Commit

Permalink
io_uring: account locked memory before potential error case
Browse files Browse the repository at this point in the history
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 <chalucha@gmail.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Jens Axboe committed Aug 6, 2020
1 parent bd74048 commit f74441e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -8341,6 +8341,16 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,
ctx->user = user;
ctx->creds = get_current_cred();

/*
* Account memory _before_ installing the file descriptor. Once
* the descriptor is installed, it can get closed at any time. Also
* do this before hitting the general error path, as ring freeing
* will un-account as well.
*/
io_account_mem(ctx, ring_pages(p->sq_entries, p->cq_entries),
ACCT_LOCKED);
ctx->limit_mem = limit_mem;

ret = io_allocate_scq_urings(ctx, p);
if (ret)
goto err;
Expand Down Expand Up @@ -8377,14 +8387,6 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,
goto err;
}

/*
* Account memory _before_ installing the file descriptor. Once
* the descriptor is installed, it can get closed at any time.
*/
io_account_mem(ctx, ring_pages(p->sq_entries, p->cq_entries),
ACCT_LOCKED);
ctx->limit_mem = limit_mem;

/*
* Install ring fd as the very last thing, so we don't risk someone
* having closed it before we finish setup
Expand Down

0 comments on commit f74441e

Please sign in to comment.