From: Cong Nguyen <congnt264@gmail.com>
To: Maxime Ripard <mripard@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
linux-media@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/3] media: sun4i-csi: add notifier unbind callback to drop the source subdev
Date: Mon, 10 Aug 2026 13:25:21 +0700 [thread overview]
Message-ID: <20260810062521.1709379-4-congnt264@gmail.com> (raw)
In-Reply-To: <20260810062521.1709379-1-congnt264@gmail.com>
sun4i_csi_notify_ops only implements .bound and .complete. The .bound
callback caches the remote sensor's subdevice in csi->src_subdev. When
that subdevice goes away (e.g. its module is unloaded), the V4L2 async
core frees it, but without an .unbind callback the driver keeps the
stale pointer.
A subsequent VIDIOC_STREAMON reaches sun4i_csi_start_streaming(), which
calls v4l2_subdev_call(csi->src_subdev, video, s_stream, 1) on the freed
subdev, resulting in a use-after-free.
Add an .unbind callback that clears csi->src_subdev. The pointer is only
dereferenced by v4l2_subdev_call() (NULL-guarded, returns -ENODEV, so
streaming fails cleanly) and by sun4i_csi_notify_complete() (which only
runs while a subdev is bound), so clearing it is sufficient to prevent
the use-after-free.
Fixes: 577bbf23b758 ("media: sunxi: Add A10 CSI driver")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4
Signed-off-by: Cong Nguyen <congnt264@gmail.com>
---
.../media/platform/sunxi/sun4i-csi/sun4i_csi.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c
index a8711336a754..f19508f2c7ed 100644
--- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c
+++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c
@@ -122,8 +122,25 @@ static int sun4i_csi_notify_complete(struct v4l2_async_notifier *notifier)
return ret;
}
+static void sun4i_csi_notify_unbind(struct v4l2_async_notifier *notifier,
+ struct v4l2_subdev *subdev,
+ struct v4l2_async_connection *asd)
+{
+ struct sun4i_csi *csi = container_of(notifier, struct sun4i_csi,
+ notifier);
+
+ /*
+ * The remote subdev is being freed. Drop our cached pointer so that a
+ * subsequent sun4i_csi_start_streaming() does not issue a
+ * v4l2_subdev_call() on the now dangling source subdev. The call is
+ * NULL-guarded and returns -ENODEV, so streaming fails cleanly.
+ */
+ csi->src_subdev = NULL;
+}
+
static const struct v4l2_async_notifier_operations sun4i_csi_notify_ops = {
.bound = sun4i_csi_notify_bound,
+ .unbind = sun4i_csi_notify_unbind,
.complete = sun4i_csi_notify_complete,
};
--
2.25.1
prev parent reply other threads:[~2026-08-10 6:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 11:05 [PATCH v1 0/3] media: sun4i-csi: fix lifecycle bugs (leak, IRQ, unbind) Cong Nguyen
2026-08-08 11:06 ` [PATCH v1 1/3] media: sun4i-csi: fix video device and subdev leak in notify_complete() Cong Nguyen
2026-08-08 11:17 ` [PATCH v1 2/3] media: sun4i-csi: disable interrupts when stopping streaming Cong Nguyen
2026-08-08 11:17 ` [PATCH v1 3/3] media: sun4i-csi: add notifier unbind callback to drop the source subdev Cong Nguyen
2026-08-10 6:25 ` [PATCH v2 0/3] media: sun4i-csi: fix probe/streaming lifecycle bugs Cong Nguyen
2026-08-10 6:25 ` [PATCH v2 1/3] media: sun4i-csi: fix video device and subdev leak in notify_complete() Cong Nguyen
2026-08-10 6:25 ` [PATCH v2 2/3] media: sun4i-csi: disable interrupts when stopping streaming Cong Nguyen
2026-08-10 6:25 ` Cong Nguyen [this message]
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=20260810062521.1709379-4-congnt264@gmail.com \
--to=congnt264@gmail.com \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=mripard@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=samuel@sholland.org \
--cc=wens@kernel.org \
/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