[lvc-project] [PATCH] media: ipu6: isys: fix csi2 NULL deref in stream enable/disable

Mikhail Lobanov m.lobanov at rosa.ru
Fri Dec 12 01:10:38 MSK 2025


media_pad_remote_pad_first() may return NULL when there is no enabled
media link on the CSI-2 sink pad. ipu6_isys_csi2_enable_streams() and
ipu6_isys_csi2_disable_streams() dereference remote_pad->entity
unconditionally, which can lead to a NULL pointer dereference when no
remote pad is present.

Check the remote pad before dereferencing it, return -ENOTCONN from the
enable path when no remote pad is found, and always stop the local CSI-2
stream in the disable path even if the remote entity is already gone.
Rely on this check to also cover the remote sub-device, as
media_entity_to_v4l2_subdev() only returns NULL when called with a NULL
entity.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 3a5c59ad926b ("media: ipu6: Rework CSI-2 sub-device streaming control")
Signed-off-by: Mikhail Lobanov <m.lobanov at rosa.ru>
---
 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
index 43a2a16a3c2a..29791b66d479 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
@@ -356,6 +356,9 @@ static int ipu6_isys_csi2_enable_streams(struct v4l2_subdev *sd,
 	int ret;
 
 	remote_pad = media_pad_remote_pad_first(&sd->entity.pads[CSI2_PAD_SINK]);
+	if (!remote_pad)
+		return -ENOTCONN;
+
 	remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
 
 	sink_streams =
@@ -393,6 +396,11 @@ static int ipu6_isys_csi2_disable_streams(struct v4l2_subdev *sd,
 						&streams_mask);
 
 	remote_pad = media_pad_remote_pad_first(&sd->entity.pads[CSI2_PAD_SINK]);
+	if (!remote_pad) {
+		ipu6_isys_csi2_set_stream(sd, NULL, 0, false);
+		return 0;
+	}
+
 	remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
 
 	ipu6_isys_csi2_set_stream(sd, NULL, 0, false);
-- 
2.47.2




More information about the lvc-project mailing list