From: Nicola Fiorillo <nicfio@gmail.com>
To: linux-media@vger.kernel.org
Cc: sakari.ailus@linux.intel.com, mchehab@kernel.org,
hverkuil@kernel.org, antti.laakso@linux.intel.com,
linux-kernel@vger.kernel.org, Nicola Fiorillo <nicfio@gmail.com>
Subject: [PATCH v2 1/3] media: ipu6: Check the remote pad before dereferencing it
Date: Fri, 11 Sep 2026 21:48:52 +0200 [thread overview]
Message-ID: <20260911194854.78894-2-nicfio@gmail.com> (raw)
In-Reply-To: <20260911194854.78894-1-nicfio@gmail.com>
Unbinding a sensor driver while a capture is running oopses the kernel:
BUG: kernel NULL pointer dereference, address: 0000000000000020
RIP: 0010:ipu6_isys_csi2_disable_streams+0x3c/0x70 [intel_ipu6_isys]
Call Trace:
v4l2_subdev_disable_streams+0x1b7/0x370 [videodev]
ipu6_isys_video_set_streaming+0x20f/0x930 [intel_ipu6_isys]
stop_streaming+0x102/0x110 [intel_ipu6_isys]
__vb2_queue_cancel+0x2a/0x2d0 [videobuf2_common]
vb2_core_queue_release+0x22/0x80 [videobuf2_common]
_vb2_fop_release+0x58/0xb0 [videobuf2_v4l2]
v4l2_release+0xbd/0xd0 [videodev]
__fput+0xde/0x2a0
media_pad_remote_pad_first() returns NULL once the sensor is gone and the
link with it, but both the enable and the disable path dereference the
result unconditionally. The faulting address is the offset of the entity
member in struct media_pad.
Check it. On enable there is nothing to stream from, so refuse with
-ENOLINK. On disable the receiver still has to be stopped, so stop it and
skip only the call towards the sensor that is no longer there.
Reproduced on a CHUWI Hi10 X1 (Alder Lake-N, IPU6) running 6.12.86, with
the CSI-2 port of a sensor being unbound mid capture. The code is
unchanged in v7.3-rc2.
Fixes: 3a5c59ad926b ("media: ipu6: Rework CSI-2 sub-device streaming control")
Signed-off-by: Nicola Fiorillo <nicfio@gmail.com>
---
Unchanged since v1.
This one collides with the IPU7 work; see the cover letter. A version of
it rebased on the ipu6 branch of the media tree was posted in the v1
thread:
https://lore.kernel.org/linux-media/20260903202820.8401-1-nicfio@gmail.com/
drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
index 7e539a0c6..c00a82eb8 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 -ENOLINK;
+
remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
sink_streams =
@@ -392,10 +395,17 @@ static int ipu6_isys_csi2_disable_streams(struct v4l2_subdev *sd,
v4l2_subdev_state_xlate_streams(state, pad, CSI2_PAD_SINK,
&streams_mask);
+ ipu6_isys_csi2_set_stream(sd, NULL, 0, false);
+
+ /*
+ * The link is gone if the sensor driver was unbound while streaming.
+ * Stop the receiver anyway, there is just no one left to tell.
+ */
remote_pad = media_pad_remote_pad_first(&sd->entity.pads[CSI2_PAD_SINK]);
- remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
+ if (!remote_pad)
+ return 0;
- ipu6_isys_csi2_set_stream(sd, NULL, 0, false);
+ remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
v4l2_subdev_disable_streams(remote_sd, remote_pad->index, sink_streams);
--
2.47.3
next prev parent reply other threads:[~2026-09-11 19:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 19:48 [PATCH v2 0/3] media: Two oopses and a hang when unbinding a streaming sensor Nicola Fiorillo
2026-09-11 19:48 ` Nicola Fiorillo [this message]
2026-09-11 19:48 ` [PATCH v2 2/3] media: v4l2-subdev: Check v4l2_dev before dereferencing it in open() Nicola Fiorillo
2026-09-11 19:48 ` [PATCH v2 3/3] media: ipu6: Signal the video queues when a sensor is unbound Nicola Fiorillo
2026-09-12 10:23 ` [PATCH v2 0/3] media: Two oopses and a hang when unbinding a streaming sensor Sakari Ailus
2026-09-12 11:20 ` Nicola Fiorillo
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=20260911194854.78894-2-nicfio@gmail.com \
--to=nicfio@gmail.com \
--cc=antti.laakso@linux.intel.com \
--cc=hverkuil@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.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®