linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sameeksha Sankpal <sameekshasankpal@gmail.com>
To: mchehab@kernel.org
Cc: christophe.jaillet@wanadoo.fr, hverkuil@kernel.org,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Sameeksha Sankpal <sameekshasankpal@gmail.com>,
	syzbot+a83ee2dae0e6cc6cd3aa@syzkaller.appspotmail.com
Subject: [PATCH] media: dtv5100: fix buffer overflow in dtv5100_i2c_msg()
Date: Sat, 22 Nov 2025 15:00:56 +0530	[thread overview]
Message-ID: <20251122093056.50774-1-sameekshasankpal@gmail.com> (raw)

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


                 reply	other threads:[~2025-11-22  9:31 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=20251122093056.50774-1-sameekshasankpal@gmail.com \
    --to=sameekshasankpal@gmail.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=syzbot+a83ee2dae0e6cc6cd3aa@syzkaller.appspotmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).