[PATCH] media: dvb-usb: dw2102: fix null-ptr-deref in su3000_i2c_transfer

From: Alex Guo
Date: Fri Jun 20 2025 - 17:26:24 EST


msg is controlled by user. If accessing msg.buf without sanity
check, null pointer deref would happen. We add check on
msg.len to prevent crash.

Similar commit: commit 0ed554fd769a ("media: dvb-usb: az6027:
fix null-ptr-deref in az6027_i2c_xfer()")

Signed-off-by: Alex Guo <alexguo1023@xxxxxxxxx>
---
drivers/media/usb/dvb-usb/dw2102.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
index 8f694d8d52bc..54493bc490ae 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -746,6 +746,10 @@ static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
while (j < num) {
switch (msg[j].addr) {
case SU3000_STREAM_CTRL:
+ if (msg[j].len < 1) {
+ num = -EOPNOTSUPP;
+ break;
+ }
state->data[0] = msg[j].buf[0] + 0x36;
state->data[1] = 3;
state->data[2] = 0;
@@ -754,6 +758,10 @@ static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
err("i2c transfer failed.");
break;
case DW2102_RC_QUERY:
+ if (msg[j].len < 2) {
+ num = -EOPNOTSUPP;
+ break;
+ }
state->data[0] = 0x10;
if (dvb_usb_generic_rw(d, state->data, 1,
state->data, 2, 0) < 0)
--
2.34.1