lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6691c0f8da1dd_8e85329468@dwillia2-xfh.jf.intel.com.notmuch>
Date: Fri, 12 Jul 2024 16:49:12 -0700
From: Dan Williams <dan.j.williams@...el.com>
To: Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>, Dan Williams
	<dan.j.williams@...el.com>, <gregkh@...uxfoundation.org>
CC: <syzbot+4762dd74e32532cda5ff@...kaller.appspotmail.com>,
	<stable@...r.kernel.org>, Ashish Sangwan <a.sangwan@...sung.com>, Namjae Jeon
	<namjae.jeon@...sung.com>, Dirk Behme <dirk.behme@...bosch.com>, "Rafael J.
 Wysocki" <rafael@...nel.org>, <linux-kernel@...r.kernel.org>,
	<linux-cxl@...r.kernel.org>
Subject: Re: [PATCH] driver core: Fix uevent_show() vs driver detach race

Tetsuo Handa wrote:
> On 2024/07/13 4:42, Dan Williams wrote:
> > @@ -2668,8 +2670,12 @@ static int dev_uevent(const struct kobject *kobj, struct kobj_uevent_env *env)
> >  	if (dev->type && dev->type->name)
> >  		add_uevent_var(env, "DEVTYPE=%s", dev->type->name);
> >  
> > -	if (dev->driver)
> > -		add_uevent_var(env, "DRIVER=%s", dev->driver->name);
> > +	/* Synchronize with module_remove_driver() */
> > +	rcu_read_lock();
> > +	driver = READ_ONCE(dev->driver);
> > +	if (driver)
> > +		add_uevent_var(env, "DRIVER=%s", driver->name);
> > +	rcu_read_unlock();
> >  
> 
> Given that read of dev->driver is protected using RCU,
> 
> > @@ -97,6 +98,9 @@ void module_remove_driver(struct device_driver *drv)
> >  	if (!drv)
> >  		return;
> >  
> 
> where is
> 
> 	dev->driver = NULL;
> 
> performed prior to

It happens in __device_release_driver() and several places in the driver
probe failure path. However, the point of this patch is that the
"dev->driver = NULL" event does not really matter for this sysfs
attribute.

This attribute just wants to opportunistically report the driver name to
userspace, but that result is ephemeral. I.e. as soon as a dev_uevent()
adds a DRIVER environment variable that result could be immediately
invalidated before userspace has a chance to do anything with the
result.

Even with the current device_lock() solution userspace can not depend on
the driver still being attached when it goes to act on the DRIVER
environment variable.

> > +	/* Synchronize with dev_uevent() */
> > +	synchronize_rcu();
> > +
> 
> this synchronize_rcu(), in order to make sure that
> READ_ONCE(dev->driver) in dev_uevent() observes NULL?

No, this synchronize_rcu() is to make sure that if dev_uevent() wins the
race and observes that dev->driver is not NULL that it is still safe to
dereference that result because the 'struct device_driver' object is
still live.

A 'struct device_driver' instance is typically static data in a kernel
module that does not get freed until after driver_unregister(). Calls to
driver_unregister() typically only happen at module removal time. So
this synchronize_rcu() delays module removal until dev_uevent() finishes
reading driver->name.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ