Patch "dma-buf/dma-resv: Stop leaking on krealloc() failure" has been added to the 6.4-stable tree
[email protected]
AppliedThis is a note to let you know that I've just added the patch titled
dma-buf/dma-resv: Stop leaking on krealloc() failure
to the 6.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
dma-buf-dma-resv-stop-leaking-on-krealloc-failure.patch
and it can be found in the queue-6.4 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From 05abb3be91d8788328231ee02973ab3d47f5e3d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= <[email protected]>
Date: Thu, 13 Jul 2023 22:47:45 +0300
Subject: dma-buf/dma-resv: Stop leaking on krealloc() failure
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
From: Ville Syrjälä <[email protected]>
commit 05abb3be91d8788328231ee02973ab3d47f5e3d2 upstream.
Currently dma_resv_get_fences() will leak the previously allocated array if the fence iteration got restarted and the krealloc_array() fails.
Free the old array by hand, and make sure we still clear the returned *fences so the caller won't end up accessing freed memory. Some (but not all) of the callers of dma_resv_get_fences() seem to still trawl through the array even when dma_resv_get_fences() failed. And let's zero out *num_fences as well for good measure.
--- drivers/dma-buf/dma-resv.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/dma-buf/dma-resv.c +9 -4
@@ -571,6 +571,7 @@ int dma_resv_get_fences(struct dma_resvdma_resv_for_each_fence_unlocked (&cursor, fence) {if (dma_resv_iter_is_restarted (&cursor)) { +struct dma_fence **new_fences;unsigned int count;while (*num_fences)
@@ -579,13 +580,17 @@ int dma_resv_get_fences(struct dma_resv count = cursor.num_fences +1 ;/* Eventually re-allocate the array */ - *fences =krealloc_array (*fences, count, -sizeof (void *), -GFP_KERNEL ); -if (count && !*fences) { + new_fences =krealloc_array (*fences, count, +sizeof (void *), +GFP_KERNEL ); +if (count && !new_fences) { +kfree (*fences); + *fences =NULL ; + *num_fences =0 ;dma_resv_iter_end (&cursor);return -ENOMEM ; } + *fences = new_fences; } (*fences)[(*num_fences)++] =dma_fence_get (fence);
Patches currently in stable-queue which might be from [email protected] are
queue-6.4/dma-buf-dma-resv-stop-leaking-on-krealloc-failure.patch