]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.30/ttusb2-limit-messages-to-buffer-size.patch
Linux 4.14.95
[thirdparty/kernel/stable-queue.git] / releases / 4.9.30 / ttusb2-limit-messages-to-buffer-size.patch
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
5
6 From: Alyssa Milburn <amilburn@zall.org>
7
8 commit a12b8ab8c5ff7ccd7b107a564743507c850a441d upstream.
9
10 Otherwise ttusb2_i2c_xfer can read or write beyond the end of static and
11 heap buffers.
12
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>
16
17 ---
18 drivers/media/usb/dvb-usb/ttusb2.c | 19 +++++++++++++++++++
19 1 file changed, 19 insertions(+)
20
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
24 u8 *s, *r = NULL;
25 int ret = 0;
26
27 + if (4 + rlen > 64)
28 + return -EIO;
29 +
30 s = kzalloc(wlen+4, GFP_KERNEL);
31 if (!s)
32 return -ENOMEM;
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;
36
37 + if (3 + msg[i].len > sizeof(obuf)) {
38 + err("i2c wr len=%d too high", msg[i].len);
39 + break;
40 + }
41 + if (write_read) {
42 + if (3 + msg[i+1].len > sizeof(ibuf)) {
43 + err("i2c rd len=%d too high", msg[i+1].len);
44 + break;
45 + }
46 + } else if (read) {
47 + if (3 + msg[i].len > sizeof(ibuf)) {
48 + err("i2c rd len=%d too high", msg[i].len);
49 + break;
50 + }
51 + }
52 +
53 obuf[0] = (msg[i].addr << 1) | (write_read | read);
54 if (read)
55 obuf[1] = 0;