Skip to content

Commit c41e012

Browse files
mrhpearsonjwrdegoede
authored andcommitted
platform/x86: think-lmi: mutex protection around multiple WMI calls
When an attribute is being changed if the Admin account is enabled, or if a password is being updated then multiple WMI calls are needed. Add mutex protection to ensure no race conditions are introduced. Fixes: b49f72e ("platform/x86: think-lmi: Certificate authentication support") Signed-off-by: Mark Pearson <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]>
1 parent 416a87c commit c41e012

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/acpi.h>
1515
#include <linux/errno.h>
1616
#include <linux/fs.h>
17+
#include <linux/mutex.h>
1718
#include <linux/string.h>
1819
#include <linux/types.h>
1920
#include <linux/dmi.h>
@@ -195,6 +196,7 @@ static const char * const level_options[] = {
195196
};
196197
static struct think_lmi tlmi_priv;
197198
static struct class *fw_attr_class;
199+
static DEFINE_MUTEX(tlmi_mutex);
198200

199201
/* ------ Utility functions ------------*/
200202
/* Strip out CR if one is present */
@@ -437,6 +439,9 @@ static ssize_t new_password_store(struct kobject *kobj,
437439
/* Strip out CR if one is present, setting password won't work if it is present */
438440
strip_cr(new_pwd);
439441

442+
/* Use lock in case multiple WMI operations needed */
443+
mutex_lock(&tlmi_mutex);
444+
440445
pwdlen = strlen(new_pwd);
441446
/* pwdlen == 0 is allowed to clear the password */
442447
if (pwdlen && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen))) {
@@ -493,6 +498,7 @@ static ssize_t new_password_store(struct kobject *kobj,
493498
kfree(auth_str);
494499
}
495500
out:
501+
mutex_unlock(&tlmi_mutex);
496502
kfree(new_pwd);
497503
return ret ?: count;
498504
}
@@ -981,6 +987,9 @@ static ssize_t current_value_store(struct kobject *kobj,
981987
/* Strip out CR if one is present */
982988
strip_cr(new_setting);
983989

990+
/* Use lock in case multiple WMI operations needed */
991+
mutex_lock(&tlmi_mutex);
992+
984993
/* Check if certificate authentication is enabled and active */
985994
if (tlmi_priv.certificate_support && tlmi_priv.pwd_admin->cert_installed) {
986995
if (!tlmi_priv.pwd_admin->signature || !tlmi_priv.pwd_admin->save_signature) {
@@ -1039,6 +1048,7 @@ static ssize_t current_value_store(struct kobject *kobj,
10391048
kobject_uevent(&tlmi_priv.class_dev->kobj, KOBJ_CHANGE);
10401049
}
10411050
out:
1051+
mutex_unlock(&tlmi_mutex);
10421052
kfree(auth_str);
10431053
kfree(set_str);
10441054
kfree(new_setting);

0 commit comments

Comments
 (0)