mbox series

[4.14,0/1] Fix NULL dereference in i2cdev_ioctl_rdwr()

Message ID 20221003084346.4652-1-harshit.m.mogalapalli@oracle.com
Headers show
Series Fix NULL dereference in i2cdev_ioctl_rdwr() | expand


Harshit Mogalapalli Oct. 3, 2022, 8:43 a.m. UTC
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_rdwr.isra.2+0x360/0x360
  ? syscall_trace_enter+0x159/0x4a0
 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

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.


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(-)