Skip to content

Commit 528ab3e

Browse files
Wer-Wolfjwrdegoede
authored andcommitted
platform/x86: think-lmi: Fix reference leak
If a duplicate attribute is found using kset_find_obj(), a reference to that attribute is returned which needs to be disposed accordingly using kobject_put(). Move the setting name validation into a separate function to allow for this change without having to duplicate the cleanup code for this setting. As a side note, a very similar bug was fixed in commit 7295a99 ("platform/x86: dell-sysman: Fix reference leak"), so it seems that the bug was copied from that driver. Compile-tested only. Fixes: 1bcad8e ("platform/x86: think-lmi: Fix issues with duplicate attributes") Reviewed-by: Mark Pearson <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Armin Wolf <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent bc3b6f5 commit 528ab3e

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,24 @@ static void tlmi_release_attr(void)
12481248
kset_unregister(tlmi_priv.authentication_kset);
12491249
}
12501250

1251+
static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
1252+
{
1253+
struct kobject *duplicate;
1254+
1255+
if (!strcmp(name, "Reserved"))
1256+
return -EINVAL;
1257+
1258+
duplicate = kset_find_obj(attribute_kset, name);
1259+
if (duplicate) {
1260+
pr_debug("Duplicate attribute name found - %s\n", name);
1261+
/* kset_find_obj() returns a reference */
1262+
kobject_put(duplicate);
1263+
return -EBUSY;
1264+
}
1265+
1266+
return 0;
1267+
}
1268+
12511269
static int tlmi_sysfs_init(void)
12521270
{
12531271
int i, ret;
@@ -1276,10 +1294,8 @@ static int tlmi_sysfs_init(void)
12761294
continue;
12771295

12781296
/* check for duplicate or reserved values */
1279-
if (kset_find_obj(tlmi_priv.attribute_kset, tlmi_priv.setting[i]->display_name) ||
1280-
!strcmp(tlmi_priv.setting[i]->display_name, "Reserved")) {
1281-
pr_debug("duplicate or reserved attribute name found - %s\n",
1282-
tlmi_priv.setting[i]->display_name);
1297+
if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
1298+
tlmi_priv.setting[i]->display_name) < 0) {
12831299
kfree(tlmi_priv.setting[i]->possible_values);
12841300
kfree(tlmi_priv.setting[i]);
12851301
tlmi_priv.setting[i] = NULL;

0 commit comments

Comments
 (0)