Otherwise ttusb2_i2c_xfer can read or write beyond the end of static and
heap buffers.
Signed-off-by: Alyssa Milburn <amilburn@zall.org>
Cc: stable@vger.kernel.org
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
        u8 *s, *r = NULL;
        int ret = 0;
 
+       if (4 + rlen > 64)
+               return -EIO;
+
        s = kzalloc(wlen+4, GFP_KERNEL);
        if (!s)
                return -ENOMEM;
                write_read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
                read = msg[i].flags & I2C_M_RD;
 
+               if (3 + msg[i].len > sizeof(obuf)) {
+                       err("i2c wr len=%d too high", msg[i].len);
+                       break;
+               }
+               if (write_read) {
+                       if (3 + msg[i+1].len > sizeof(ibuf)) {
+                               err("i2c rd len=%d too high", msg[i+1].len);
+                               break;
+                       }
+               } else if (read) {
+                       if (3 + msg[i].len > sizeof(ibuf)) {
+                               err("i2c rd len=%d too high", msg[i].len);
+                               break;
+                       }
+               }
+
                obuf[0] = (msg[i].addr << 1) | (write_read | read);
                if (read)
                        obuf[1] = 0;