Skip to content

Commit 2c55070

Browse files
Danilo Krummrichgregkh
authored andcommitted
platform/wmi: use generic driver_override infrastructure
[ Upstream commit 8a700b1 ] When a driver is probed through __driver_attach(), the bus' match() callback is called without the device lock held, thus accessing the driver_override field without a lock, which can cause a UAF. Fix this by using the driver-core driver_override infrastructure taking care of proper locking internally. Note that calling match() from __driver_attach() without the device lock held is intentional. [1] Link: https://lore.kernel.org/driver-core/DGRGTIRHA62X.3RY09D9SOK77P@kernel.org/ [1] Reported-by: Gui-Dong Han <hanguidong02@gmail.com> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220789 Fixes: 12046f8 ("platform/x86: wmi: Add driver_override support") Reviewed-by: Armin Wolf <W_Armin@gmx.de> Acked-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Link: https://patch.msgid.link/20260324005919.2408620-7-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 58a42be commit 2c55070

2 files changed

Lines changed: 5 additions & 35 deletions

File tree

drivers/platform/x86/wmi.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -702,39 +702,11 @@ static ssize_t expensive_show(struct device *dev,
702702
}
703703
static DEVICE_ATTR_RO(expensive);
704704

705-
static ssize_t driver_override_show(struct device *dev, struct device_attribute *attr,
706-
char *buf)
707-
{
708-
struct wmi_device *wdev = to_wmi_device(dev);
709-
ssize_t ret;
710-
711-
device_lock(dev);
712-
ret = sysfs_emit(buf, "%s\n", wdev->driver_override);
713-
device_unlock(dev);
714-
715-
return ret;
716-
}
717-
718-
static ssize_t driver_override_store(struct device *dev, struct device_attribute *attr,
719-
const char *buf, size_t count)
720-
{
721-
struct wmi_device *wdev = to_wmi_device(dev);
722-
int ret;
723-
724-
ret = driver_set_override(dev, &wdev->driver_override, buf, count);
725-
if (ret < 0)
726-
return ret;
727-
728-
return count;
729-
}
730-
static DEVICE_ATTR_RW(driver_override);
731-
732705
static struct attribute *wmi_attrs[] = {
733706
&dev_attr_modalias.attr,
734707
&dev_attr_guid.attr,
735708
&dev_attr_instance_count.attr,
736709
&dev_attr_expensive.attr,
737-
&dev_attr_driver_override.attr,
738710
NULL
739711
};
740712
ATTRIBUTE_GROUPS(wmi);
@@ -803,7 +775,6 @@ static void wmi_dev_release(struct device *dev)
803775
{
804776
struct wmi_block *wblock = dev_to_wblock(dev);
805777

806-
kfree(wblock->dev.driver_override);
807778
kfree(wblock);
808779
}
809780

@@ -812,10 +783,12 @@ static int wmi_dev_match(struct device *dev, const struct device_driver *driver)
812783
const struct wmi_driver *wmi_driver = to_wmi_driver(driver);
813784
struct wmi_block *wblock = dev_to_wblock(dev);
814785
const struct wmi_device_id *id = wmi_driver->id_table;
786+
int ret;
815787

816788
/* When driver_override is set, only bind to the matching driver */
817-
if (wblock->dev.driver_override)
818-
return !strcmp(wblock->dev.driver_override, driver->name);
789+
ret = device_match_driver_override(dev, driver);
790+
if (ret >= 0)
791+
return ret;
819792

820793
if (id == NULL)
821794
return 0;
@@ -936,6 +909,7 @@ static struct class wmi_bus_class = {
936909
static const struct bus_type wmi_bus_type = {
937910
.name = "wmi",
938911
.dev_groups = wmi_groups,
912+
.driver_override = true,
939913
.match = wmi_dev_match,
940914
.uevent = wmi_dev_uevent,
941915
.probe = wmi_dev_probe,

include/linux/wmi.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@
1616
* struct wmi_device - WMI device structure
1717
* @dev: Device associated with this WMI device
1818
* @setable: True for devices implementing the Set Control Method
19-
* @driver_override: Driver name to force a match; do not set directly,
20-
* because core frees it; use driver_set_override() to
21-
* set or clear it.
2219
*
2320
* This represents WMI devices discovered by the WMI driver core.
2421
*/
2522
struct wmi_device {
2623
struct device dev;
2724
bool setable;
28-
const char *driver_override;
2925
};
3026

3127
/**

0 commit comments

Comments
 (0)