Skip to content

Commit 5805edb

Browse files
kuu-rtgregkh
authored andcommitted
platform/x86: think-lmi: Fix kobject cleanup
commit 9110056 upstream. In tlmi_analyze(), allocated structs with an embedded kobject are freed in error paths after the they were already initialized. Fix this by first by avoiding the initialization of kobjects in tlmi_analyze() and then by correctly cleaning them up in tlmi_release_attr() using their kset's kobject list. Fixes: a40cd7e ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms") Fixes: 30e7843 ("platform/x86: think-lmi: Split kobject_init() and kobject_add() calls") Cc: [email protected] Reviewed-by: Mark Pearson <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Kurt Borja <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b11397b commit 5805edb

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,13 +1313,13 @@ static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
13131313
/* ---- Initialisation --------------------------------------------------------- */
13141314
static void tlmi_release_attr(void)
13151315
{
1316+
struct kobject *pos, *n;
13161317
int i;
13171318

13181319
/* Attribute structures */
13191320
for (i = 0; i < TLMI_SETTINGS_COUNT; i++) {
13201321
if (tlmi_priv.setting[i]) {
13211322
sysfs_remove_group(&tlmi_priv.setting[i]->kobj, &tlmi_attr_group);
1322-
kobject_put(&tlmi_priv.setting[i]->kobj);
13231323
}
13241324
}
13251325
sysfs_remove_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
@@ -1328,6 +1328,9 @@ static void tlmi_release_attr(void)
13281328
if (tlmi_priv.can_debug_cmd && debug_support)
13291329
sysfs_remove_file(&tlmi_priv.attribute_kset->kobj, &debug_cmd.attr);
13301330

1331+
list_for_each_entry_safe(pos, n, &tlmi_priv.attribute_kset->list, entry)
1332+
kobject_put(pos);
1333+
13311334
kset_unregister(tlmi_priv.attribute_kset);
13321335

13331336
/* Free up any saved signatures */
@@ -1336,19 +1339,17 @@ static void tlmi_release_attr(void)
13361339

13371340
/* Authentication structures */
13381341
sysfs_remove_group(&tlmi_priv.pwd_admin->kobj, &auth_attr_group);
1339-
kobject_put(&tlmi_priv.pwd_admin->kobj);
13401342
sysfs_remove_group(&tlmi_priv.pwd_power->kobj, &auth_attr_group);
1341-
kobject_put(&tlmi_priv.pwd_power->kobj);
13421343

13431344
if (tlmi_priv.opcode_support) {
13441345
sysfs_remove_group(&tlmi_priv.pwd_system->kobj, &auth_attr_group);
1345-
kobject_put(&tlmi_priv.pwd_system->kobj);
13461346
sysfs_remove_group(&tlmi_priv.pwd_hdd->kobj, &auth_attr_group);
1347-
kobject_put(&tlmi_priv.pwd_hdd->kobj);
13481347
sysfs_remove_group(&tlmi_priv.pwd_nvme->kobj, &auth_attr_group);
1349-
kobject_put(&tlmi_priv.pwd_nvme->kobj);
13501348
}
13511349

1350+
list_for_each_entry_safe(pos, n, &tlmi_priv.authentication_kset->list, entry)
1351+
kobject_put(pos);
1352+
13521353
kset_unregister(tlmi_priv.authentication_kset);
13531354
}
13541355

@@ -1412,8 +1413,8 @@ static int tlmi_sysfs_init(void)
14121413

14131414
/* Build attribute */
14141415
tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
1415-
ret = kobject_add(&tlmi_priv.setting[i]->kobj, NULL,
1416-
"%s", tlmi_priv.setting[i]->display_name);
1416+
ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
1417+
NULL, "%s", tlmi_priv.setting[i]->display_name);
14171418
if (ret)
14181419
goto fail_create_attr;
14191420

@@ -1438,7 +1439,8 @@ static int tlmi_sysfs_init(void)
14381439

14391440
/* Create authentication entries */
14401441
tlmi_priv.pwd_admin->kobj.kset = tlmi_priv.authentication_kset;
1441-
ret = kobject_add(&tlmi_priv.pwd_admin->kobj, NULL, "%s", "Admin");
1442+
ret = kobject_init_and_add(&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype,
1443+
NULL, "%s", "Admin");
14421444
if (ret)
14431445
goto fail_create_attr;
14441446

@@ -1447,7 +1449,8 @@ static int tlmi_sysfs_init(void)
14471449
goto fail_create_attr;
14481450

14491451
tlmi_priv.pwd_power->kobj.kset = tlmi_priv.authentication_kset;
1450-
ret = kobject_add(&tlmi_priv.pwd_power->kobj, NULL, "%s", "Power-on");
1452+
ret = kobject_init_and_add(&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype,
1453+
NULL, "%s", "Power-on");
14511454
if (ret)
14521455
goto fail_create_attr;
14531456

@@ -1457,7 +1460,8 @@ static int tlmi_sysfs_init(void)
14571460

14581461
if (tlmi_priv.opcode_support) {
14591462
tlmi_priv.pwd_system->kobj.kset = tlmi_priv.authentication_kset;
1460-
ret = kobject_add(&tlmi_priv.pwd_system->kobj, NULL, "%s", "System");
1463+
ret = kobject_init_and_add(&tlmi_priv.pwd_system->kobj, &tlmi_pwd_setting_ktype,
1464+
NULL, "%s", "System");
14611465
if (ret)
14621466
goto fail_create_attr;
14631467

@@ -1466,7 +1470,8 @@ static int tlmi_sysfs_init(void)
14661470
goto fail_create_attr;
14671471

14681472
tlmi_priv.pwd_hdd->kobj.kset = tlmi_priv.authentication_kset;
1469-
ret = kobject_add(&tlmi_priv.pwd_hdd->kobj, NULL, "%s", "HDD");
1473+
ret = kobject_init_and_add(&tlmi_priv.pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
1474+
NULL, "%s", "HDD");
14701475
if (ret)
14711476
goto fail_create_attr;
14721477

@@ -1475,7 +1480,8 @@ static int tlmi_sysfs_init(void)
14751480
goto fail_create_attr;
14761481

14771482
tlmi_priv.pwd_nvme->kobj.kset = tlmi_priv.authentication_kset;
1478-
ret = kobject_add(&tlmi_priv.pwd_nvme->kobj, NULL, "%s", "NVMe");
1483+
ret = kobject_init_and_add(&tlmi_priv.pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
1484+
NULL, "%s", "NVMe");
14791485
if (ret)
14801486
goto fail_create_attr;
14811487

@@ -1512,8 +1518,6 @@ static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type,
15121518
new_pwd->maxlen = tlmi_priv.pwdcfg.core.max_length;
15131519
new_pwd->index = 0;
15141520

1515-
kobject_init(&new_pwd->kobj, &tlmi_pwd_setting_ktype);
1516-
15171521
return new_pwd;
15181522
}
15191523

@@ -1617,7 +1621,6 @@ static int tlmi_analyze(void)
16171621
if (setting->possible_values)
16181622
strreplace(setting->possible_values, ',', ';');
16191623

1620-
kobject_init(&setting->kobj, &tlmi_attr_setting_ktype);
16211624
tlmi_priv.setting[i] = setting;
16221625
kfree(item);
16231626
}

0 commit comments

Comments
 (0)