WSL2-Linux-Kernel/drivers
Dan Williams 9c23fc327d driver core: Fix uevent_show() vs driver detach race
commit 15fffc6a5624b13b428bb1c6e9088e32a55eb82c upstream.

uevent_show() wants to de-reference dev->driver->name. There is no clean
way for a device attribute to de-reference dev->driver unless that
attribute is defined via (struct device_driver).dev_groups. Instead, the
anti-pattern of taking the device_lock() in the attribute handler risks
deadlocks with code paths that remove device attributes while holding
the lock.

This deadlock is typically invisible to lockdep given the device_lock()
is marked lockdep_set_novalidate_class(), but some subsystems allocate a
local lockdep key for @dev->mutex to reveal reports of the form:

 ======================================================
 WARNING: possible circular locking dependency detected
 6.10.0-rc7+ #275 Tainted: G           OE    N
 ------------------------------------------------------
 modprobe/2374 is trying to acquire lock:
 ffff8c2270070de0 (kn->active#6){++++}-{0:0}, at: __kernfs_remove+0xde/0x220

 but task is already holding lock:
 ffff8c22016e88f8 (&cxl_root_key){+.+.}-{3:3}, at: device_release_driver_internal+0x39/0x210

 which lock already depends on the new lock.

 the existing dependency chain (in reverse order) is:

 -> #1 (&cxl_root_key){+.+.}-{3:3}:
        __mutex_lock+0x99/0xc30
        uevent_show+0xac/0x130
        dev_attr_show+0x18/0x40
        sysfs_kf_seq_show+0xac/0xf0
        seq_read_iter+0x110/0x450
        vfs_read+0x25b/0x340
        ksys_read+0x67/0xf0
        do_syscall_64+0x75/0x190
        entry_SYSCALL_64_after_hwframe+0x76/0x7e

 -> #0 (kn->active#6){++++}-{0:0}:
        __lock_acquire+0x121a/0x1fa0
        lock_acquire+0xd6/0x2e0
        kernfs_drain+0x1e9/0x200
        __kernfs_remove+0xde/0x220
        kernfs_remove_by_name_ns+0x5e/0xa0
        device_del+0x168/0x410
        device_unregister+0x13/0x60
        devres_release_all+0xb8/0x110
        device_unbind_cleanup+0xe/0x70
        device_release_driver_internal+0x1c7/0x210
        driver_detach+0x47/0x90
        bus_remove_driver+0x6c/0xf0
        cxl_acpi_exit+0xc/0x11 [cxl_acpi]
        __do_sys_delete_module.isra.0+0x181/0x260
        do_syscall_64+0x75/0x190
        entry_SYSCALL_64_after_hwframe+0x76/0x7e

The observation though is that driver objects are typically much longer
lived than device objects. It is reasonable to perform lockless
de-reference of a @driver pointer even if it is racing detach from a
device. Given the infrequency of driver unregistration, use
synchronize_rcu() in module_remove_driver() to close any potential
races.  It is potentially overkill to suffer synchronize_rcu() just to
handle the rare module removal racing uevent_show() event.

Thanks to Tetsuo Handa for the debug analysis of the syzbot report [1].

Fixes: c0a40097f0bc ("drivers: core: synchronize really_probe() and dev_uevent()")
Reported-by: syzbot+4762dd74e32532cda5ff@syzkaller.appspotmail.com
Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Closes: http://lore.kernel.org/5aa5558f-90a4-4864-b1b1-5d6784c5607d@I-love.SAKURA.ne.jp [1]
Link: http://lore.kernel.org/669073b8ea479_5fffa294c1@dwillia2-xfh.jf.intel.com.notmuch
Cc: stable@vger.kernel.org
Cc: Ashish Sangwan <a.sangwan@samsung.com>
Cc: Namjae Jeon <namjae.jeon@samsung.com>
Cc: Dirk Behme <dirk.behme@de.bosch.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Link: https://lore.kernel.org/r/172081332794.577428.9738802016494057132.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-08-19 05:45:45 +02:00
..
accessibility
acpi ACPI: SBS: manage alarm sysfs attribute through psy core 2024-08-19 05:45:37 +02:00
amba
android binder: fix hang of unregistered readers 2024-08-19 05:45:16 +02:00
ata ata: libata-scsi: Honor the D_SENSE bit for CK_COND=1 and no error 2024-08-19 05:45:12 +02:00
atm
auxdisplay
base driver core: Fix uevent_show() vs driver detach race 2024-08-19 05:45:45 +02:00
bcma
block rbd: don't assume RBD_LOCK_STATE_LOCKED for exclusive mappings 2024-08-19 05:45:22 +02:00
bluetooth Bluetooth: btusb: Add Realtek RTL8852BE support ID 0x13d3:0x3591 2024-08-19 05:45:22 +02:00
bus
cdrom
char hwrng: amd - Convert PCIBIOS_* return codes to errnos 2024-08-19 05:45:15 +02:00
clk clk: davinci: da8xx-cfgchip: Initialize clk_init_data before use 2024-08-19 05:45:16 +02:00
clocksource clocksource/drivers/sh_cmt: Address race condition for clock events 2024-08-19 05:45:37 +02:00
comedi
connector
counter
cpufreq
cpuidle
crypto crypto: hisilicon/sec - Fix memory leak for sec resource release 2024-07-05 09:14:24 +02:00
cxl
dax
dca
devfreq
dio
dma dmaengine: ti: k3-udma: Fix BCHAN count with UHC and HC channels 2024-08-19 05:45:23 +02:00
dma-buf dma-buf/sw-sync: don't enable IRQ from sync_print_obj() 2024-06-16 13:39:49 +02:00
edac EDAC, i10nm: make skx_common.o a separate module 2024-08-19 05:44:49 +02:00
eisa
extcon
firewire
firmware firmware: turris-mox-rwtm: Initialize completion before mailbox 2024-08-19 05:44:55 +02:00
fpga
fsi
gnss
gpio gpiolib: of: add polarity quirk for TSC2005 2024-07-18 13:07:32 +02:00
gpu drm/client: fix null pointer dereference in drm_client_modeset_probe 2024-08-19 05:45:43 +02:00
greybus greybus: Fix use-after-free bug in gb_interface_release due to race condition. 2024-07-05 09:14:23 +02:00
hid HID: wacom: Modify pen IDs 2024-08-19 05:45:33 +02:00
hsi
hv
hwmon hwmon: (max6697) Fix swapped temp{1,8} critical alarms 2024-08-19 05:44:51 +02:00
hwspinlock
hwtracing coresight: Fix ref leak when of_coresight_parse_endpoint() fails 2024-08-19 05:45:04 +02:00
i2c i2c: smbus: Send alert notifications to all devices if source not found 2024-08-19 05:45:42 +02:00
i3c i3c: master: svc: fix invalidate IBI type and miss call client IBI handler 2024-06-16 13:40:00 +02:00
idle
iio iio: chemical: bme680: Fix sensor data read operation 2024-07-05 09:14:46 +02:00
infiniband RDMA/iwcm: Fix a use-after-free related to destroying CM IDs 2024-08-19 05:45:20 +02:00
input Input: elan_i2c - do not leave interrupt disabled on suspend failure 2024-08-19 05:45:05 +02:00
interconnect
iommu iommu: sprd: Avoid NULL deref in sprd_iommu_hw_en 2024-08-19 05:45:26 +02:00
ipack
irqchip irqchip/meson-gpio: Convert meson_gpio_irq_controller::lock to 'raw_spinlock_t' 2024-08-19 05:45:45 +02:00
isdn mISDN: Fix a use after free in hfcmulti_tx() 2024-08-19 05:45:25 +02:00
leds leds: triggers: Flush pending brightness before activating trigger 2024-08-19 05:45:29 +02:00
macintosh macintosh/therm_windtunnel: fix module unload. 2024-08-19 05:45:06 +02:00
mailbox
mcb
md md/raid5: avoid BUG_ON() while continue reshape after reassembling 2024-08-19 05:45:36 +02:00
media media: uvcvideo: Fix the bandwdith quirk on USB 3.x 2024-08-19 05:45:38 +02:00
memory memory: fsl_ifc: Make FSL_IFC config visible and selectable 2024-08-19 05:44:52 +02:00
memstick
message
mfd mfd: omap-usb-tll: Use struct_size to allocate tll 2024-08-19 05:45:03 +02:00
misc mei: demote client disconnect warning on suspend to debug 2024-07-27 10:46:10 +02:00
mmc mmc: sdhci: Do not lock spinlock around mmc_gpio_get_ro() 2024-07-05 09:14:45 +02:00
most
mtd ubi: eba: properly rollback inside self_check_eba 2024-08-19 05:45:16 +02:00
mux
net net: fec: Stop PPS on driver remove 2024-08-19 05:45:36 +02:00
nfc nfc/nci: Add the inconsistency check between the input data length and count 2024-07-18 13:07:36 +02:00
ntb
nubus
nvdimm
nvme nvme-pci: add missing condition check for existence of mapped data 2024-08-19 05:45:27 +02:00
nvmem nvmem: core: only change name to fram for current attribute 2024-07-18 13:07:42 +02:00
of cma: factor out minimum alignment requirement 2024-07-05 09:14:13 +02:00
opp
parisc
parport dev/parport: fix the array out-of-bounds risk 2024-08-19 05:45:16 +02:00
pci PCI: rockchip: Use GPIOD_OUT_LOW flag while requesting ep_gpio 2024-08-19 05:45:15 +02:00
pcmcia
perf
phy phy: cadence-torrent: Check return value on register read 2024-08-19 05:45:23 +02:00
pinctrl pinctrl: freescale: mxs: Fix refcount of child 2024-08-19 05:45:09 +02:00
platform platform/chrome: cros_ec_proto: Lock device when updating MKBP version 2024-08-19 05:45:33 +02:00
pnp
power power: supply: bq24190_charger: replace deprecated strncpy with strscpy 2024-08-19 05:45:33 +02:00
powercap
pps
ps3
ptp ptp: fix integer overflow in max_vclocks_store 2024-07-05 09:14:31 +02:00
pwm pwm: stm32: Always do lazy disabling 2024-08-19 05:44:51 +02:00
rapidio
ras
regulator regulator: bd71815: fix ramp values 2024-07-05 09:14:33 +02:00
remoteproc remoteproc: imx_rproc: Fix refcount mistake in imx_rproc_addr_init 2024-08-19 05:45:30 +02:00
reset
rpmsg
rtc rtc: isl1208: Fix return value of nvmem callbacks 2024-08-19 05:45:20 +02:00
s390 s390/sclp: Prevent release of buffer in I/O 2024-08-19 05:45:39 +02:00
sbus
scsi scsi: ufs: core: Fix hba->last_dme_cmd_tstamp timestamp updating logic 2024-08-19 05:45:44 +02:00
sh
siox
slimbus
soc drivers: soc: xilinx: check return status of get_api_version() 2024-08-19 05:45:29 +02:00
soundwire
spi spi: spi-fsl-lpspi: Fix scldiv calculation 2024-08-19 05:45:42 +02:00
spmi spmi: hisi-spmi-controller: Do not override device identifier 2024-07-05 09:14:20 +02:00
ssb
staging
target
tc
tee
thermal thermal/drivers/qcom/lmh: Check for SCM availability at probe 2024-06-16 13:39:55 +02:00
thunderbolt
tty serial: 8250_omap: Fix Errata i2310 with RX FIFO level check 2024-07-05 09:14:52 +02:00
uio
usb usb: gadget: u_serial: Set start_delayed during suspend 2024-08-19 05:45:44 +02:00
vdpa vduse: Temporarily fail if control queue feature requested 2024-07-05 09:14:42 +02:00
vfio
vhost vhost-vdpa: switch to use vmf_insert_pfn() in the fault handler 2024-08-19 05:45:44 +02:00
video fbdev: savage: Handle err return when savagefb_check_var failed 2024-06-16 13:39:57 +02:00
virt
virtio virtio: delete vq in vp_find_vqs_msix() when request_irq() fails 2024-06-16 13:39:47 +02:00
visorbus
vlynq
vme
w1
watchdog watchdog: rti_wdt: Set min_hw_heartbeat_ms to accommodate a safety margin 2024-06-16 13:39:59 +02:00
xen
zorro
Kconfig
Makefile