[PATCH] media: cx231xx: clamp bulk buffer copy length to vb2 plane size
From: Elkin Cruz
Date: Wed Nov 25 2026 - 17:28:39 EST
In cx231xx-417, start_streaming() initializes bulk URB buffers of size
320 * max_pkt_size (up to 163,840 bytes for 512-byte USB 2.0 bulk
endpoints), whereas queue_setup() allocates vb2 plane buffers of size
mpeglinesize * mpeglines (65,536 bytes by default). Passing unchecked
len into buffer_filled() overflows the destination vb2 plane buffer
when actual_length exceeds the plane size.
Guard against non-positive lengths in buffer_filled(), clamp the copy
length to vb2_plane_size(), and record the payload length via
vb2_set_plane_payload().
Fixes: 64fbf4445526 ("[media] cx231xx: Added support for Carraera, Shelby, RDx_253S and VIDEO_GRABBER")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Elkin Cruz <elkin@xxxxxxxxxx>
---
I am trying out new Clang static analysis checks for kernel bug
classes, and they flagged this code as possibly buggy. The findings
were triaged/fixed and commit descriptions were drafted with help of AI,
then checked against linux-next (not runtime-tested on hardware).
Thanks,
Elkin
drivers/media/usb/cx231xx/cx231xx-417.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c
index 55af8b9f2038..0b3e856f6d21 100644
--- a/drivers/media/usb/cx231xx/cx231xx-417.c
+++ b/drivers/media/usb/cx231xx/cx231xx-417.c
@@ -1297,15 +1297,18 @@ static void buffer_filled(char *data, int len, struct urb *urb,
{
void *vbuf;
struct cx231xx_buffer *buf;
+ size_t copy_len;
- if (list_empty(&dma_q->active))
+ if (len <= 0 || list_empty(&dma_q->active))
return;
buf = list_entry(dma_q->active.next, struct cx231xx_buffer, list);
/* Fill buffer */
vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
- memcpy(vbuf, data, len);
+ copy_len = min_t(size_t, len, vb2_plane_size(&buf->vb.vb2_buf, 0));
+ memcpy(vbuf, data, copy_len);
+ vb2_set_plane_payload(&buf->vb.vb2_buf, 0, copy_len);
buf->vb.sequence = dma_q->sequence++;
buf->vb.vb2_buf.timestamp = ktime_get_ns();
list_del(&buf->list);
--
2.56.1.839.g22a8290db9-goog