From: Dan Carpenter <dan.carpenter@oracle.com>
To: Christoph Hellwig <hch@infradead.org>,
Tianyu Lan <Tianyu.Lan@microsoft.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
iommu@lists.linux.dev, kernel-janitors@vger.kernel.org
Subject: [PATCH] swiotlb: Fix use after free on error handling path
Date: Fri, 15 Jul 2022 11:19:50 +0300 [thread overview]
Message-ID: <YtEjJkxyiZouY7d3@kili> (raw)
Don't dereference "mem" after it has been freed. Flip the
two kfree()s around to address this bug.
Fixes: 26ffb91fa5e0 ("swiotlb: split up the global swiotlb lock")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
kernel/dma/swiotlb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index bf2ae98a42b4..78af9e455c59 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -980,8 +980,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
mem->areas = kcalloc(nareas, sizeof(*mem->areas),
GFP_KERNEL);
if (!mem->areas) {
- kfree(mem);
kfree(mem->slots);
+ kfree(mem);
return -ENOMEM;
}
--
2.35.1
next reply other threads:[~2022-07-15 8:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-15 8:19 Dan Carpenter [this message]
2022-07-18 4:50 ` [PATCH] swiotlb: Fix use after free on error handling path Christoph Hellwig
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=YtEjJkxyiZouY7d3@kili \
--to=dan.carpenter@oracle.com \
--cc=Tianyu.Lan@microsoft.com \
--cc=hch@infradead.org \
--cc=iommu@lists.linux.dev \
--cc=kernel-janitors@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
/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