From: Haoran Wang <haoranwangsec@gmail.com>
To: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-media@vger.kernel.org,
linux-rpi-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] media: raspberrypi: cfe: guard against empty dma_queue when scheduling
Date: Thu, 03 Dec 2026 19:42:27 +0800 [thread overview]
Message-ID: <179629814789.16896.15718250883599448511@gmail.com> (raw)
cfe_schedule_next_csi2_job() and cfe_schedule_next_pisp_job() call
list_first_entry() on node->dma_queue without checking that the queue
is non-empty. Both run only when cfe->job_ready is true, which
cfe_check_job_ready() establishes by requiring every enabled node to
have a non-empty queue, so the invariant currently holds but there is
no guard at the scheduling site. If it is ever broken, list_first_entry()
returns a pointer into struct cfe_node instead of a struct cfe_buffer,
list_del() corrupts the empty list head and the CSI2 path programs a
garbage DMA address into the hardware.
Use list_first_entry_or_null() and skip the node, or abort the FE
submit for the PISP path, if the queue is unexpectedly empty. A broken
invariant then yields a WARN_ON() instead of wild dereferences, list
corruption and a bogus DMA address.
This was found by static analysis and the trigger is theoretical, so
the change is a defensive guard at the scheduling site only.
Fixes: 6edb685abb2a ("media: raspberrypi: Add support for RP1-CFE")
Signed-off-by: Haoran Wang <haoranwangsec@gmail.com>
---
drivers/media/platform/raspberrypi/rp1-cfe/cfe.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c b/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
index 8375ed3e97b9..9d0ac4262bb4 100644
--- a/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
+++ b/drivers/media/platform/raspberrypi/rp1-cfe/cfe.c
@@ -532,8 +532,10 @@ static void cfe_schedule_next_csi2_job(struct cfe_device *cfe)
if (!check_state(cfe, NODE_STREAMING, i))
continue;
- buf = list_first_entry(&node->dma_queue, struct cfe_buffer,
- list);
+ buf = list_first_entry_or_null(&node->dma_queue,
+ struct cfe_buffer, list);
+ if (WARN_ON(!buf))
+ continue;
node->next_frm = buf;
list_del(&buf->list);
@@ -565,8 +567,10 @@ static void cfe_schedule_next_pisp_job(struct cfe_device *cfe)
if (!check_state(cfe, NODE_STREAMING, i))
continue;
- buf = list_first_entry(&node->dma_queue, struct cfe_buffer,
- list);
+ buf = list_first_entry_or_null(&node->dma_queue,
+ struct cfe_buffer, list);
+ if (WARN_ON(!buf))
+ return;
trace_cfe_fe_schedule(node->id, &buf->vb.vb2_buf);
reply other threads:[~2026-12-03 11:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179629814789.16896.15718250883599448511@gmail.com \
--to=haoranwangsec@gmail.com \
--cc=kernel-list@raspberrypi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=tomi.valkeinen@ideasonboard.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®