mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sinan Turunc <enscrpt@pm.me>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH] media: cx231xx: Bound audio copies by the PCM buffer size
Date: Tue, 03 Nov 2026 12:08:29 +0000	[thread overview]
Message-ID: <20261103120813.362-1-enscrpt@pm.me> (raw)

cx231xx_audio_isocirq() and cx231xx_audio_bulkirq() split the copy into
the ALSA ring buffer once at the buffer end and wrap hwptr_done_capture
once, which is only correct when one packet holds at most buffer_size
frames. The packet size is max_pkt_size from the device's alternate
setting, while the hw constraints allow 64-byte periods with
periods_min 2, so a packet can be larger than the whole buffer.

Clamp length to buffer_size before the copy in both callbacks so the
single wrap stays inside the buffer.

Reproduced on 7.3-rc7 with a USB/IP device presenting a Pixelview
Xcapture interface layout and 1024-byte packets into a 128-byte buffer:

  BUG: KASAN: use-after-free in cx231xx_audio_isocirq+0x2c7/0x780
  Read of size 4294966528 at addr ffff88800e8e0400 by task vhci_rx/82

Fixes: e0d3bafd0258 ("V4L/DVB (10954): Add cx231xx USB driver")
Cc: stable@vger.kernel.org
Signed-off-by: Sinan Turunc <enscrpt@pm.me>
---
 drivers/media/usb/cx231xx/cx231xx-audio.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c b/drivers/media/usb/cx231xx/cx231xx-audio.c
index b24ceef497e..4e5110dd160 100644
--- a/drivers/media/usb/cx231xx/cx231xx-audio.c
+++ b/drivers/media/usb/cx231xx/cx231xx-audio.c
@@ -123,6 +123,15 @@ static void cx231xx_audio_isocirq(struct urb *urb)
 			if (!length)
 				continue;
 
+			/*
+			 * A packet can carry up to max_pkt_size, which the
+			 * device chooses, while the ring buffer can be as small
+			 * as two 64-byte periods. The single wrap below is only
+			 * valid for length <= buffer_size, so keep what fits.
+			 */
+			if (unlikely(length > runtime->buffer_size))
+				length = runtime->buffer_size;
+
 			oldptr = dev->adev.hwptr_done_capture;
 			if (oldptr + length >= runtime->buffer_size) {
 				unsigned int cnt;
@@ -210,6 +219,10 @@ static void cx231xx_audio_bulkirq(struct urb *urb)
 				     stride;
 			cp = (unsigned char *)urb->transfer_buffer;
 
+			/* same bound as in cx231xx_audio_isocirq() */
+			if (unlikely(length > runtime->buffer_size))
+				length = runtime->buffer_size;
+
 			oldptr = dev->adev.hwptr_done_capture;
 			if (oldptr + length >= runtime->buffer_size) {
 				unsigned int cnt;
-- 
2.56.0


                 reply	other threads:[~2026-11-03 12:08 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=20261103120813.362-1-enscrpt@pm.me \
    --to=enscrpt@pm.me \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=stable@vger.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

all inboxes | Powered by JetHome®