From: Hanjun Guo <guohanjun@huawei.com>
To: Miaoqian Lin <linmq006@gmail.com>,
Lorenzo Pieralisi <lpieralisi@kernel.org>,
Sudeep Holla <sudeep.holla@arm.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>, Joerg Roedel <jroedel@suse.de>,
Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>,
Robin Murphy <robin.murphy@arm.com>, <linux-acpi@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <bpf@vger.kernel.org>
Cc: <stable@vger.kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>
Subject: Re: [PATCH] ACPI/IORT: Fix memory leak in iort_rmr_alloc_sids()
Date: Mon, 1 Sep 2025 20:10:11 +0800 [thread overview]
Message-ID: <a2ac5b97-ea63-3187-164c-9568d7810a0a@huawei.com> (raw)
In-Reply-To: <20250828112243.61460-1-linmq006@gmail.com>
+Cc Catalin, Will
On 2025/8/28 19:22, Miaoqian Lin wrote:
> If krealloc_array() fails in iort_rmr_alloc_sids(), the function returns
> NULL but does not free the original 'sids' allocation. This results in a
> memory leak since the caller overwrites the original pointer with the
> NULL return value.
>
> Fixes: 491cf4a6735a ("ACPI/IORT: Add support to retrieve IORT RMR reserved regions")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> This follows the same pattern as the fix in commit 06615967d488
> ("bpf, verifier: Fix memory leak in array reallocation for stack state").
> ---
> drivers/acpi/arm64/iort.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index 98759d6199d3..65f0f56ad753 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -937,8 +937,10 @@ static u32 *iort_rmr_alloc_sids(u32 *sids, u32 count, u32 id_start,
>
> new_sids = krealloc_array(sids, count + new_count,
> sizeof(*new_sids), GFP_KERNEL);
> - if (!new_sids)
> + if (!new_sids) {
> + kfree(sids);
> return NULL;
> + }
>
> for (i = count; i < total_count; i++)
> new_sids[i] = id_start++;
Good catch!
Reviewed-by: Hanjun Guo <guohanjun@huawei.com>
Thanks
Hanjun
next prev parent reply other threads:[~2025-09-01 12:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 11:22 Miaoqian Lin
2025-09-01 12:10 ` Hanjun Guo [this message]
2025-09-02 12:23 ` Markus Elfring
2025-09-05 16:13 ` Catalin Marinas
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=a2ac5b97-ea63-3187-164c-9568d7810a0a@huawei.com \
--to=guohanjun@huawei.com \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=jroedel@suse.de \
--cc=lenb@kernel.org \
--cc=linmq006@gmail.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=rafael@kernel.org \
--cc=robin.murphy@arm.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=stable@vger.kernel.org \
--cc=sudeep.holla@arm.com \
--cc=will@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
all inboxes | Powered by JetHome®