From: Nicola Fiorillo <nicfio@gmail.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 2/2] media: v4l2-subdev: Fix NULL pointer dereference in the EXT_CTRLS ioctls
Date: Thu, 8 Oct 2026 06:26:00 +0200 [thread overview]
Message-ID: <20261008042600.275884-3-nicfio@gmail.com> (raw)
In-Reply-To: <20261008042600.275884-1-nicfio@gmail.com>
VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS and VIDIOC_TRY_EXT_CTRLS on a
sub-device node pass sd->v4l2_dev->mdev to the control framework.
v4l2_device_unregister_subdev() clears sd->v4l2_dev before it
unregisters the device node, and nothing serialises the
video_is_registered() checks in v4l2_ioctl() and subdev_do_ioctl_lock()
against it: sub-device nodes have no vdev->lock, and unregistration
would not take it anyway. An EXT_CTRLS ioctl on a file handle opened
before a driver is unbound can therefore dereference NULL:
KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
RIP: 0010:subdev_do_ioctl+0x1926/0x2550
Call Trace:
subdev_do_ioctl_lock+0x246/0x5c0
video_usercopy+0x47b/0xcc0
v4l2_ioctl+0x187/0x1f0
__x64_sys_ioctl+0x134/0x1c0
Use vdev->v4l2_dev->mdev instead, as the previous patch does in
subdev_open(), and as the video node ioctls already do.
Found by reading the code, then reproduced in QEMU with KASAN: with the
previous patch applied, threads looping on VIDIOC_G_EXT_CTRLS on vimc's
sub-device nodes while vimc is unbound and rebound hit the oops above;
with this patch the same test shows no oops, KASAN report or warning.
Fixes: c41e9cff704a ("media: v4l2-ctrls: support g/s_ext_ctrls for requests")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Nicola Fiorillo <nicfio@gmail.com>
---
drivers/media/v4l2-core/v4l2-subdev.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index c56ca328f..1a2ae7c13 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -775,19 +775,19 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,
if (!vfh->ctrl_handler)
return -ENOTTY;
return v4l2_g_ext_ctrls(vfh->ctrl_handler,
- vdev, sd->v4l2_dev->mdev, arg);
+ vdev, vdev->v4l2_dev->mdev, arg);
case VIDIOC_S_EXT_CTRLS:
if (!vfh->ctrl_handler)
return -ENOTTY;
return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler,
- vdev, sd->v4l2_dev->mdev, arg);
+ vdev, vdev->v4l2_dev->mdev, arg);
case VIDIOC_TRY_EXT_CTRLS:
if (!vfh->ctrl_handler)
return -ENOTTY;
return v4l2_try_ext_ctrls(vfh->ctrl_handler,
- vdev, sd->v4l2_dev->mdev, arg);
+ vdev, vdev->v4l2_dev->mdev, arg);
case VIDIOC_DQEVENT:
if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS))
--
2.47.3
next prev parent reply other threads:[~2026-10-08 4:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 4:25 [PATCH v3 0/2] media: v4l2-subdev: Fix NULL dereferences racing with unbind Nicola Fiorillo
2026-10-08 4:25 ` [PATCH v3 1/2] media: v4l2-subdev: Fix NULL pointer dereference in subdev_open() Nicola Fiorillo
2026-10-08 5:48 ` Laurent Pinchart
2026-10-08 7:06 ` Nicola Fiorillo
2026-10-09 9:48 ` Laurent Pinchart
2026-10-09 10:37 ` Nicola Fiorillo
2026-10-08 4:26 ` Nicola Fiorillo [this message]
2026-10-08 10:44 ` [PATCH v3 2/2] media: v4l2-subdev: Fix NULL pointer dereference in the EXT_CTRLS ioctls Sakari Ailus
2026-10-08 13:55 ` 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=20261008042600.275884-3-nicfio@gmail.com \
--to=nicfio@gmail.com \
--cc=hverkuil@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ngocthang2710.1999@gmail.com \
--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®