All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: Sakari Ailus <sakari.ailus@iki.fi>,
	Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
	Alexander Shiyan <eagle.alexander923@gmail.com>,
	Fabio Estevam <festevam@gmail.com>,
	Frieder Schrempf <frieder.schrempf@kontron.de>,
	Marek Vasut <marex@denx.de>,
	Martin Kepplinger <martin.kepplinger@puri.sm>,
	Rui Miguel Silva <rmfrfs@gmail.com>,
	Tim Harvey <tharvey@gateworks.com>,
	Purism Kernel Team <kernel@puri.sm>
Subject: [PATCH 3/7] media: nxp: imx8-isi: Check whether crossbar pad is non-NULL before access
Date: Mon, 15 Jan 2024 12:30:25 +0200	[thread overview]
Message-ID: <20240115103029.28055-4-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20240115103029.28055-1-laurent.pinchart@ideasonboard.com>

From: Marek Vasut <marex@denx.de>

When translating source to sink streams in the crossbar subdev, the
driver tries to locate the remote subdev connected to the sink pad. The
remote pad may be NULL, if userspace tries to enable a stream that ends
at an unconnected crossbar sink. When that occurs, the driver
dereferences the NULL pad, leading to a crash.

Prevent the crash by checking if the pad is NULL before using it, and
return an error if it is.

Fixes: cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")
Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Link: https://lore.kernel.org/r/20231201150614.63300-1-marex@denx.de
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c
index 792f031e032a..44354931cf8a 100644
--- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c
+++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c
@@ -160,8 +160,14 @@ mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar,
 	}
 
 	pad = media_pad_remote_pad_first(&xbar->pads[sink_pad]);
-	sd = media_entity_to_v4l2_subdev(pad->entity);
+	if (!pad) {
+		dev_dbg(xbar->isi->dev,
+			"no pad connected to crossbar input %u\n",
+			sink_pad);
+		return ERR_PTR(-EPIPE);
+	}
 
+	sd = media_entity_to_v4l2_subdev(pad->entity);
 	if (!sd) {
 		dev_dbg(xbar->isi->dev,
 			"no entity connected to crossbar input %u\n",
-- 
Regards,

Laurent Pinchart


  parent reply	other threads:[~2024-01-15 10:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-15 10:30 [PATCH 0/7] media: Fix mishandling of MEDIA_PAD_FL_MUST_CONNECT flag Laurent Pinchart
2024-01-15 10:30 ` [PATCH 1/7] media: mc: Add local pad to pipeline regardless of the link state Laurent Pinchart
2024-01-15 10:30 ` [PATCH 2/7] media: mc: Fix flags handling when creating pad links Laurent Pinchart
2024-01-15 10:30 ` Laurent Pinchart [this message]
2024-01-15 10:30 ` [PATCH 4/7] media: mc: Add num_links flag to media_pad Laurent Pinchart
2024-01-15 10:30 ` [PATCH 5/7] media: mc: Rename pad variable to clarify intent Laurent Pinchart
2024-01-15 10:30 ` [PATCH 6/7] media: mc: Expand MUST_CONNECT flag to always require an enabled link Laurent Pinchart
2024-01-15 10:43   ` Sakari Ailus
2024-01-15 10:55     ` Laurent Pinchart
2024-01-15 10:59       ` Sakari Ailus
2024-01-15 11:10         ` Laurent Pinchart
2024-01-15 10:54   ` Sakari Ailus
2024-01-15 10:59     ` Laurent Pinchart
2024-01-15 10:30 ` [PATCH 7/7] media: nxp: imx8-isi: Mark all crossbar sink pads as MUST_CONNECT Laurent Pinchart

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=20240115103029.28055-4-laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=eagle.alexander923@gmail.com \
    --cc=festevam@gmail.com \
    --cc=frieder.schrempf@kontron.de \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=kernel@puri.sm \
    --cc=linux-media@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=martin.kepplinger@puri.sm \
    --cc=rmfrfs@gmail.com \
    --cc=sakari.ailus@iki.fi \
    --cc=tharvey@gateworks.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.