• D
    media: usb: siano: Fix warning due to null work_func_t function pointer · 98c8030b
    Duoming Zhou 提交于
    mainline inclusion
    from mainline-v6.5-rc1
    commit 6f489a966fbeb0da63d45c2c66a8957eab604bf6
    category: bugfix
    bugzilla: https://gitee.com/openeuler/kernel/issues/I7QTMZ
    CVE: CVE-2023-4132
    
    Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6f489a966fbeb0da63d45c2c66a8957eab604bf6
    
    --------------------------------
    
    The previous commit ebad8e73 ("media: usb: siano: Fix use after
    free bugs caused by do_submit_urb") adds cancel_work_sync() in
    smsusb_stop_streaming(). But smsusb_stop_streaming() may be called,
    even if the work_struct surb->wq has not been initialized. As a result,
    the warning will occur. One of the processes that could lead to warning
    is shown below:
    
    smsusb_probe()
      smsusb_init_device()
        if (!dev->in_ep || !dev->out_ep || align < 0) {
             smsusb_term_device(intf);
               smsusb_stop_streaming()
                 cancel_work_sync(&dev->surbs[i].wq);
                   __cancel_work_timer()
                     __flush_work()
                       if (WARN_ON(!work->func)) // work->func is null
    
    The log reported by syzbot is shown below:
    
    WARNING: CPU: 0 PID: 897 at kernel/workqueue.c:3066 __flush_work+0x798/0xa80 kernel/workqueue.c:3063
    Modules linked in:
    CPU: 0 PID: 897 Comm: kworker/0:2 Not tainted 6.2.0-rc1-syzkaller #0
    RIP: 0010:__flush_work+0x798/0xa80 kernel/workqueue.c:3066
    ...
    RSP: 0018:ffffc9000464ebf8 EFLAGS: 00010246
    RAX: 1ffff11002dbb420 RBX: 0000000000000021 RCX: 1ffffffff204fa4e
    RDX: dffffc0000000000 RSI: 0000000000000001 RDI: ffff888016dda0e8
    RBP: ffffc9000464ed98 R08: 0000000000000001 R09: ffffffff90253b2f
    R10: 0000000000000001 R11: 0000000000000000 R12: ffff888016dda0e8
    R13: ffff888016dda0e8 R14: ffff888016dda100 R15: 0000000000000001
    FS:  0000000000000000(0000) GS:ffff8880b9a00000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00007ffd4331efe8 CR3: 000000000b48e000 CR4: 00000000003506f0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
     <TASK>
     __cancel_work_timer+0x315/0x460 kernel/workqueue.c:3160
     smsusb_stop_streaming drivers/media/usb/siano/smsusb.c:182 [inline]
     smsusb_term_device+0xda/0x2d0 drivers/media/usb/siano/smsusb.c:344
     smsusb_init_device+0x400/0x9ce drivers/media/usb/siano/smsusb.c:419
     smsusb_probe+0xbbd/0xc55 drivers/media/usb/siano/smsusb.c:567
    ...
    
    This patch adds check before cancel_work_sync(). If surb->wq has not
    been initialized, the cancel_work_sync() will not be executed.
    
    Reported-by: syzbot+27b0b464864741b18b99@syzkaller.appspotmail.com
    Fixes: ebad8e73 ("media: usb: siano: Fix use after free bugs caused by do_submit_urb")
    Signed-off-by: NDuoming Zhou <duoming@zju.edu.cn>
    Signed-off-by: NHans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: NRuan Jinjie <ruanjinjie@huawei.com>
    (cherry picked from commit d6a3c21a)
    98c8030b
smsusb.c 19.3 KB