From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
Jason Gunthorpe <jgg@nvidia.com>,
Michael Kelley <mhklinux@outlook.com>,
Mostafa Saleh <smostafa@google.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y 1/2] dma-pool: fix page leak in atomic_pool_expand() cleanup
Date: Thu, 3 Dec 2026 14:34:56 -0500 [thread overview]
Message-ID: <20261203193446.653960-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120205-grumbling-salaried-cc68@gregkh>
From: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
[ Upstream commit 0510cb5b23037dbaaf57b8ddd6af32cbfc173ef2 ]
atomic_pool_expand() frees the allocated pages from the remove_mapping
error path only when CONFIG_DMA_DIRECT_REMAP is enabled.
When CONFIG_DMA_DIRECT_REMAP is disabled, failures after page allocation,
such as gen_pool_add_virt(), jump to remove_mapping and return without
freeing the pages.
Move __free_pages(page, order) out of the CONFIG_DMA_DIRECT_REMAP block so
that cleanup paths always release the allocation.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Tested-by: Michael Kelley <mhklinux@outlook.com>
Tested-by: Mostafa Saleh <smostafa@google.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
Link: https://lore.kernel.org/r/20260717180442.110954-3-aneesh.kumar@kernel.org
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Stable-dep-of: ca010d38da7b ("dma-pool: release CMA pages on atomic_pool_expand() error path")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/dma/pool.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
index 8a15b5008b20c..7c55405c8d0da 100644
--- a/kernel/dma/pool.c
+++ b/kernel/dma/pool.c
@@ -81,6 +81,7 @@ static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size,
{
unsigned int order;
struct page *page = NULL;
+ bool leak_pages = false;
void *addr;
int ret = -ENOMEM;
@@ -115,8 +116,10 @@ static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size,
*/
ret = set_memory_decrypted((unsigned long)page_to_virt(page),
1 << order);
- if (ret)
+ if (ret) {
+ leak_pages = true;
goto remove_mapping;
+ }
ret = gen_pool_add_virt(pool, (unsigned long)addr, page_to_phys(page),
pool_size, NUMA_NO_NODE);
if (ret)
@@ -130,14 +133,15 @@ static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size,
1 << order);
if (WARN_ON_ONCE(ret)) {
/* Decrypt succeeded but encrypt failed, purposely leak */
- goto out;
+ leak_pages = true;
}
remove_mapping:
#ifdef CONFIG_DMA_DIRECT_REMAP
dma_common_free_remap(addr, pool_size);
free_page:
- __free_pages(page, order);
#endif
+ if (!leak_pages)
+ __free_pages(page, order);
out:
return ret;
}
--
2.53.0
next prev parent reply other threads:[~2026-12-03 19:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:00 FAILED: patch "[PATCH] dma-pool: release CMA pages on atomic_pool_expand() error" failed to apply to 6.6-stable tree gregkh
2026-12-03 19:34 ` Sasha Levin [this message]
2026-12-03 19:34 ` [PATCH 6.6.y 2/2] dma-pool: release CMA pages on atomic_pool_expand() error path Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203193446.653960-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=aneesh.kumar@kernel.org \
--cc=jgg@nvidia.com \
--cc=m.szyprowski@samsung.com \
--cc=mhklinux@outlook.com \
--cc=smostafa@google.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox