android_kernel_motorola_sm6375/drivers/usb
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Gui-Dong Han 85f6a6590d usb: mon: Fix atomicity violation in mon_bin_vma_fault
commit 2dd23cc4d0e6aa55cf9fb3b05f2f4165b01de81c upstream.

In mon_bin_vma_fault():
    offset = vmf->pgoff << PAGE_SHIFT;
    if (offset >= rp->b_size)
        return VM_FAULT_SIGBUS;
    chunk_idx = offset / CHUNK_SIZE;
    pageptr = rp->b_vec[chunk_idx].pg;
The code is executed without holding any lock.

In mon_bin_vma_close():
    spin_lock_irqsave(&rp->b_lock, flags);
    rp->mmap_active--;
    spin_unlock_irqrestore(&rp->b_lock, flags);

In mon_bin_ioctl():
    spin_lock_irqsave(&rp->b_lock, flags);
    if (rp->mmap_active) {
        ...
    } else {
        ...
        kfree(rp->b_vec);
        rp->b_vec  = vec;
        rp->b_size = size;
        ...
    }
    spin_unlock_irqrestore(&rp->b_lock, flags);

Concurrent execution of mon_bin_vma_fault() with mon_bin_vma_close() and
mon_bin_ioctl() could lead to atomicity violations. mon_bin_vma_fault()
accesses rp->b_size and rp->b_vec without locking, risking array
out-of-bounds access or use-after-free bugs due to possible modifications
in mon_bin_ioctl().

This possible bug is found by an experimental static analysis tool
developed by our team, BassCheck[1]. This tool analyzes the locking APIs
to extract function pairs that can be concurrently executed, and then
analyzes the instructions in the paired functions to identify possible
concurrency bugs including data races and atomicity violations. The above
possible bug is reported when our tool analyzes the source code of
Linux 6.2.

To address this issue, it is proposed to add a spin lock pair in
mon_bin_vma_fault() to ensure atomicity. With this patch applied, our tool
never reports the possible bug, with the kernel configuration allyesconfig
for x86_64. Due to the lack of associated hardware, we cannot test the
patch in runtime testing, and just verify it according to the code logic.

[1] https://sites.google.com/view/basscheck/

Fixes: 19e6317d24c2 ("usb: mon: Fix a deadlock in usbmon between ...")
Cc:  <[email protected]>
Signed-off-by: Gui-Dong Han <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2024-01-25 14:34:30 -08:00
..
atm
c67x00
cdns3 usb: cdns3: Fix issue with using incorrect PCI device function 2023-04-05 11:16:40 +02:00
chipidea usb: chipidea: wait controller resume finished for wakeup irq 2024-01-25 14:34:29 -08:00
class USB: usbtmc: Fix direction for 0-length ioctl control messages 2023-05-30 12:44:06 +01:00
common usb: common: usb-conn-gpio: Prevent bailing out if initial role is none 2023-08-16 18:19:23 +02:00
core usb: hub: Guard against accesses to uninitialized BOS descriptors 2023-10-25 11:53:20 +02:00
dwc2 USB: dwc2: write HCINT with INTMASK applied 2023-12-08 08:44:25 +01:00
dwc3 Revert "usb: dwc3: don't reset device side if dwc3 was configured as host-only" 2024-01-25 14:34:29 -08:00
early
gadget usb: gadget: f_hid: fix report descriptor allocation 2023-12-13 18:18:15 +01:00
host usb: fotg210-hcd: delete an incorrect bounds test 2024-01-08 11:29:47 +01:00
image
isp1760
misc USB: sisusbvga: Add endpoint checks 2023-05-30 12:44:10 +01:00
mon usb: mon: Fix atomicity violation in mon_bin_vma_fault 2024-01-25 14:34:30 -08:00
mtu3 usb: mtu3: fix kernel panic at qmu transfer done irq handler 2023-05-17 11:35:49 +02:00
musb usb: musb: Modify the "HWVers" register address 2023-10-25 11:53:19 +02:00
phy usb: phy: mxs: remove CONFIG_USB_OTG condition for mxs_phy_is_otg_host() 2024-01-25 14:34:29 -08:00
renesas_usbhs
roles
serial USB: serial: option: add Quectel RM500Q R13 firmware support 2024-01-08 11:29:47 +01:00
storage usb: storage: set 1.50 as the lower bcdDevice for older "Super Top" compatibility 2023-11-08 11:23:42 +01:00
typec usb: typec: class: fix typec_altmode_put_partner to put plugs 2024-01-25 14:34:30 -08:00
usbip USB: usbip: fix stub_dev hub disconnect 2023-11-20 10:30:14 +01:00
Kconfig
Makefile
usb-skeleton.c