Skip to content

Commit a6dcefc

Browse files
harperchenmchehab
authored andcommitted
media: dvb-usb-v2: ec168: fix null-ptr-deref in ec168_i2c_xfer()
In ec168_i2c_xfer, msg is controlled by user. When msg[i].buf is null and msg[i].len is zero, former checks on msg[i].buf would be passed. If accessing msg[i].buf[0] without sanity check, null pointer deref would happen. We add check on msg[i].len to prevent crash. Similar commit: commit 0ed554f ("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()") Link: https://lore.kernel.org/linux-media/20230313085853.3252349-1-harperchen1110@gmail.com Signed-off-by: Wei Chen <harperchen1110@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
1 parent 858e97d commit a6dcefc

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

  • drivers/media/usb/dvb-usb-v2

drivers/media/usb/dvb-usb-v2/ec168.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ static int ec168_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
115115
while (i < num) {
116116
if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
117117
if (msg[i].addr == ec168_ec100_config.demod_address) {
118+
if (msg[i].len < 1) {
119+
i = -EOPNOTSUPP;
120+
break;
121+
}
118122
req.cmd = READ_DEMOD;
119123
req.value = 0;
120124
req.index = 0xff00 + msg[i].buf[0]; /* reg */
@@ -131,6 +135,10 @@ static int ec168_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
131135
}
132136
} else {
133137
if (msg[i].addr == ec168_ec100_config.demod_address) {
138+
if (msg[i].len < 1) {
139+
i = -EOPNOTSUPP;
140+
break;
141+
}
134142
req.cmd = WRITE_DEMOD;
135143
req.value = msg[i].buf[1]; /* val */
136144
req.index = 0xff00 + msg[i].buf[0]; /* reg */
@@ -139,6 +147,10 @@ static int ec168_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
139147
ret = ec168_ctrl_msg(d, &req);
140148
i += 1;
141149
} else {
150+
if (msg[i].len < 1) {
151+
i = -EOPNOTSUPP;
152+
break;
153+
}
142154
req.cmd = WRITE_I2C;
143155
req.value = msg[i].buf[0]; /* val */
144156
req.index = 0x0100 + msg[i].addr; /* I2C addr */

0 commit comments

Comments
 (0)