ACPI/IORT: Fix memory leak in iort_rmr_alloc_sids()
Subsystems (4)
PATCH 1/1 ACPI/IORT: Fix memory leak in iort_rmr_alloc_sids()
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.
---
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(-)
drivers/acpi/arm64/iort.c +3 -1
@@ -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++;
Signature · 1 line
2.39.5 (Apple Git-154)
+Cc Catalin, Will
Quoted 21 lines · Miaoqian Lin
If
krealloc_array()fails iniort_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 <[email protected]>Signed-off-by Miaoqian Lin <[email protected]>---
This follows the same pattern as the fix in commit06615967d488("bpf, verifier: Fix memory leak in array reallocation for stack state").--- drivers/acpi/arm64/iort.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/acpi/arm64/iort.c +0
-0@@ -937,8 +937,10 @@ static u32 *iort_rmr_alloc_sids(u32 *sids, u32 count, u32 id_start,
drivers/acpi/arm64/iort.c static u32 *iort_rmr_alloc_sids(u32 *sids, u32 count, u32 id_start, · line 946
Quoted 10 lines
drivers/acpi/arm64/iort.c +3
-1new_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!
Thanks
Hanjun
Quoted 2 lines
If
krealloc_array()fails iniort_rmr_alloc_sids(), the function returns NULL but does not free the original 'sids' allocation. …
…
Quoted 3 lines
---
This follows the same pattern as the fix in commit06615967d488("bpf, verifier: Fix memory leak in array reallocation for stack state").
…
Regards,
Markus
Quoted 6 lines · Miaoqian Lin
If
krealloc_array()fails iniort_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.
Applied to arm64 (for-next/fixes), thanks!
[1/1] ACPI/IORT: Fix memory leak in iort_rmr_alloc_sids()
https://git.kernel.org/arm64/c/f3ef7110924b
Signature · 1 line
Catalin