From: "Cen Zhang (Microsoft)" <blbllhy@gmail.com>
To: mchehab@kernel.org, hverkuil@kernel.org
Cc: kees@kernel.org, rongqianfeng@vivo.com, axboe@kernel.dk,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
AutonomousCodeSecurity@microsoft.com,
tgopinath@linux.microsoft.com, kys@microsoft.com,
blbllhy@gmail.com, stable@vger.kernel.org
Subject: [PATCH] media: dvb-core: fix race between dvb_dvr_read() and dvb_dvr_set_buffer_size()
Date: Wed, 22 Jul 2026 20:00:16 -0400 [thread overview]
Message-ID: <20260723000016.84091-1-blbllhy@gmail.com> (raw)
dvb_dvr_read() accesses the DVR ring buffer without holding
dmxdev->mutex, while ioctl(DMX_SET_BUFFER_SIZE) replaces the backing
memory of the buffer under that mutex. A concurrent resize can free
the vmalloc region while the reader is still copying from it,
resulting in a use-after-free read.
BUG: KASAN: vmalloc-out-of-bounds in _copy_to_user+0x4e/0x80
_copy_to_user+0x4e/0x80
dvb_ringbuffer_read_user+0x141/0x390 (dvb_ringbuffer.c:151)
dvb_dmxdev_buffer_read.isra.0+0x310/0x3e0
dvb_dvr_read+0xc6/0x110
vfs_read+0x1ac/0x940
This is a re-discovery of an issue noted by the original author:
https://lore.kernel.org/all/47E45138.1030107@googlemail.com/.
Fix by protecting dvb_dvr_read() with dmxdev->mutex.
Fixes: a095be4b030c ("V4L/DVB (7659): dvb-core: Implement DMX_SET_BUFFER_SIZE for dvr")
Cc: stable@vger.kernel.org
Reported-by: AutonomousCodeSecurity@microsoft.com
Signed-off-by: Cen Zhang (Microsoft) <blbllhy@gmail.com>
---
drivers/media/dvb-core/dmxdev.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index 3c8bc75e4d6c..b4aa8d37ff03 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -270,13 +270,23 @@ static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count,
{
struct dvb_device *dvbdev = file->private_data;
struct dmxdev *dmxdev = dvbdev->priv;
+ ssize_t ret;
- if (dmxdev->exit)
+ if (mutex_lock_interruptible(&dmxdev->mutex))
+ return -ERESTARTSYS;
+
+ if (dmxdev->exit) {
+ mutex_unlock(&dmxdev->mutex);
return -ENODEV;
+ }
+
+ ret = dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer,
+ file->f_flags & O_NONBLOCK,
+ buf, count, ppos);
- return dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer,
- file->f_flags & O_NONBLOCK,
- buf, count, ppos);
+ mutex_unlock(&dmxdev->mutex);
+
+ return ret;
}
static int dvb_dvr_set_buffer_size(struct dmxdev *dmxdev,
--
2.53.0
reply other threads:[~2026-07-23 0:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260723000016.84091-1-blbllhy@gmail.com \
--to=blbllhy@gmail.com \
--cc=AutonomousCodeSecurity@microsoft.com \
--cc=axboe@kernel.dk \
--cc=hverkuil@kernel.org \
--cc=kees@kernel.org \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=rongqianfeng@vivo.com \
--cc=stable@vger.kernel.org \
--cc=tgopinath@linux.microsoft.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