Skip to content

Commit 858e97d

Browse files
harperchenmchehab
authored andcommitted
media: dvb-usb: az6027: fix three null-ptr-deref in az6027_i2c_xfer()
In az6027_i2c_xfer, msg is controlled by user. When msg[i].buf is null, commit 0ed554f ("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()") fix the null-ptr-deref bug when msg[i].addr is 0x99. However, null-ptr-deref also happens when msg[i].addr is 0xd0 and 0xc0. We add check on msg[i].len to prevent null-ptr-deref. Link: https://lore.kernel.org/linux-media/20230310165604.3093483-1-harperchen1110@gmail.com Signed-off-by: Wei Chen <harperchen1110@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
1 parent 0f5bb36 commit 858e97d

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

drivers/media/usb/dvb-usb/az6027.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,10 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
988988
/* write/read request */
989989
if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD)) {
990990
req = 0xB9;
991+
if (msg[i].len < 1) {
992+
i = -EOPNOTSUPP;
993+
break;
994+
}
991995
index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff));
992996
value = msg[i].addr + (msg[i].len << 8);
993997
length = msg[i + 1].len + 6;
@@ -1001,6 +1005,10 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
10011005

10021006
/* demod 16bit addr */
10031007
req = 0xBD;
1008+
if (msg[i].len < 1) {
1009+
i = -EOPNOTSUPP;
1010+
break;
1011+
}
10041012
index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff));
10051013
value = msg[i].addr + (2 << 8);
10061014
length = msg[i].len - 2;
@@ -1026,6 +1034,10 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
10261034
} else {
10271035

10281036
req = 0xBD;
1037+
if (msg[i].len < 1) {
1038+
i = -EOPNOTSUPP;
1039+
break;
1040+
}
10291041
index = msg[i].buf[0] & 0x00FF;
10301042
value = msg[i].addr + (1 << 8);
10311043
length = msg[i].len - 1;

0 commit comments

Comments
 (0)