Skip to content

Commit 5cbfae4

Browse files
noopwafelgregkh
authored andcommitted
ttusb2: limit messages to buffer size
commit a12b8ab8c5ff7ccd7b107a564743507c850a441d upstream. Otherwise ttusb2_i2c_xfer can read or write beyond the end of static and heap buffers. Signed-off-by: Alyssa Milburn <amilburn@zall.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9737909 commit 5cbfae4

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd,
7878
u8 *s, *r = NULL;
7979
int ret = 0;
8080

81+
if (4 + rlen > 64)
82+
return -EIO;
83+
8184
s = kzalloc(wlen+4, GFP_KERNEL);
8285
if (!s)
8386
return -ENOMEM;
@@ -381,6 +384,22 @@ static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num
381384
write_read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
382385
read = msg[i].flags & I2C_M_RD;
383386

387+
if (3 + msg[i].len > sizeof(obuf)) {
388+
err("i2c wr len=%d too high", msg[i].len);
389+
break;
390+
}
391+
if (write_read) {
392+
if (3 + msg[i+1].len > sizeof(ibuf)) {
393+
err("i2c rd len=%d too high", msg[i+1].len);
394+
break;
395+
}
396+
} else if (read) {
397+
if (3 + msg[i].len > sizeof(ibuf)) {
398+
err("i2c rd len=%d too high", msg[i].len);
399+
break;
400+
}
401+
}
402+
384403
obuf[0] = (msg[i].addr << 1) | (write_read | read);
385404
if (read)
386405
obuf[1] = 0;

0 commit comments

Comments
 (0)