media: exynos4-is: fix DMA memory double free
Subsystems (4)
PATCH 1/1 media: exynos4-is: fix DMA memory double free
fimc_is_alloc_cpu_memory() frees the coherent DMA buffer when its DMA address does not satisfy the firmware alignment requirement, but leaves is->memory.vaddr non-NULL.
Because firmware loading is asynchronous, this error path may run after probe has returned successfully. A later remove can then attempt to free the same DMA allocation again.
Set is->memory.vaddr to NULL after freeing the buffer so the existing NULL check in fimc_is_free_cpu_memory() skips the already-freed allocation.
This issue was found by our static analysis tool under development.
--- drivers/media/platform/samsung/exynos4-is/fimc-is.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/platform/samsung/exynos4-is/fimc-is.c +1 -0
@@ -346,6 +346,7 @@ static int fimc_is_alloc_cpu_memory(struct fimc_is *is) (u32)is->memory.addr);dma_free_coherent (dev, is->memory.size, is->memory.vaddr, is->memory.addr); + is->memory.vaddr =NULL ;return -EIO ; }
Signature · 1 line
2.43.0
Krzysztof Kozlowski
maintainerQuoted 12 lines · Guangshuo Li
fimc_is_alloc_cpu_memory()frees the coherent DMA buffer when its DMA address does not satisfy the firmware alignment requirement, but leavesis->memory.vaddrnon-NULL.Because firmware loading is asynchronous, this error path may run after probe has returned successfully. A later remove can then attempt to free the same DMA allocation again.
Set
is->memory.vaddrto NULL after freeing the buffer so the existing NULL check infimc_is_free_cpu_memory()skips the already-freed allocation.
Quoted 6 lines
This issue was found by our static analysis tool under development.
Fixes db47622c13ae ("media: platform: exynos4-is: remove all references to physical addresses")Signed-off-by Guangshuo Li <[email protected]>---
More of postings by bot ignoring any feedback.
Best regards,
Krzysztof
Hi Krzysztof,
Quoted 21 lines · Krzysztof Kozlowski
Quoted 12 lines · Guangshuo Li
fimc_is_alloc_cpu_memory()frees the coherent DMA buffer when its DMA address does not satisfy the firmware alignment requirement, but leavesis->memory.vaddrnon-NULL.Because firmware loading is asynchronous, this error path may run after probe has returned successfully. A later remove can then attempt to free the same DMA allocation again.
Set
is->memory.vaddrto NULL after freeing the buffer so the existing NULL check infimc_is_free_cpu_memory()skips the already-freed allocation.Quoted 6 lines
This issue was found by our static analysis tool under development.
Fixes db47622c13ae ("media: platform: exynos4-is: remove all references to physical addresses")Signed-off-by Guangshuo Li <[email protected]>---
Quoted 4 lines
More of postings by bot ignoring any feedback.
Best regards,
Krzysztof
Thank you for your feedback, and I apologize if our recent submissions gave the impression that we were ignoring your previous comments.
We did take your earlier suggestions into account and subsequently submitted a patch series accordingly.
For the more recent patches, however, since they address issues in different drivers, we thought it would be more appropriate to submit them separately rather than group them into a single series.
We certainly did not intend to disregard your feedback. We appreciate your time and guidance, and we will be more careful with our future submissions.
Thank you for your understanding.
Best regards,
Guangshuo Li
Quoted 12 lines · Guangshuo Li
fimc_is_alloc_cpu_memory()frees the coherent DMA buffer when its DMA address does not satisfy the firmware alignment requirement, but leavesis->memory.vaddrnon-NULL.Because firmware loading is asynchronous, this error path may run after probe has returned successfully. A later remove can then attempt to free the same DMA allocation again.
Set
is->memory.vaddrto NULL after freeing the buffer so the existing NULL check infimc_is_free_cpu_memory()skips the already-freed allocation.
Quoted 5 lines
This issue was found by our static analysis tool under development.
Fixes db47622c13ae ("media: platform: exynos4-is: remove all references to physical addresses")Signed-off-by Guangshuo Li <[email protected]>
but I would relax a bit the severity of this issue. I'm not sure if it makes sense to bother stable team with it and I would add 'potential' word to the subject. In practice this case would not happen.
Quoted 9 lines
--- drivers/media/platform/samsung/exynos4-is/fimc-is.c | 1 + 1 file changed, 1 insertion(+)drivers/media/platform/samsung/exynos4-is/fimc-is.c +0
-0
drivers/media/platform/samsung/exynos4-is/fimc-is.c static int fimc_is_alloc_cpu_memory(struct fimc_is *is) · line 352
Quoted 7 lines
drivers/media/platform/samsung/exynos4-is/fimc-is.c +1
-0@@ -346,6 +346,7 @@ static int fimc_is_alloc_cpu_memory(struct fimc_is *is) (u32)is->memory.addr);dma_free_coherent (dev, is->memory.size, is->memory.vaddr, is->memory.addr); + is->memory.vaddr =NULL ;return -EIO ; }
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland