Skip to contentSkip to conversation

platform/x86: wmi: fix potential null pointer dereference

PATCH In review Mattias Jacobsson 3 participants 3 messages Jan 30, 2019 – Feb 21, 2019 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 platform/x86: wmi: fix potential null pointer dereference

In the function wmi_dev_match() the variable id is dereferenced without first performing a NULL check. The variable can for example be NULL if a WMI driver is registered without specifying the id_table field in struct wmi_driver.

Add a NULL check and return that the driver can't handle the device if the variable is NULL.

Fixes 844af950da94 ("platform/x86: wmi: Turn WMI into a bus driver")
---
 drivers/platform/x86/wmi.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/platform/x86/wmi.c +3 -0
index bea35be68706..b0f3d8ecd898 100644
@@ -768,6 +768,9 @@ static int wmi_dev_match(struct device *dev, struct device_driver *driver)
 	struct wmi_block *wblock = dev_to_wblock(dev);
 	const struct wmi_device_id *id = wmi_driver->id_table;
 
+	if (id == NULL)
+		return 0;
+
 	while (id->guid_string) {
 		uuid_le driver_guid;
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 9 lines · Mattias Jacobsson

In the function wmi_dev_match() the variable id is dereferenced without first performing a NULL check. The variable can for example be NULL if a WMI driver is registered without specifying the id_table field in struct wmi_driver.

Add a NULL check and return that the driver can't handle the device if the variable is NULL.

Good for me, thanks!

Quoted 23 lines
Fixes 844af950da94 ("platform/x86: wmi: Turn WMI into a bus driver")
---
 drivers/platform/x86/wmi.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/platform/x86/wmi.c +3 -1
index bea35be68706..b0f3d8ecd898 100644
@@ -768,6 +768,9 @@ static int wmi_dev_match(struct device *dev, struct device_driver *driver)
        struct wmi_block *wblock = dev_to_wblock(dev);
        const struct wmi_device_id *id = wmi_driver->id_table;
 
+       if (id == NULL)
+               return 0;
+
        while (id->guid_string) {
                uuid_le driver_guid;
 
--

2.20.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Mattias Jacobsson

In the function wmi_dev_match() the variable id is dereferenced without first performing a NULL check. The variable can for example be NULL if a WMI driver is registered without specifying the id_table field in struct wmi_driver.

Quoted 5 lines
Quoted 3 lines

Add a NULL check and return that the driver can't handle the device if the variable is NULL.

Good for me, thanks!

Queued for testing, thanks Mattias.

Signature · 2 lines
Darren Hart
VMware Open Source Technology Center