1 From a12b8ab8c5ff7ccd7b107a564743507c850a441d Mon Sep 17 00:00:00 2001
2 From: Alyssa Milburn <amilburn@zall.org>
3 Date: Sat, 1 Apr 2017 14:34:32 -0300
4 Subject: [media] ttusb2: limit messages to buffer size
6 From: Alyssa Milburn <amilburn@zall.org>
8 commit a12b8ab8c5ff7ccd7b107a564743507c850a441d upstream.
10 Otherwise ttusb2_i2c_xfer can read or write beyond the end of static and
13 Signed-off-by: Alyssa Milburn <amilburn@zall.org>
14 Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18 drivers/media/usb/dvb-usb/ttusb2.c | 19 +++++++++++++++++++
19 1 file changed, 19 insertions(+)
21 --- a/drivers/media/usb/dvb-usb/ttusb2.c
22 +++ b/drivers/media/usb/dvb-usb/ttusb2.c
23 @@ -78,6 +78,9 @@ static int ttusb2_msg(struct dvb_usb_dev
30 s = kzalloc(wlen+4, GFP_KERNEL);
33 @@ -381,6 +384,22 @@ static int ttusb2_i2c_xfer(struct i2c_ad
34 write_read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
35 read = msg[i].flags & I2C_M_RD;
37 + if (3 + msg[i].len > sizeof(obuf)) {
38 + err("i2c wr len=%d too high", msg[i].len);
42 + if (3 + msg[i+1].len > sizeof(ibuf)) {
43 + err("i2c rd len=%d too high", msg[i+1].len);
47 + if (3 + msg[i].len > sizeof(ibuf)) {
48 + err("i2c rd len=%d too high", msg[i].len);
53 obuf[0] = (msg[i].addr << 1) | (write_read | read);