Skip to contentSkip to conversation

platform/x86: think-lmi: Fix check for admin password being set

PATCH In review Hans de Goede 2 participants 4 messages Jun 9, 2021 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 platform/x86: think-lmi: Fix check for admin password being set

tlmi_priv.pwd_admin->password is an array (not a pointer), so the correct way to check for the password being set is to check for tlmi_priv.pwd_admin->password[0] != 0.

For the second check, replace the check with checking that auth_str is set instead.

Addresses-Coverity-ID: 1505158 ("NO_EFFECT")

Fixes a7314b3b1d8a ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms")
---
 drivers/platform/x86/think-lmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/think-lmi.c +2 -2
index c6413b906e4a..4881de4e669d 100644
@@ -537,7 +537,7 @@ static ssize_t current_value_store(struct kobject *kobj,
 	p = strchrnul(new_setting, '\n');
 	*p = '\0';
 
-	if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password) {
+	if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) {
 		auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;",
 				tlmi_priv.pwd_admin->password,
 				encoding_options[tlmi_priv.pwd_admin->encoding],
@@ -563,7 +563,7 @@ static ssize_t current_value_store(struct kobject *kobj,
 	if (ret)
 		goto out;
 
-	if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password)
+	if (auth_str)
 		ret = tlmi_save_bios_settings(auth_str);
 	else
 		ret = tlmi_save_bios_settings("");
Signature · 1 line
2.31.1
#1 lore raw

PATCH 2/2 platform/x86: think-lmi: Avoid potential read before start of the buffer

If length equals 0 then reading buf[length-1] will read before the start of the buffer.

Avoid this by moving the length == 0 check up.

---
 drivers/platform/x86/think-lmi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/platform/x86/think-lmi.c +4 -1
index 4881de4e669d..7771c9359449 100644
@@ -443,10 +443,13 @@ static ssize_t kbdlang_store(struct kobject *kobj,
 	int length;
 
 	length = strlen(buf);
+	if (!length)
+		return -EINVAL;
+
 	if (buf[length-1] == '\n')
 		length--;
 
-	if (!length || (length >= TLMI_LANG_MAXLEN))
+	if (length >= TLMI_LANG_MAXLEN)
 		return -EINVAL;
 
 	memcpy(setting->kbdlang, buf, length);
Signature · 1 line
2.31.1
#2 lore raw
In reply to Hans de Goede

Hi,

Quoted 7 lines · Hans de Goede

tlmi_priv.pwd_admin->password is an array (not a pointer), so the correct way to check for the password being set is to check for tlmi_priv.pwd_admin->password[0] != 0.

For the second check, replace the check with checking that auth_str is set instead.

Quoted 6 lines

Addresses-Coverity-ID: 1505158 ("NO_EFFECT")

Fixes a7314b3b1d8a ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms")

I've added this series to my review-hans branch (soon to be pdx86/for-next) branch now.

Regards,

Hans

Quoted 27 lines
---
 drivers/platform/x86/think-lmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/think-lmi.c +2 -2
index c6413b906e4a..4881de4e669d 100644
@@ -537,7 +537,7 @@ static ssize_t current_value_store(struct kobject *kobj,
 	p = strchrnul(new_setting, '\n');
 	*p = '\0';
 
-	if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password) {
+	if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) {
 		auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;",
 				tlmi_priv.pwd_admin->password,
 				encoding_options[tlmi_priv.pwd_admin->encoding],
@@ -563,7 +563,7 @@ static ssize_t current_value_store(struct kobject *kobj,
 	if (ret)
 		goto out;
 
-	if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password)
+	if (auth_str)
 		ret = tlmi_save_bios_settings(auth_str);
 	else
 		ret = tlmi_save_bios_settings("");
#3 lore raw
Quoted 17 lines · Hans de Goede

Hi,

Quoted 7 lines · Hans de Goede

tlmi_priv.pwd_admin->password is an array (not a pointer), so the correct way to check for the password being set is to check for tlmi_priv.pwd_admin->password[0] != 0.

For the second check, replace the check with checking that auth_str is set instead.

Quoted 6 lines

Addresses-Coverity-ID: 1505158 ("NO_EFFECT")

Fixes a7314b3b1d8a ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms")
Quoted 6 lines

I've added this series to my review-hans branch (soon to be pdx86/for-next) branch now.

Regards,

Hans

Thanks Hans - I was just about to start looking at these. You're fast :)

I think you've fixed everything I saw flagged - let me know if there is anything else I should look at and might have missed.

Mark