[lvc-project] [PATCH] usb: dvb-usb-v2: fix i2c race condition during device probe

Nalivayko Sergey Sergey.Nalivayko at kaspersky.com
Tue Jul 22 12:22:27 MSK 2025


syzbot reports a KASAN issue as below:

Oops: general protection fault, probably for non-canonical address 0xdffffc0000000019: 0000 [#1] SMP KASAN PTI
KASAN: null-ptr-deref in range [0x00000000000000c8-0x00000000000000cf]
CPU: 1 UID: 0 PID: 5849 Comm: syz-executor279 Not tainted 6.15.0-rc2-syzkaller #0 PREEMPT(full) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2025
RIP: 0010:__mutex_lock_common kernel/locking/mutex.c:580 [inline]
RIP: 0010:__mutex_lock+0x15d/0x10c0 kernel/locking/mutex.c:746
Code: c0 80 f6 73 9a 48 c1 e8 03 42 0f b6 04 38 84 c0 0f 85 07 0e 00 00 83 3d 40 ba 41 0e 00 75 21 49 8d 7e 60 48 89 f8 48 c1 e8 03 <42> 80 3c 38 00 74 05 e8 17 52 fb f5 4d 39 76 60 0f 85 81 0d 00 00
RSP: 0018:ffffc90004206f80 EFLAGS: 00010202
RAX: 0000000000000019 RBX: ffffc90004207040 RCX: ffffffff9a73f603
RDX: ffff888035f65a00 RSI: ffffffff8e4fde18 RDI: 00000000000000c8
RBP: ffffc90004207118 R08: ffffc90004207087 R09: 0000000000000000
R10: ffffc90004207060 R11: fffff52000840e11 R12: 0000000000000000
R13: ffffc90004207048 R14: 0000000000000068 R15: dffffc0000000000
FS:  0000555594939380(0000) GS:ffff888125093000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f79554c50f0 CR3: 000000007cfd2000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 dvb_usbv2_generic_write+0x26/0x50 drivers/media/usb/dvb-usb-v2/dvb_usb_urb.c:77
 mxl111sf_ctrl_msg+0x172/0x2e0 drivers/media/usb/dvb-usb-v2/mxl111sf.c:73
 mxl111sf_write_reg+0xda/0x1f0 drivers/media/usb/dvb-usb-v2/mxl111sf.c:123
 mxl111sf_i2c_start drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c:130 [inline]
 mxl111sf_i2c_sw_xfer_msg drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c:-1 [inline]
 mxl111sf_i2c_xfer+0x923/0x8aa0 drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c:813
 __i2c_transfer+0x859/0x2250 drivers/i2c/i2c-core-base.c:-1
 i2c_transfer+0x2c2/0x430 drivers/i2c/i2c-core-base.c:2315
 i2c_transfer_buffer_flags+0x182/0x260 drivers/i2c/i2c-core-base.c:2343
 i2c_master_recv include/linux/i2c.h:79 [inline]
 i2cdev_read+0x10a/0x220 drivers/i2c/i2c-dev.c:155
 vfs_read+0x21f/0xb90 fs/read_write.c:568
 ksys_read+0x19d/0x2d0 fs/read_write.c:713
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f795544e4e9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 c1 17 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffc002847a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 0000200000000000 RCX: 00007f795544e4e9
RDX: 0000000000000063 RSI: 0000000000000000 RDI: 0000000000000004
RBP: 00000000000f4240 R08: 00232d6332692f76 R09: 00000000000000a0
R10: 000000000000000f R11: 0000000000000246 R12: 0000000000000001
R13: 00007ffc002849c8 R14: 00007ffc002847d0 R15: 00007ffc002847c0
 </TASK>

The current implementation of dvb-usb-v2 initializes i2c device in 
dvb_usbv2_probe() while making it immediately available for data transfers. 
This creates a window where userspace can trigger dvb_usbv2_generic_write 
operations before device initialization completes, potentially leading to 
NULL pointer dereference and kernel panic.


      Thread 1 (probe device)             Thread 2 (receive i2c data)
    ...
    dvb_usbv2_probe()
      ...
      d->priv = kzalloc(
          d->props->size_of_priv, 
          GFP_KERNEL);
      ...
      dvb_usbv2_init()
      ...
        // can read data from i2c 
        dvb_usbv2_i2c_init()
      ...
                                        ...
                                        i2cdev_read()
                                        ...
                                          // d->priv data is invalid. UB
                                          mxl111sf_i2c_xfer()
                                            ...
                                            mxl111sf_ctrl_msg()
                                              ...
                                              // null ptr deref
                                              dvb_usbv2_generic_write()
                                        ...
      ...
      // d->priv data is valid
      dvb_usbv2_adapter_init()
      ...

Acquire i2c mutex in probe function to prevent data access before device 
completes initialization, thus avoiding invalid memory access.

Reported-by: syzbot+f9f5333782a854509322 at syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=f9f5333782a854509322
Fixes: dd0f5e0b7554 ("[media] dvb_usb_v2: get rid of deferred probe")
Cc: stable at vger.kernel.org
Signed-off-by: Nalivayko Sergey <Sergey.Nalivayko at kaspersky.com>
---
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
index f1c79f351ec8..aa414735fe7d 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -917,15 +917,16 @@ int dvb_usbv2_probe(struct usb_interface *intf,
 	d->udev = udev;
 	d->props = driver_info->props;
 
+	mutex_init(&d->usb_mutex);
+	mutex_init(&d->i2c_mutex);
+	mutex_lock(&d->i2c_mutex);
+
 	if (intf->cur_altsetting->desc.bInterfaceNumber !=
 			d->props->bInterfaceNumber) {
 		ret = -ENODEV;
 		goto err_kfree_d;
 	}
 
-	mutex_init(&d->usb_mutex);
-	mutex_init(&d->i2c_mutex);
-
 	if (d->props->size_of_priv) {
 		d->priv = kzalloc(d->props->size_of_priv, GFP_KERNEL);
 		if (!d->priv) {
@@ -987,6 +988,7 @@ int dvb_usbv2_probe(struct usb_interface *intf,
 			KBUILD_MODNAME, d->name);
 exit:
 	usb_set_intfdata(intf, d);
+	mutex_unlock(&d->i2c_mutex);
 
 	return 0;
 err_free_all:
@@ -996,6 +998,7 @@ int dvb_usbv2_probe(struct usb_interface *intf,
 err_kfree_priv:
 	kfree(d->priv);
 err_kfree_d:
+	mutex_unlock(&d->i2c_mutex);
 	kfree(d);
 err:
 	dev_dbg(&udev->dev, "%s: failed=%d\n", __func__, ret);
-- 
2.30.2




More information about the lvc-project mailing list