All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	driver-core@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] driver core: fix race between bus_remove_driver() and dev_driver_uevent()
Date: Wed, 14 Oct 2026 07:31:19 +0200	[thread overview]
Message-ID: <2026101444-unnoticed-caliber-21d5@gregkh> (raw)
In-Reply-To: <as71DkwHeLGNDsPv@google.com>

On Tue, Oct 13, 2026 at 08:24:20PM -0700, Dmitry Torokhov wrote:
> When a device driver is being removed, bus_remove_driver() removes the
> driver from the bus klist before detaching it from bound devices. If
> dev_driver_uevent() runs concurrently on another CPU, it may acquire the
> bus klist lock after the driver has been removed from the list, read the
> still-valid driver pointer from the device, and access the driver's name
> while bus_remove_driver() proceeds to free the driver structure.
> 
> To close this race window, acquire and immediately release the bus
> drivers klist lock after all devices have been detached. This ensures
> that any in-flight uevent generation that observed the driver pointer
> before device detachment completed finishes reading the driver name
> before the driver structure is destroyed.
> 
> Fixes: 18daa52418e7 ("driver core: fix potential NULL pointer dereference in dev_uevent()")
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> 
> Extremely unlikely to hit so I would not worry about backporting to
> stable.
> 
>  drivers/base/bus.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index d17bd91490ee..8b3aaf451e4f 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -830,6 +830,15 @@ void bus_remove_driver(struct device_driver *drv)
>  	driver_remove_file(drv, &driver_attr_uevent);
>  	klist_remove(&drv->p->knode_bus);
>  	driver_detach(drv);
> +
> +	/*
> +	 * Ensure that any concurrent dev_driver_uevent() that observed
> +	 * dev->driver before driver_detach() cleared it, finishes
> +	 * accessing drv->name.
> +	 */
> +	scoped_guard(spinlock, &sp->klist_drivers.k_lock) {
> +	}

Shouldn't the compiler just no-op this away into nothing?

thanks,

greg k-h

  reply	other threads:[~2026-10-14  5:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14  3:24 [PATCH] driver core: fix race between bus_remove_driver() and dev_driver_uevent() Dmitry Torokhov
2026-10-14  5:31 ` Greg Kroah-Hartman [this message]
2026-10-14  6:11   ` Dmitry Torokhov
2026-10-14 12:16     ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2026101444-unnoticed-caliber-21d5@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=dakr@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=driver-core@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.