* [PATCH] media: bcm2835-unicam: fix dummy buffer double free when register fails
@ 2026-05-15 15:25 Dawei Feng
0 siblings, 0 replies; only message in thread
From: Dawei Feng @ 2026-05-15 15:25 UTC (permalink / raw)
To: kernel-list
Cc: mchehab, linux-media, florian.fainelli, bcm-kernel-feedback-list,
rjui, sbranden, linux-rpi-kernel, linux-arm-kernel, linux-kernel,
jianhao.xu, Dawei Feng, stable, Zilin Guan
unicam_register_node() allocates node->dummy_buf_cpu_addr before
registering the video device. If video_register_device() fails, the
error path frees the dummy buffer but leaves the pointer unchanged.
unicam_async_complete() then unwinds the partial setup through
unicam_unregister_nodes(), which sees the stale non-NULL pointer and
frees the same buffer again.
Set dummy_buf_cpu_addr to NULL after dma_free_coherent() in both the
local error path and unicam_unregister_nodes() so later cleanup skips
already released buffers.
The bug was first flagged by an experimental analysis tool we are
developing for kernel memory-management bugs while analyzing
v6.13-rc1. The tool is still under development and is not yet publicly
available. Manual inspection confirms that the bug is still
present in v7.1-rc3.
Runtime validation was not attempted because reproducing this failure
path requires fault injection in a hardware-specific driver.
Fixes: 392cd78d495f ("media: bcm2835-unicam: Add support for CCP2/CSI2 camera interface")
Cc: stable@vger.kernel.org
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Signed-off-by: Dawei Feng <dawei.feng@seu.edu.cn>
---
drivers/media/platform/broadcom/bcm2835-unicam.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/broadcom/bcm2835-unicam.c b/drivers/media/platform/broadcom/bcm2835-unicam.c
index 8d28ba0b59a3..94c80601c50d 100644
--- a/drivers/media/platform/broadcom/bcm2835-unicam.c
+++ b/drivers/media/platform/broadcom/bcm2835-unicam.c
@@ -2360,6 +2360,7 @@ static int unicam_register_node(struct unicam_device *unicam,
dma_free_coherent(unicam->dev, node->dummy_buf.size,
node->dummy_buf_cpu_addr,
node->dummy_buf.dma_addr);
+ node->dummy_buf_cpu_addr = NULL;
err_entity_cleanup:
media_entity_cleanup(&vdev->entity);
err_unicam_put:
@@ -2379,10 +2380,12 @@ static void unicam_unregister_nodes(struct unicam_device *unicam)
node->registered = false;
}
- if (node->dummy_buf_cpu_addr)
+ if (node->dummy_buf_cpu_addr) {
dma_free_coherent(unicam->dev, node->dummy_buf.size,
node->dummy_buf_cpu_addr,
node->dummy_buf.dma_addr);
+ node->dummy_buf_cpu_addr = NULL;
+ }
}
}
--
2.34.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-15 15:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-15 15:25 [PATCH] media: bcm2835-unicam: fix dummy buffer double free when register fails Dawei Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox