]> www.infradead.org Git - users/griffoul/linux.git/commitdiff
ACPI/IORT: Fix memory leak in iort_rmr_alloc_sids()
authorMiaoqian Lin <linmq006@gmail.com>
Thu, 28 Aug 2025 11:22:43 +0000 (19:22 +0800)
committerCatalin Marinas <catalin.marinas@arm.com>
Thu, 4 Sep 2025 16:00:01 +0000 (17:00 +0100)
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> # 6.0.x
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Hanjun Guo <guohanjun@huawei.com>
Link: https://lore.kernel.org/r/20250828112243.61460-1-linmq006@gmail.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
drivers/acpi/arm64/iort.c

index 98759d6199d3acb72f8fd942a7632c9697280109..65f0f56ad7538a8fc705f8d60877017266a4c1f6 100644 (file)
@@ -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++;