platform/x86: dell-wmi-sysman: fix kobject leak on populate failure
Subsystems (3)
PATCH 1/1 platform/x86: dell-wmi-sysman: fix kobject leak on populate failure
When populate_enum_data(), populate_int_data(), populate_str_data(), or populate_po_data() fails after a successful kobject_init_and_add(), the code jumps to err_attr_init without calling kobject_put() on attr_name_kobj, leaking the kobject and its associated memory.
Add the missing kobject_put() call before the goto to properly release the kobject on error.
--- 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
@@ -497,6 +497,7 @@ static int init_bios_attributes(int attr_type, const char *guid)if (retval) {pr_debug ("failed to populate %s\n" , elements[ATTR_NAME ].string.pointer); +kobject_put (attr_name_kobj); goto err_attr_init; }
Signature · 1 line
2.52.0
Greg KH
maintainerQuoted 20 lines · Daniel Hodges
When
populate_enum_data(),populate_int_data(),populate_str_data(), orpopulate_po_data()fails after a successfulkobject_init_and_add(), the code jumps toerr_attr_initwithout callingkobject_put()onattr_name_kobj, leaking the kobject and its associated memory.Add the missing
kobject_put()call before the goto to properly release the kobject on error.Fixes e8a60aa7404b ("platform/x86: Introduce support for Systems Management Driver over WMI for Dell Systems")Signed-off-by Daniel Hodges <[email protected]>--- drivers/platform/x86/dell/dell-wmi-sysman/sysman.c | 1 + 1 file changed, 1 insertion(+)drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +0
-0
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c static int init_bios_attributes(int attr_type, const char *guid) · line 503
Quoted 7 lines
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +1
-0@@ -497,6 +497,7 @@ static int init_bios_attributes(int attr_type, const char *guid)if (retval) {pr_debug ("failed to populate %s\n" , elements[ATTR_NAME ].string.pointer); +kobject_put (attr_name_kobj); goto err_attr_init; }
The "larger" problem with this driver is its use of raw kobjects. No driver should be doing that, it is hiding all of this information from userspace tools by doing so, and there's loads of race conditions happening with the creation of these files. It should be fixed by just using normal device attributes and not attempting to custom create kobjects by hand like this (as it is very easy to get things wrong, as this patch shows.)
thanks,
greg k-h
Quoted 37 lines · Greg KH
Quoted 20 lines · Daniel Hodges
When
populate_enum_data(),populate_int_data(),populate_str_data(), orpopulate_po_data()fails after a successfulkobject_init_and_add(), the code jumps toerr_attr_initwithout callingkobject_put()onattr_name_kobj, leaking the kobject and its associated memory.Add the missing
kobject_put()call before the goto to properly release the kobject on error.Fixes e8a60aa7404b ("platform/x86: Introduce support for Systems Management Driver over WMI for Dell Systems")Signed-off-by Daniel Hodges <[email protected]>--- drivers/platform/x86/dell/dell-wmi-sysman/sysman.c | 1 + 1 file changed, 1 insertion(+)drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +0
-0drivers/platform/x86/dell/dell-wmi-sysman/sysman.c static int init_bios_attributes(int attr_type, const char *guid) · line 503
Quoted 7 lines
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +1
-0@@ -497,6 +497,7 @@ static int init_bios_attributes(int attr_type, const char *guid)if (retval) {pr_debug ("failed to populate %s\n" , elements[ATTR_NAME ].string.pointer); +kobject_put (attr_name_kobj); goto err_attr_init; }The "larger" problem with this driver is its use of raw kobjects. No driver should be doing that, it is hiding all of this information from userspace tools by doing so, and there's loads of race conditions happening with the creation of these files. It should be fixed by just using normal device attributes and not attempting to custom create kobjects by hand like this (as it is very easy to get things wrong, as this patch shows.)
Quoted 3 lines
thanks,
greg k-h
Yeah, that makes sense. I think your point of finding "bad patterns" in usage would also be really helpful for code analysis tools. If there's some canonical docs on various antipatterns it would be pretty helpful.
-Daniel
Greg KH
maintainerQuoted 38 lines · Daniel Hodges
Quoted 37 lines · Greg KH
Quoted 20 lines · Daniel Hodges
When
populate_enum_data(),populate_int_data(),populate_str_data(), orpopulate_po_data()fails after a successfulkobject_init_and_add(), the code jumps toerr_attr_initwithout callingkobject_put()onattr_name_kobj, leaking the kobject and its associated memory.Add the missing
kobject_put()call before the goto to properly release the kobject on error.Fixes e8a60aa7404b ("platform/x86: Introduce support for Systems Management Driver over WMI for Dell Systems")Signed-off-by Daniel Hodges <[email protected]>--- drivers/platform/x86/dell/dell-wmi-sysman/sysman.c | 1 + 1 file changed, 1 insertion(+)drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +0
-0drivers/platform/x86/dell/dell-wmi-sysman/sysman.c static int init_bios_attributes(int attr_type, const char *guid) · line 503
Quoted 7 lines
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +1
-0@@ -497,6 +497,7 @@ static int init_bios_attributes(int attr_type, const char *guid)if (retval) {pr_debug ("failed to populate %s\n" , elements[ATTR_NAME ].string.pointer); +kobject_put (attr_name_kobj); goto err_attr_init; }The "larger" problem with this driver is its use of raw kobjects. No driver should be doing that, it is hiding all of this information from userspace tools by doing so, and there's loads of race conditions happening with the creation of these files. It should be fixed by just using normal device attributes and not attempting to custom create kobjects by hand like this (as it is very easy to get things wrong, as this patch shows.)
Quoted 7 lines
Quoted 3 lines
thanks,
greg k-h
Yeah, that makes sense. I think your point of finding "bad patterns" in usage would also be really helpful for code analysis tools. If there's some canonical docs on various antipatterns it would be pretty helpful.
Huge hint, any driver that calls any sysfs_*() function or touches a kobject at all, is probably doing things wrong. Start there and see what you find :)
thanks,
greg k-h