platform/x86: dell-wmi-sysman: Various error-handling and robustness fixes
Subsystems (2)
v2 cover platform/x86: dell-wmi-sysman: Various error-handling and robustness fixes
Hi All,
There have been several bug-reports about crashes related to the dell-wmi-sysman module:
https://bugzilla.redhat.com/show_bug.cgi?id=1936171
https://bugzilla.kernel.org/show_bug.cgi?id=211895
https://bugs.archlinux.org/task/69702
Here is v2 of my series with a bunch of fixes for NULL pointer derefs, double-frees, etc. which fixes this.
New in v2:
-New patch: "platform/x86: dell-wmi-sysman: Fix crash caused by calling kset_unregister twice" which addresses the direct-cause of the crash. Note that the crash was already fixed in v1 because that removed the code-path where kset_unregister ended up being called twice.
-Dropped: "platform/x86: dell-wmi-sysman: Make init_bios_attributes() ACPI object parsing more robust". This needs more testing / discussion and is not necessary to fix the boot-failure which people are seeing.
Regards,
Hans
Hans de Goede (7):
platform/x86: dell-wmi-sysman: Fix crash caused by calling
kset_unregister twice
platform/x86: dell-wmi-sysman: Fix possible NULL pointer deref on exit platform/x86: dell-wmi-sysman: Make it safe to call
exit_foo_attributes() multiple times
platform/x86: dell-wmi-sysman: Fix release_attributes_data() getting
called twice on init_bios_attributes() failure
platform/x86: dell-wmi-sysman: Cleanup sysman_init() error-exit
handling
platform/x86: dell-wmi-sysman: Make sysman_init() return -ENODEV of
the interfaces are not found
platform/x86: dell-wmi-sysman: Cleanup
create_attributes_level_sysfs_files()
.../dell/dell-wmi-sysman/enum-attributes.c | 3 + .../x86/dell/dell-wmi-sysman/int-attributes.c | 3 + .../dell/dell-wmi-sysman/passobj-attributes.c | 3 + .../dell/dell-wmi-sysman/string-attributes.c | 3 + .../x86/dell/dell-wmi-sysman/sysman.c | 84 +++++++------------ 5 files changed, 44 insertions(+), 52 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/7 platform/x86: dell-wmi-sysman: Fix crash caused by calling kset_unregister twice
On some system the WMI GUIDs used by dell-wmi-sysman are present but there are no enum type attributes, this causes init_bios_attributes() to return -ENODEV, after which sysman_init() does a "goto fail_create_group" and then calls release_attributes_data().
release_attributes_data() calls kset_unregister(wmi_priv.main_dir_kset); but before this commit it was missing a "wmi_priv.main_dir_kset = NULL;" statement; and after calling release_attributes_data() the sysman_init() error handling does this:
if (wmi_priv.main_dir_kset) {
kset_unregister(wmi_priv.main_dir_kset);
wmi_priv.main_dir_kset = NULL;
}Which causes a second kset_unregister(wmi_priv.main_dir_kset), leading to a double-free, which causes a crash.
Add the missing "wmi_priv.main_dir_kset = NULL;" statement to release_attributes_data() to fix this double-free crash.
--- drivers/platform/x86/dell/dell-wmi-sysman/sysman.c | 1 + 1 file changed, 1 insertion(+)
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +1 -0
@@ -388,6 +388,7 @@ static void release_attributes_data(void)if (wmi_priv.main_dir_kset) {destroy_attribute_objs (wmi_priv.main_dir_kset);kset_unregister (wmi_priv.main_dir_kset); + wmi_priv.main_dir_kset =NULL ; }mutex_unlock (&wmi_priv.mutex);
Signature · 1 line
2.30.2
PATCH v2 2/7 platform/x86: dell-wmi-sysman: Fix possible NULL pointer deref on exit
In reply to Hans de GoedeIt is possible for release_attributes_data() to get called when the main_dir_kset has not been created yet, move the removal of the bios-reset sysfs attr to under a if (main_dir_kset) check to avoid a NULL pointer deref.
--- drivers/platform/x86/dell/dell-wmi-sysman/sysman.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +2 -9
@@ -225,12 +225,6 @@ static int create_attributes_level_sysfs_files(void)return ret; } -static void release_reset_bios_data (void ) -{ -sysfs_remove_file (&wmi_priv.main_dir_kset->kobj, &reset_bios.attr); -sysfs_remove_file (&wmi_priv.main_dir_kset->kobj, &pending_reboot.attr); -} -static ssize_t wmi_sysman_attr_show (struct kobject *kobj,struct attribute *attr,char *buf) {
@@ -373,8 +367,6 @@ static void destroy_attribute_objs(struct kset *kset)*/ static void release_attributes_data (void ) { -release_reset_bios_data (); -mutex_lock (&wmi_priv.mutex);exit_enum_attributes ();exit_int_attributes ();
@@ -386,12 +378,13 @@ static void release_attributes_data(void) wmi_priv.authentication_dir_kset =NULL ; }if (wmi_priv.main_dir_kset) { +sysfs_remove_file (&wmi_priv.main_dir_kset->kobj, &reset_bios.attr); +sysfs_remove_file (&wmi_priv.main_dir_kset->kobj, &pending_reboot.attr);destroy_attribute_objs (wmi_priv.main_dir_kset);kset_unregister (wmi_priv.main_dir_kset); wmi_priv.main_dir_kset =NULL ; }mutex_unlock (&wmi_priv.mutex); - }/**
Signature · 1 line
2.30.2
PATCH v2 3/7 platform/x86: dell-wmi-sysman: Make it safe to call exit_foo_attributes() multiple times
In reply to Hans de GoedeDuring some of the error-exit paths it is possible that release_attributes_data() will get called multiple times, which results in exit_foo_attributes() getting called multiple times.
Make it safe to call exit_foo_attributes() multiple times, avoiding double-free()s in this case.
Note that release_attributes_data() really should only be called once during error-exit paths. This will be fixed in a separate patch and it is good to have the exit_foo_attributes() functions modified this way regardless.
--- drivers/platform/x86/dell/dell-wmi-sysman/enum-attributes.c | 3 +++ drivers/platform/x86/dell/dell-wmi-sysman/int-attributes.c | 3 +++ drivers/platform/x86/dell/dell-wmi-sysman/passobj-attributes.c | 3 +++ drivers/platform/x86/dell/dell-wmi-sysman/string-attributes.c | 3 +++ 4 files changed, 12 insertions(+)
drivers/platform/x86/dell/dell-wmi-sysman/enum-attributes.c +3 -0
@@ -185,5 +185,8 @@ void exit_enum_attributes(void)sysfs_remove_group (wmi_priv.enumeration_data[instance_id].attr_name_kobj, &enumeration_attr_group); } + wmi_priv.enumeration_instances_count =0 ; +kfree (wmi_priv.enumeration_data); + wmi_priv.enumeration_data =NULL ; }
drivers/platform/x86/dell/dell-wmi-sysman/int-attributes.c +3 -0
@@ -175,5 +175,8 @@ void exit_int_attributes(void)sysfs_remove_group (wmi_priv.integer_data[instance_id].attr_name_kobj, &integer_attr_group); } + wmi_priv.integer_instances_count =0 ; +kfree (wmi_priv.integer_data); + wmi_priv.integer_data =NULL ; }
drivers/platform/x86/dell/dell-wmi-sysman/passobj-attributes.c +3 -0
@@ -183,5 +183,8 @@ void exit_po_attributes(void)sysfs_remove_group (wmi_priv.po_data[instance_id].attr_name_kobj, &po_attr_group); } + wmi_priv.po_instances_count =0 ; +kfree (wmi_priv.po_data); + wmi_priv.po_data =NULL ; }
drivers/platform/x86/dell/dell-wmi-sysman/string-attributes.c +3 -0
@@ -155,5 +155,8 @@ void exit_str_attributes(void)sysfs_remove_group (wmi_priv.str_data[instance_id].attr_name_kobj, &str_attr_group); } + wmi_priv.str_instances_count =0 ; +kfree (wmi_priv.str_data); + wmi_priv.str_data =NULL ; }
Signature · 1 line
2.30.2
PATCH v2 4/7 platform/x86: dell-wmi-sysman: Fix release_attributes_data() getting called twice on init_bios_attributes() failure
In reply to Hans de GoedeAll calls of init_bios_attributes() will result in a goto fail_create_group if they fail, which calls release_attributes_data().
So there is no need to call release_attributes_data() from init_bios_attributes() on failure itself.
--- drivers/platform/x86/dell/dell-wmi-sysman/sysman.c | 1 - 1 file changed, 1 deletion(-)
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +0 -1
@@ -491,7 +491,6 @@ static int init_bios_attributes(int attr_type, const char *guid) err_attr_init:mutex_unlock (&wmi_priv.mutex); -release_attributes_data ();kfree (obj);return retval; }
Signature · 1 line
2.30.2
PATCH v2 5/7 platform/x86: dell-wmi-sysman: Cleanup sysman_init() error-exit handling
In reply to Hans de GoedeCleanup sysman_init() error-exit handling:
1. There is no need for the fail_reset_bios and fail_authentication_kset eror-exit cases, these can be handled by release_attributes_data()
2. Rename all the labels from fail_what_failed, to err_what_to_cleanup this is the usual way to name these and avoids the need to rename them when extra steps are added.
--- .../x86/dell/dell-wmi-sysman/sysman.c | 45 +++++++------------ 1 file changed, 16 insertions(+), 29 deletions(-)
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +16 -29
@@ -508,100 +508,87 @@ static int __init sysman_init(void) ret =init_bios_attr_set_interface ();if (ret || !wmi_priv.bios_attr_wdev) {pr_debug ("failed to initialize set interface\n" ); - goto fail_set_interface; +return ret; } ret =init_bios_attr_pass_interface ();if (ret || !wmi_priv.password_attr_wdev) {pr_debug ("failed to initialize pass interface\n" ); - goto fail_pass_interface; + goto err_exit_bios_attr_set_interface; } ret =class_register (&firmware_attributes_class);if (ret) - goto fail_class; + goto err_exit_bios_attr_pass_interface; wmi_priv.class_dev =device_create (&firmware_attributes_class,NULL ,MKDEV (0 ,0 ),NULL ,"%s" ,DRIVER_NAME );if (IS_ERR (wmi_priv.class_dev)) { ret =PTR_ERR (wmi_priv.class_dev); - goto fail_classdev; + goto err_unregister_class; } wmi_priv.main_dir_kset =kset_create_and_add ("attributes" ,NULL , &wmi_priv.class_dev->kobj);if (!wmi_priv.main_dir_kset) { ret = -ENOMEM ; - goto fail_main_kset; + goto err_destroy_classdev; } wmi_priv.authentication_dir_kset =kset_create_and_add ("authentication" ,NULL , &wmi_priv.class_dev->kobj);if (!wmi_priv.authentication_dir_kset) { ret = -ENOMEM ; - goto fail_authentication_kset; + goto err_release_attributes_data; } ret =create_attributes_level_sysfs_files ();if (ret) {pr_debug ("could not create reset BIOS attribute\n" ); - goto fail_reset_bios; + goto err_release_attributes_data; } ret =init_bios_attributes (ENUM ,DELL_WMI_BIOS_ENUMERATION_ATTRIBUTE_GUID );if (ret) {pr_debug ("failed to populate enumeration type attributes\n" ); - goto fail_create_group; + goto err_release_attributes_data; } ret =init_bios_attributes (INT ,DELL_WMI_BIOS_INTEGER_ATTRIBUTE_GUID );if (ret) {pr_debug ("failed to populate integer type attributes\n" ); - goto fail_create_group; + goto err_release_attributes_data; } ret =init_bios_attributes (STR ,DELL_WMI_BIOS_STRING_ATTRIBUTE_GUID );if (ret) {pr_debug ("failed to populate string type attributes\n" ); - goto fail_create_group; + goto err_release_attributes_data; } ret =init_bios_attributes (PO ,DELL_WMI_BIOS_PASSOBJ_ATTRIBUTE_GUID );if (ret) {pr_debug ("failed to populate pass object type attributes\n" ); - goto fail_create_group; + goto err_release_attributes_data; }return 0 ; -fail_create_group: +err_release_attributes_data:release_attributes_data (); -fail_reset_bios: -if (wmi_priv.authentication_dir_kset) { -kset_unregister (wmi_priv.authentication_dir_kset); - wmi_priv.authentication_dir_kset =NULL ; - } - -fail_authentication_kset: -if (wmi_priv.main_dir_kset) { -kset_unregister (wmi_priv.main_dir_kset); - wmi_priv.main_dir_kset =NULL ; - } - -fail_main_kset: +err_destroy_classdev:device_destroy (&firmware_attributes_class,MKDEV (0 ,0 )); -fail_classdev: +err_unregister_class:class_unregister (&firmware_attributes_class); -fail_class: +err_exit_bios_attr_pass_interface:exit_bios_attr_pass_interface (); -fail_pass_interface: +err_exit_bios_attr_set_interface:exit_bios_attr_set_interface (); -fail_set_interface:return ret; }
Signature · 1 line
2.30.2
PATCH v2 6/7 platform/x86: dell-wmi-sysman: Make sysman_init() return -ENODEV of the interfaces are not found
In reply to Hans de GoedeWhen either the attributes or the password interface is not found, then unregister the 2 wmi drivers again and return -ENODEV from sysman_init().
--- drivers/platform/x86/dell/dell-wmi-sysman/sysman.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +7 -5
@@ -506,15 +506,17 @@ static int __init sysman_init(void) } ret =init_bios_attr_set_interface (); -if (ret || !wmi_priv.bios_attr_wdev) { -pr_debug ("failed to initialize set interface\n" ); +if (ret)return ret; - } ret =init_bios_attr_pass_interface (); -if (ret || !wmi_priv.password_attr_wdev) { -pr_debug ("failed to initialize pass interface\n" ); +if (ret) goto err_exit_bios_attr_set_interface; + +if (!wmi_priv.bios_attr_wdev || !wmi_priv.password_attr_wdev) { +pr_debug ("failed to find set or pass interface\n" ); + ret = -ENODEV ; + goto err_exit_bios_attr_pass_interface; } ret =class_register (&firmware_attributes_class);
Signature · 1 line
2.30.2
PATCH v2 7/7 platform/x86: dell-wmi-sysman: Cleanup create_attributes_level_sysfs_files()
In reply to Hans de GoedeCleanup create_attributes_level_sysfs_files():
1. There is no need to call sysfs_remove_file() on error, sysman_init() will already call release_attributes_data() on failure which already does this.
2. There is no need for the pr_debug() calls sysfs_create_file() should never fail and if it does it will already complain about the problem itself.
--- .../platform/x86/dell/dell-wmi-sysman/sysman.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +7 -9
@@ -210,19 +210,17 @@ static struct kobj_attribute pending_reboot = __ATTR_RO(pending_reboot);*/ static int create_attributes_level_sysfs_files (void ) { -int ret =sysfs_create_file (&wmi_priv.main_dir_kset->kobj, &reset_bios.attr); +int ret; -if (ret) { -pr_debug ("could not create reset_bios file\n" ); + ret =sysfs_create_file (&wmi_priv.main_dir_kset->kobj, &reset_bios.attr); +if (ret)return ret; - } ret =sysfs_create_file (&wmi_priv.main_dir_kset->kobj, &pending_reboot.attr); -if (ret) { -pr_debug ("could not create changing_pending_reboot file\n" ); -sysfs_remove_file (&wmi_priv.main_dir_kset->kobj, &reset_bios.attr); - } -return ret; +if (ret) +return ret; + +return 0 ; } static ssize_t wmi_sysman_attr_show(struct kobject *kobj, struct attribute *attr,
Signature · 1 line
2.30.2
Hi,
Quoted 19 lines · Hans de Goede
Hi All,
There have been several bug-reports about crashes related to the dell-wmi-sysman module:
https://bugzilla.redhat.com/show_bug.cgi?id=1936171
https://bugzilla.kernel.org/show_bug.cgi?id=211895
https://bugs.archlinux.org/task/69702Here is v2 of my series with a bunch of fixes for NULL pointer derefs, double-frees, etc. which fixes this.
New in v2:
-New patch: "platform/x86: dell-wmi-sysman: Fix crash caused by callingkset_unregistertwice" which addresses the direct-cause of the crash. Note that the crash was already fixed in v1 because that removed the code-path wherekset_unregisterended up being called twice.
Quoted 3 lines
-Dropped: "platform/x86: dell-wmi-sysman: Make
init_bios_attributes()ACPI object parsing more robust". This needs more testing / discussion and is not necessary to fix the boot-failure which people are seeing.
I've added this series to the pdx86/review-hans and pdx86/fixes branches, so it should show up in linux-next soon and it will also be included in my next pull-req to Linus for 5.12.
Regards,
Hans
Quoted 22 lines
Hans de Goede (7):
platform/x86: dell-wmi-sysman: Fix crash caused by calling
kset_unregistertwice
platform/x86: dell-wmi-sysman: Fix possible NULL pointer deref on exit platform/x86: dell-wmi-sysman: Make it safe to call
exit_foo_attributes()multiple times
platform/x86: dell-wmi-sysman: Fixrelease_attributes_data()getting
called twice oninit_bios_attributes()failure
platform/x86: dell-wmi-sysman: Cleanupsysman_init()error-exit
handling
platform/x86: dell-wmi-sysman: Makesysman_init()return-ENODEVof
the interfaces are not found
platform/x86: dell-wmi-sysman: Cleanup
create_attributes_level_sysfs_files().../dell/dell-wmi-sysman/enum-attributes.c | 3 + .../x86/dell/dell-wmi-sysman/int-attributes.c | 3 + .../dell/dell-wmi-sysman/passobj-attributes.c | 3 + .../dell/dell-wmi-sysman/string-attributes.c | 3 + .../x86/dell/dell-wmi-sysman/sysman.c | 84 +++++++------------ 5 files changed, 44 insertions(+), 52 deletions(-)