From: Jens Axboe Date: Wed, 5 Aug 2020 19:00:44 +0000 (-0600) Subject: io_uring: account locked memory before potential error case X-Git-Tag: io_uring-5.9-2020-08-14~11 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=f74441e6311a28f0ee89b9c8e296a33730f812fc;p=linux-2.6-block.git 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 Reviewed-by: Stefano Garzarella Signed-off-by: Jens Axboe --- diff --git a/fs/io_uring.c b/fs/io_uring.c index 0d857f7ca507..e9b27cdaa735 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -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; @@ -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