[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20221003084346.4652-2-harshit.m.mogalapalli@oracle.com>
Date: Mon, 3 Oct 2022 01:43:46 -0700
From: Harshit Mogalapalli <harshit.m.mogalapalli@...cle.com>
To: unlisted-recipients:; (no To-header on input)
Cc: harshit.m.mogalapalli@...cle.com, george.kennedy@...cle.com,
darren.kenny@...cle.com, vegard.nossum@...cle.com,
stable@...r.kernel.org, Alexander Popov <alex.popov@...ux.com>,
Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>, Wolfram Sang <wsa@...-dreams.de>,
linux-i2c@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 4.14 1/1] i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr()
From: Alexander Popov <alex.popov@...ux.com>
commit 23a27722b5292ef0b27403c87a109feea8296a5c upstream.
i2cdev_ioctl_rdwr() allocates i2c_msg.buf using memdup_user(), which
returns ZERO_SIZE_PTR if i2c_msg.len is zero.
Currently i2cdev_ioctl_rdwr() always dereferences the buf pointer in case
of I2C_M_RD | I2C_M_RECV_LEN transfer. That causes a kernel oops in
case of zero len.
Let's check the len against zero before dereferencing buf pointer.
This issue was triggered by syzkaller.
Signed-off-by: Alexander Popov <alex.popov@...ux.com>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
[wsa: use '< 1' instead of '!' for easier readability]
Signed-off-by: Wolfram Sang <wsa@...-dreams.de>
[Harshit: backport to 4.14.y, use rdwr_pa[i].len instead of msgs[i].len
as the 4.14.y code uses rdwr_pa.]
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@...cle.com>
---
Conflicts:
drivers/i2c/i2c-dev.c - use rdwr_pa[i].len instead of
msgs[i].len
Since a NULL pointer dereference happens on 4.14.y this backport patch
will fix the issue.
---
drivers/i2c/i2c-dev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index b7f9fb00f695..08aff5ebc99a 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -297,7 +297,7 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,
*/
if (rdwr_pa[i].flags & I2C_M_RECV_LEN) {
if (!(rdwr_pa[i].flags & I2C_M_RD) ||
- rdwr_pa[i].buf[0] < 1 ||
+ rdwr_pa[i].len < 1 || rdwr_pa[i].buf[0] < 1 ||
rdwr_pa[i].len < rdwr_pa[i].buf[0] +
I2C_SMBUS_BLOCK_MAX) {
i++;
--
2.37.1
Powered by blists - more mailing lists