Skip to contentSkip to conversation

media: dtv5100: fix buffer overflow in dtv5100_i2c_msg()

PATCH New Sameeksha Sankpal 1 participant 1 message Nov 22, 2025 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: dtv5100: fix buffer overflow in dtv5100_i2c_msg()

syzbot reported a field-spanning write where rlen (4096 bytes) is copied into st->data, which is only 80 bytes in size. This causes a buffer overflow and triggers KASAN warnings.

Clamp the copy size using min_t() to ensure we never write beyond the bounds of st->data, and pass the clamped size to usb_control_msg().

This fixes the following syzbot report:

---
 drivers/media/usb/dvb-usb/dtv5100.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/media/usb/dvb-usb/dtv5100.c +5 -2
index 3d85c6f7f6ec..df1ce9b49ecf 100644
@@ -55,10 +55,13 @@ static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
 	}
 	index = (addr << 8) + wbuf[0];
 
-	memcpy(st->data, rbuf, rlen);
+	/* Prevent buffer overflow: st->data is 80 bytes */
+	size_t copy_len = min_t(size_t, rlen, sizeof(st->data));
+
+	memcpy(st->data, rbuf, copy_len);
 	msleep(1); /* avoid I2C errors */
 	return usb_control_msg(d->udev, pipe, request,
-			       type, value, index, st->data, rlen,
+			       type, value, index, st->data, copy_len,
 			       DTV5100_USB_TIMEOUT);
 }
 
Signature · 1 line
2.43.0