linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: dtv5100: fix buffer overflow in dtv5100_i2c_msg()
@ 2025-11-22  9:30 Sameeksha Sankpal
  0 siblings, 0 replies; only message in thread
From: Sameeksha Sankpal @ 2025-11-22  9:30 UTC (permalink / raw)
  To: mchehab
  Cc: christophe.jaillet, hverkuil, linux-media, linux-kernel,
	Sameeksha Sankpal, syzbot+a83ee2dae0e6cc6cd3aa

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:
Reported-by: syzbot+a83ee2dae0e6cc6cd3aa@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a83ee2dae0e6cc6cd3aa
Signed-off-by: Sameeksha Sankpal <sameekshasankpal@gmail.com>
---
 drivers/media/usb/dvb-usb/dtv5100.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dtv5100.c b/drivers/media/usb/dvb-usb/dtv5100.c
index 3d85c6f7f6ec..df1ce9b49ecf 100644
--- a/drivers/media/usb/dvb-usb/dtv5100.c
+++ b/drivers/media/usb/dvb-usb/dtv5100.c
@@ -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);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-11-22  9:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-22  9:30 [PATCH] media: dtv5100: fix buffer overflow in dtv5100_i2c_msg() Sameeksha Sankpal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).