[PATCH] media: dvb-usb: az6027: fix out-of-bounds in az6027_i2c_xfer()

Jeongjun Park posted 1 patch 9 months, 3 weeks ago
There is a newer version of this series
drivers/media/usb/dvb-usb/az6027.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] media: dvb-usb: az6027: fix out-of-bounds in az6027_i2c_xfer()
Posted by Jeongjun Park 9 months, 3 weeks ago
Missing maximum size check on msg[i].len causes out-of-bounds vuln for u8 *data.
Therefore, we need to add proper range checking to prevent this vuln.

Fixes: 858e97d7956d ("media: dvb-usb: az6027: fix three null-ptr-deref in az6027_i2c_xfer()")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
 drivers/media/usb/dvb-usb/az6027.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/az6027.c b/drivers/media/usb/dvb-usb/az6027.c
index 056935d3cbd6..f9bd8a4c1577 100644
--- a/drivers/media/usb/dvb-usb/az6027.c
+++ b/drivers/media/usb/dvb-usb/az6027.c
@@ -988,7 +988,7 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
 			/* write/read request */
 			if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD)) {
 				req = 0xB9;
-				if (msg[i].len < 1) {
+				if (msg[i].len < 1 || msg[i + 1].len + 5 > sizeof(data)) {
 					i = -EOPNOTSUPP;
 					break;
 				}
@@ -1005,7 +1005,7 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
 
 				/* demod 16bit addr */
 				req = 0xBD;
-				if (msg[i].len < 1) {
+				if (msg[i].len < 1 || msg[i].len - 2 > sizeof(data)) {
 					i = -EOPNOTSUPP;
 					break;
 				}
@@ -1034,7 +1034,7 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
 			} else {
 
 				req = 0xBD;
-				if (msg[i].len < 1) {
+				if (msg[i].len < 1 || msg[i].len - 1 > sizeof(data)) {
 					i = -EOPNOTSUPP;
 					break;
 				}
--