kernel_samsung_a53x/drivers
Dan Williams 1ee9fd53e6 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-11-23 23:20:28 +01:00
..
accessibility
acpi ACPI: SBS: manage alarm sysfs attribute through psy core 2024-11-23 23:20:23 +01:00
amba
android binder: fix hang of unregistered readers 2024-11-23 23:20:14 +01:00
ata ata: libata-core: Fix double free on error 2024-11-19 14:19:34 +01:00
atm
auxdisplay
base driver core: Fix uevent_show() vs driver detach race 2024-11-23 23:20:28 +01:00
battery
bcma
block rbd: don't assume RBD_LOCK_STATE_LOCKED for exclusive mappings 2024-11-23 23:20:16 +01:00
bluetooth Bluetooth: btusb: Add Realtek RTL8852BE support ID 0x13d3:0x3591 2024-11-23 23:20:16 +01:00
bts
bus
cdrom
char hwrng: amd - Convert PCIBIOS_* return codes to errnos 2024-11-23 23:20:14 +01:00
clk clk: davinci: da8xx-cfgchip: Initialize clk_init_data before use 2024-11-23 23:20:14 +01:00
clocksource clocksource/drivers/sh_cmt: Address race condition for clock events 2024-11-23 23:20:23 +01:00
connector
counter counter: ti-eqep: enable clock at probe 2024-11-19 14:19:33 +01:00
cpufreq
cpuidle cpuidle: menu: Take negative "sleep length" values into account 2024-11-19 18:01:28 +01:00
crypto
dax
dca
devfreq
dio
dma
dma-buf dma-buf/sync_file: Speed up ioctl by omitting debug names 2024-11-19 17:53:23 +01:00
edac EDAC, i10nm: make skx_common.o a separate module 2024-11-23 23:19:56 +01:00
eisa
extcon
fingerprint
firewire
firmware firmware: turris-mox-rwtm: Initialize completion before mailbox 2024-11-23 23:20:06 +01:00
fpga
fsi
gnss
gpio gpiolib: cdev: Disallow reconfiguration without direction (uAPI v1) 2024-11-19 14:19:33 +01:00
gpu drm/client: fix null pointer dereference in drm_client_modeset_probe 2024-11-23 23:20:27 +01:00
greybus
gud
hid HID: wacom: Modify pen IDs 2024-11-23 23:20:20 +01:00
hsi
hv
hwmon hwmon: (max6697) Fix swapped temp{1,8} critical alarms 2024-11-23 23:19:57 +01:00
hwspinlock
hwtracing coresight: Fix ref leak when of_coresight_parse_endpoint() fails 2024-11-23 23:20:10 +01:00
i2c i2c: smbus: Send alert notifications to all devices if source not found 2024-11-23 23:20:26 +01:00
i3c
ide
idle
ifconn
iio iio: chemical: bme680: Fix sensor data read operation 2024-11-19 14:19:33 +01:00
infiniband RDMA/iwcm: Fix a use-after-free related to destroying CM IDs 2024-11-23 23:20:15 +01:00
input Input: elan_i2c - do not leave interrupt disabled on suspend failure 2024-11-23 23:20:10 +01:00
interconnect
iommu iommu: pcie: Fix incorrect kmemleak_ignore() usage 2024-11-19 17:53:28 +01:00
ipack
irqchip irqchip/mbigen: Fix mbigen node address layout 2024-11-23 23:20:21 +01:00
isdn mISDN: Fix a use after free in hfcmulti_tx() 2024-11-23 23:20:17 +01:00
kperfmon
kq/mesh
leds leds: ss4200: Convert PCIBIOS_* return codes to errnos 2024-11-23 23:20:13 +01:00
lightnvm
macintosh macintosh/therm_windtunnel: fix module unload. 2024-11-23 23:20:11 +01:00
mailbox
mcb
md md/raid5: avoid BUG_ON() while continue reshape after reassembling 2024-11-23 23:20:23 +01:00
media media: uvcvideo: Fix the bandwdith quirk on USB 3.x 2024-11-23 23:20:24 +01:00
memory
memstick
message
mfd mfd: omap-usb-tll: Use struct_size to allocate tll 2024-11-23 23:20:09 +01:00
misc uid_sys_stats: Remove dependency on the profiling subsystem 2024-11-19 17:53:52 +01:00
mmc mmc: Disable crc check 2024-11-19 17:47:04 +01:00
most
mtd ubi: eba: properly rollback inside self_check_eba 2024-11-23 23:20:14 +01:00
muic
mux
net net: fec: Stop PPS on driver remove 2024-11-23 23:20:22 +01:00
nfc
ntb
nubus
nvdimm
nvme nvme-pci: add missing condition check for existence of mapped data 2024-11-23 23:20:18 +01:00
nvmem nvmem: meson-efuse: Fix return value of nvmem callbacks 2024-11-19 14:19:45 +01:00
of
opp
oprofile
parisc
parport dev/parport: fix the array out-of-bounds risk 2024-11-23 23:20:14 +01:00
pci PCI: rockchip: Use GPIOD_OUT_LOW flag while requesting ep_gpio 2024-11-23 23:20:14 +01:00
pcmcia
perf
phy
pinctrl pinctrl: freescale: mxs: Fix refcount of child 2024-11-23 23:20:11 +01:00
platform platform/chrome: cros_ec_proto: Lock device when updating MKBP version 2024-11-23 23:20:20 +01:00
pnp
power
powercap
pps
ps3
ptp
pwm pwm: stm32: Always do lazy disabling 2024-11-23 23:19:56 +01:00
rapidio
ras
regulator
remoteproc remoteproc: imx_rproc: Skip over memory region when node value is NULL 2024-11-23 23:20:20 +01:00
reset
rpmsg
rtc rtc: isl1208: Fix return value of nvmem callbacks 2024-11-23 23:20:15 +01:00
s390 s390/sclp: Prevent release of buffer in I/O 2024-11-23 23:20:24 +01:00
samsung
sbus
scsi scsi: ufs: core: Fix hba->last_dme_cmd_tstamp timestamp updating logic 2024-11-23 23:20:28 +01:00
sensorhub
sensors
sfi
sh
siox
slimbus
soc drivers: soc: xilinx: check return status of get_api_version() 2024-11-23 23:20:19 +01:00
soundwire
spi spi: spi-fsl-lpspi: Fix scldiv calculation 2024-11-23 23:20:27 +01:00
spmi
spu_verify
ssb
staging drivers: staging: Import Xiaomi's binder prio driver 2024-11-19 17:46:55 +01:00
sti
target target/file: allocate the bvec array as part of struct target_core_file_cmd 2024-11-19 17:42:15 +01:00
tc
tee
thermal
thunderbolt
tty serial: 8250_omap: Fix Errata i2310 with RX FIFO level check 2024-11-19 14:19:39 +01:00
uh
uio
usb usb: gadget: u_serial: Set start_delayed during suspend 2024-11-23 23:20:28 +01:00
vdpa
vfio
vhost
vibrator
video Optimized Console FrameBuffer for upto 70% increase in Performance 2024-11-19 17:30:21 +01:00
virt
virtio
vision
vision3
visorbus
vlynq
vme
w1
watchdog
xen
zorro
Kconfig Added KernelSU 2024-11-19 22:44:48 +01:00
Kconfig.variant1
kernelsu Added KernelSU 2024-11-19 22:44:48 +01:00
Makefile Added KernelSU 2024-11-19 22:44:48 +01:00
Makefile.variant1