Skip to contentSkip to conversation

media: pxa_camera: guard list_first_entry() against empty capture list in EOF bottom half

PATCH Superseded Li Ximo 1 participant 1 message Oct 28 Media (V4L/DVB)

lore
Share & tools
lore

Li Ximo

author
#0 lore raw

PATCH v2 1/1 media: pxa_camera: guard list_first_entry() against empty capture list in EOF bottom half

From: Wang Haoran <[email protected]>

list_first_entry() does not return NULL on an empty list; it returns a bogus pointer computed by container_of() from the list head. pxa_camera_eof_bh_work() calls list_first_entry() on &pcdev->capture without checking list_empty() first. The capture list can become empty between the EOF interrupt and the execution of the queued bottom-half
work: pxa_camera_irq() queues eof_bh_work on system_bh_wq on every end-of-frame interrupt, and if the DMA completion path runs first, pxa_camera_wakeup() removes the last buffer from pcdev->capture (e.g. with a single queued buffer) and stops the capture. The already-queued bottom half then observes an empty list, obtains the bogus pointer, stores it in pcdev->active, and unconditionally writes through it in pxa_video_buf_set_actdma() (buf->active_dma = DMA_Y) before starting the DMA channels on it, corrupting memory around pcdev and likely crashing the kernel. This was found by code audit; we do not have PXA hardware to reproduce it.

The sibling function pxa_camera_wakeup(), which operates on the very same list and sets the very same pcdev->active, already guards against an empty list with list_empty() and pxa_camera_stop_capture(). Add the same guard to pxa_camera_eof_bh_work() so both consumers of pcdev->capture behave consistently.

---
v2: add Link: tag referencing the v1 submission as requested by the media CI; no code change.

 drivers/media/platform/intel/pxa_camera.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/platform/intel/pxa_camera.c +5 -0
index 2269d852a..73ce48650 100644
@@ -1161,6 +1161,11 @@ static void pxa_camera_eof_bh_work(struct work_struct *t)
 	cifr = __raw_readl(pcdev->base + CIFR) | CIFR_RESET_F;
 	__raw_writel(cifr, pcdev->base + CIFR);
 
+	if (list_empty(&pcdev->capture)) {
+		pxa_camera_stop_capture(pcdev);
+		return;
+	}
+
 	pcdev->active = list_first_entry(&pcdev->capture,
 					 struct pxa_buffer, queue);
 	buf = pcdev->active;
Signature · 1 line
2.30.2