kernel_samsung_a53x/drivers/base
Dirk Behme 32ba65d9a4 drivers: core: synchronize really_probe() and dev_uevent()
commit c0a40097f0bc81deafc15f9195d1fb54595cd6d0 upstream.

Synchronize the dev->driver usage in really_probe() and dev_uevent().
These can run in different threads, what can result in the following
race condition for dev->driver uninitialization:

Thread #1:
==========

really_probe() {
...
probe_failed:
...
device_unbind_cleanup(dev) {
    ...
    dev->driver = NULL;   // <= Failed probe sets dev->driver to NULL
    ...
    }
...
}

Thread #2:
==========

dev_uevent() {
...
if (dev->driver)
      // If dev->driver is NULLed from really_probe() from here on,
      // after above check, the system crashes
      add_uevent_var(env, "DRIVER=%s", dev->driver->name);
...
}

really_probe() holds the lock, already. So nothing needs to be done
there. dev_uevent() is called with lock held, often, too. But not
always. What implies that we can't add any locking in dev_uevent()
itself. So fix this race by adding the lock to the non-protected
path. This is the path where above race is observed:

 dev_uevent+0x235/0x380
 uevent_show+0x10c/0x1f0  <= Add lock here
 dev_attr_show+0x3a/0xa0
 sysfs_kf_seq_show+0x17c/0x250
 kernfs_seq_show+0x7c/0x90
 seq_read_iter+0x2d7/0x940
 kernfs_fop_read_iter+0xc6/0x310
 vfs_read+0x5bc/0x6b0
 ksys_read+0xeb/0x1b0
 __x64_sys_read+0x42/0x50
 x64_sys_call+0x27ad/0x2d30
 do_syscall_64+0xcd/0x1d0
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Similar cases are reported by syzkaller in

https://syzkaller.appspot.com/bug?extid=ffa8143439596313a85a

But these are regarding the *initialization* of dev->driver

dev->driver = drv;

As this switches dev->driver to non-NULL these reports can be considered
to be false-positives (which should be "fixed" by this commit, as well,
though).

The same issue was reported and tried to be fixed back in 2015 in

https://lore.kernel.org/lkml/1421259054-2574-1-git-send-email-a.sangwan@samsung.com/

already.

Fixes: 239378f16aa1 ("Driver core: add uevent vars for devices of a class")
Cc: stable <stable@kernel.org>
Cc: syzbot+ffa8143439596313a85a@syzkaller.appspotmail.com
Cc: Ashish Sangwan <a.sangwan@samsung.com>
Cc: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Link: https://lore.kernel.org/r/20240513050634.3964461-1-dirk.behme@de.bosch.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-19 14:19:04 +01:00
..
firmware_loader Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
power PM: sleep: wakeirq: fix wake irq warning in system suspend 2024-11-19 09:22:17 +01:00
regmap regmap: Add missing map->bus check 2024-11-19 08:45:00 +01:00
test Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
arch_topology.c arch_topology: Rename freq_scale as arch_freq_scale 2024-11-17 17:45:22 +01:00
attribute_container.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
base.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bus.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cacheinfo.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
class.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
component.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
container.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
core.c drivers: core: synchronize really_probe() and dev_uevent() 2024-11-19 14:19:04 +01:00
cpu.c x86/rfds: Mitigate Register File Data Sampling (RFDS) 2024-11-19 09:22:40 +01:00
dd.c driver core: Release all resources during unbind before updating device links 2024-11-18 12:11:17 +01:00
devcoredump.c devcoredump: Send uevent once devcd is ready 2024-11-18 12:11:48 +01:00
devres.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
devtmpfs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
driver.c driver: platform: Add helper for safer setting of driver_override 2024-11-18 10:58:45 +01:00
firmware.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hypervisor.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
init.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
isa.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
map.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
memory.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
module.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
node.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
platform-mock.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
platform-msi.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
platform.c driver: platform: Add helper for safer setting of driver_override 2024-11-18 10:58:45 +01:00
property.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
soc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
swnode.c software node: Let args be NULL in software_node_get_reference_args 2024-11-18 12:12:49 +01:00
syscore.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
topology.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
transport_class.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00