This backport patch addresses a NULL pointer dereference bug in 4.14.y
BUG: unable to handle kernel NULL pointer dereference at 0000000000000010
IP: i2cdev_ioctl_rdwr.isra.2+0xe4/0x360
PGD 13af50067 P4D 13af50067 PUD 13504c067 PMD 0
Oops: 0000 [#1] PREEMPT SMP
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
CPU: 1 PID: 17421 Comm: rep Not tainted 4.14.295 #7
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-2.el7 04/01/2014
task: ffff88807c43a080 task.stack: ffffc90000d0c000
RIP: 0010:i2cdev_ioctl_rdwr.isra.2+0xe4/0x360
RSP: 0018:ffffc90000d0fdf0 EFLAGS: 00010297
RAX: ffff88807c43a080 RBX: 0000000000000000 RCX: 0000000000000000
....
Call Trace:
i2cdev_ioctl+0x1a5/0x2a0
? i2cdev_ioctl_rdwr.isra.2+0x360/0x360
do_vfs_ioctl+0xac/0x840
? syscall_trace_enter+0x159/0x4a0
SyS_ioctl+0x7e/0xb0
do_syscall_64+0x8d/0x220
....
RIP: i2cdev_ioctl_rdwr.isra.2+0xe4/0x360 RSP: ffffc90000d0fdf0
....
Kernel panic - not syncing: Fatal exception
Rebooting in 86400 seconds..
rdwr_pa[i].buf[0] is a NULL dereference when len=0, so to avoid
dereferencing zero-length buffer we add a check on len before
dereferencing.
I have tested only with the reproducer and the bug doesnot occur
after this patch.
This patch is only made for 4.14.y as other higher LTS branches
(>=4.19.y) already have the fix.
Thanks,
Harshit
Alexander Popov (1):
i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr()
drivers/i2c/i2c-dev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.37.1
From: Alexander Popov <[email protected]>
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 <[email protected]>
Reviewed-by: Uwe Kleine-König <[email protected]>
[wsa: use '< 1' instead of '!' for easier readability]
Signed-off-by: Wolfram Sang <[email protected]>
[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 <[email protected]>
---
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