public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 4.14 01/12] media: dvb-usb-v2: af9035: Fix null-ptr-deref in af9035_i2c_master_xfer
@ 2023-09-09  0:41 Sasha Levin
  2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 02/12] media: dw2102: Fix null-ptr-deref in dw2102_i2c_transfer() Sasha Levin
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: Sasha Levin @ 2023-09-09  0:41 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Zhang Shurong, Hans Verkuil, Sasha Levin, crope, mchehab,
	linux-media

From: Zhang Shurong <zhang_shurong@foxmail.com>

[ Upstream commit 7bf744f2de0a848fb1d717f5831b03db96feae89 ]

In af9035_i2c_master_xfer, msg is controlled by user. When msg[i].buf
is null and msg[i].len is zero, former checks on msg[i].buf would be
passed. Malicious data finally reach af9035_i2c_master_xfer. If accessing
msg[i].buf[0] without sanity check, null ptr deref would happen.
We add check on msg[i].len to prevent crash.

Similar commit:
commit 0ed554fd769a
("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()")

Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index 1f6c1eefe3892..55c7e7348869b 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -336,6 +336,8 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
 			ret = -EOPNOTSUPP;
 		} else if ((msg[0].addr == state->af9033_i2c_addr[0]) ||
 			   (msg[0].addr == state->af9033_i2c_addr[1])) {
+			if (msg[0].len < 3 || msg[1].len < 1)
+				return -EOPNOTSUPP;
 			/* demod access via firmware interface */
 			u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
 					msg[0].buf[2];
@@ -395,6 +397,8 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
 			ret = -EOPNOTSUPP;
 		} else if ((msg[0].addr == state->af9033_i2c_addr[0]) ||
 			   (msg[0].addr == state->af9033_i2c_addr[1])) {
+			if (msg[0].len < 3)
+				return -EOPNOTSUPP;
 			/* demod access via firmware interface */
 			u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
 					msg[0].buf[2];
@@ -402,10 +406,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
 			if (msg[0].addr == state->af9033_i2c_addr[1])
 				reg |= 0x100000;
 
-			ret = (msg[0].len >= 3) ? af9035_wr_regs(d, reg,
-							         &msg[0].buf[3],
-							         msg[0].len - 3)
-					        : -EOPNOTSUPP;
+			ret = af9035_wr_regs(d, reg, &msg[0].buf[3], msg[0].len - 3);
 		} else {
 			/* I2C write */
 			u8 buf[MAX_XFER_SIZE];
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-09-10 13:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-09  0:41 [PATCH AUTOSEL 4.14 01/12] media: dvb-usb-v2: af9035: Fix null-ptr-deref in af9035_i2c_master_xfer Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 02/12] media: dw2102: Fix null-ptr-deref in dw2102_i2c_transfer() Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 03/12] media: af9005: Fix null-ptr-deref in af9005_i2c_xfer Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 04/12] media: anysee: fix null-ptr-deref in anysee_master_xfer Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 05/12] media: az6007: Fix null-ptr-deref in az6007_i2c_xfer() Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 06/12] iio: core: Use min() instead of min_t() to make code more robust Sasha Levin
2023-09-10 13:23   ` Jonathan Cameron
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 07/12] media: tuners: qt1010: replace BUG_ON with a regular error Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 08/12] media: pci: cx23885: replace BUG with error return Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 09/12] usb: gadget: fsl_qe_udc: validate endpoint index for ch9 udc Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 10/12] scsi: target: iscsi: Fix buffer overflow in lio_target_nacl_info_show() Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 11/12] serial: cpm_uart: Avoid suspicious locking Sasha Levin
2023-09-09  0:41 ` [PATCH AUTOSEL 4.14 12/12] kobject: Add sanity check for kset->kobj.ktype in kset_register() Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox