]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
driver core: fix potential NULL pointer dereference in dev_uevent()
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 11 Mar 2025 05:24:16 +0000 (22:24 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:51:03 +0000 (07:51 +0200)
commitabe56be73eb10a677d16066f65ff9d30251f5eee
tree6801d90800c6bf5f9c9a40d64accfab04cfda4b1
parenta55111066205090aec18e1e999155a5dd15f4394
driver core: fix potential NULL pointer dereference in dev_uevent()

commit 18daa52418e7e4629ed1703b64777294209d2622 upstream.

If userspace reads "uevent" device attribute at the same time as another
threads unbinds the device from its driver, change to dev->driver from a
valid pointer to NULL may result in crash. Fix this by using READ_ONCE()
when fetching the pointer, and take bus' drivers klist lock to make sure
driver instance will not disappear while we access it.

Use WRITE_ONCE() when setting the driver pointer to ensure there is no
tearing.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Link: https://lore.kernel.org/r/20250311052417.1846985-3-dmitry.torokhov@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/base.h
drivers/base/bus.c
drivers/base/core.c