From 2a539f2eac9bfc87e93dacdcf4b1a54b43a5f339 Mon Sep 17 00:00:00 2001 From: Pavel Begunkov Date: Tue, 28 Feb 2023 09:21:47 +0800 Subject: [PATCH] io_uring: correct pinned_vm accounting stable inclusion from stable-v5.10.150 commit 67cbc8865a66533fa08c1c13fe9acbaaae63c403 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/I6BTWC CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.10.168&id=67cbc8865a66533fa08c1c13fe9acbaaae63c403 -------------------------------- [ upstream commit 42b6419d0aba47c5d8644cdc0b68502254671de5 ] ->mm_account should be released only after we free all registered buffers, otherwise __io_sqe_buffers_unregister() will see a NULL ->mm_account and skip locked_vm accounting. Cc: Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/6d798f65ed4ab8db3664c4d3397d4af16ca98846.1664849932.git.asml.silence@gmail.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman Signed-off-by: Li Lingfeng Reviewed-by: Zhang Yi Reviewed-by: Wang Weiyang Signed-off-by: Jialin Zhang --- fs/io_uring.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index cfcdea67a0e3..1d8173741310 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8475,8 +8475,6 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx) if (ctx->sqo_task) { put_task_struct(ctx->sqo_task); ctx->sqo_task = NULL; - mmdrop(ctx->mm_account); - ctx->mm_account = NULL; } #ifdef CONFIG_BLK_CGROUP @@ -8497,6 +8495,11 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx) } #endif + if (ctx->mm_account) { + mmdrop(ctx->mm_account); + ctx->mm_account = NULL; + } + io_mem_free(ctx->rings); io_mem_free(ctx->sq_sqes); -- GitLab