Skip to content

Commit c89b250

Browse files
committed
platform/x86: wmi: Fix opening of char device
jira LE-1907 cve CVE-2023-52864 Rebuild_History Non-Buildable kernel-5.14.0-427.31.1.el9_4 commit-author Armin Wolf <[email protected]> commit eba9ac7 Since commit fa1f68d ("drivers: misc: pass miscdevice pointer via file private data"), the miscdevice stores a pointer to itself inside filp->private_data, which means that private_data will not be NULL when wmi_char_open() is called. This might cause memory corruption should wmi_char_open() be unable to find its driver, something which can happen when the associated WMI device is deleted in wmi_free_devices(). Fix the problem by using the miscdevice pointer to retrieve the WMI device data associated with a char device using container_of(). This also avoids wmi_char_open() picking a wrong WMI device bound to a driver with the same name as the original driver. Fixes: 44b6b76 ("platform/x86: wmi: create userspace interface for drivers") Signed-off-by: Armin Wolf <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> (cherry picked from commit eba9ac7) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 9108eb0 commit c89b250

File tree

1 file changed

+6
-14
lines changed
  • drivers/platform/x86

1 file changed

+6
-14
lines changed

drivers/platform/x86/wmi.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -803,21 +803,13 @@ static int wmi_dev_match(struct device *dev, struct device_driver *driver)
803803
}
804804
static int wmi_char_open(struct inode *inode, struct file *filp)
805805
{
806-
const char *driver_name = filp->f_path.dentry->d_iname;
807-
struct wmi_block *wblock;
808-
struct wmi_block *next;
809-
810-
list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
811-
if (!wblock->dev.dev.driver)
812-
continue;
813-
if (strcmp(driver_name, wblock->dev.dev.driver->name) == 0) {
814-
filp->private_data = wblock;
815-
break;
816-
}
817-
}
806+
/*
807+
* The miscdevice already stores a pointer to itself
808+
* inside filp->private_data
809+
*/
810+
struct wmi_block *wblock = container_of(filp->private_data, struct wmi_block, char_dev);
818811

819-
if (!filp->private_data)
820-
return -ENODEV;
812+
filp->private_data = wblock;
821813

822814
return nonseekable_open(inode, filp);
823815
}

0 commit comments

Comments
 (0)