[PATCH] media: stk1160: clamp the payload to the buffer size

From: YuanZhe Liu

Date: Sat Dec 05 2026 - 11:55:17 EST


stk1160_buffer_done() passes buf->bytesused to vb2_set_plane_payload()
without checking that it fits in the plane. bytesused is only cleared
when a buffer is queued, while pos is reset every time a new field
starts. A stream that contains an extra 0x80 marker therefore makes
the driver copy three field segments into the same buffer. Each
segment can fill half of the buffer, so bytesused reaches 1.5 times
the plane size and the WARN_ON_ONCE() in vb2_set_plane_payload() is
triggered.

Clamp bytesused to buf->length before reporting the payload, in the
same way gspca_frame_add() limits a frame that overflows its image
buffer.

Fixes: 9cb2173e6ea8 ("[media] media: Add stk1160 new driver (easycap replacement)")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/media/usb/stk1160/stk1160-video.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/stk1160/stk1160-video.c b/drivers/media/usb/stk1160/stk1160-video.c
index 020b75fc5b2d..0543239b9172 100644
--- a/drivers/media/usb/stk1160/stk1160-video.c
+++ b/drivers/media/usb/stk1160/stk1160-video.c
@@ -93,7 +93,8 @@ void stk1160_buffer_done(struct stk1160 *dev)
buf->vb.field = V4L2_FIELD_INTERLACED;
buf->vb.vb2_buf.timestamp = ktime_get_ns();

- vb2_set_plane_payload(&buf->vb.vb2_buf, 0, buf->bytesused);
+ vb2_set_plane_payload(&buf->vb.vb2_buf, 0,
+ min(buf->bytesused, buf->length));
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);

dev->isoc_ctl.buf = NULL;
--
2.34.1