Skip to contentSkip to conversation

platform: x86: Use kfree_sensitive instead of kfree

PATCH In review Wang Ming 3 participants 3 messages Jul 17, 2023 – Jul 25, 2023 x86 platform drivers

lore
Share & tools
lore

Wang Ming

author
#0 lore raw

PATCH 1/1 platform: x86: Use kfree_sensitive instead of kfree

key might contain private part of the key, so better use kfree_sensitive to free it.

---
 drivers/platform/x86/think-lmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/think-lmi.c +2 -2
index 52d1ce8dfe44..79346881cadb 100644
@@ -719,12 +719,12 @@ static ssize_t cert_to_password_store(struct kobject *kobj,
 	/* Format: 'Password,Signature' */
 	auth_str = kasprintf(GFP_KERNEL, "%s,%s", passwd, setting->signature);
 	if (!auth_str) {
-		kfree(passwd);
+		kfree_sensitive(passwd);
 		return -ENOMEM;
 	}
 	ret = tlmi_simple_call(LENOVO_CERT_TO_PASSWORD_GUID, auth_str);
 	kfree(auth_str);
-	kfree(passwd);
+	kfree_sensitive(passwd);
 
 	return ret ?: count;
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 17 lines · Wang Ming

key might contain private part of the key, so better use kfree_sensitive to free it.

---
  drivers/platform/x86/think-lmi.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/think-lmi.c +0 -1
index 52d1ce8dfe44..79346881cadb 100644
@@ -719,12 +719,12 @@ static ssize_t cert_to_password_store(struct kobject *kobj,
  	/* Format: 'Password,Signature' */
  	auth_str = kasprintf(GFP_KERNEL, "%s,%s", passwd, setting->signature);
  	if (!auth_str) {
-		kfree(passwd);

drivers/platform/x86/think-lmi.c static ssize_t cert_to_password_store(struct kobject *kobj, · line 730

Quoted 10 lines
drivers/platform/x86/think-lmi.c +2 -1
+		kfree_sensitive(passwd);
  		return -ENOMEM;
  	}
  	ret = tlmi_simple_call(LENOVO_CERT_TO_PASSWORD_GUID, auth_str);
  	kfree(auth_str);
-	kfree(passwd);
+	kfree_sensitive(passwd);
 
  	return ret ?: count;
  }

I wasn't aware of kfree_sensitive - looks good to me!

Thank you

Mark

#2 lore raw
In reply to Wang Ming

Hi,

Quoted 4 lines · Wang Ming

key might contain private part of the key, so better use kfree_sensitive to free it.

Thank you for your patch, I've applied this patch to my fixes branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=fixes

Note it will show up in my fixes branch once I've pushed my local branch there, which might take a while.

I will include this patch in my next fixes pull-req to Linus for the current kernel development cycle.

Regards,

Hans

Quoted 23 lines
---
 drivers/platform/x86/think-lmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/think-lmi.c +2 -2
index 52d1ce8dfe44..79346881cadb 100644
@@ -719,12 +719,12 @@ static ssize_t cert_to_password_store(struct kobject *kobj,
 	/* Format: 'Password,Signature' */
 	auth_str = kasprintf(GFP_KERNEL, "%s,%s", passwd, setting->signature);
 	if (!auth_str) {
-		kfree(passwd);
+		kfree_sensitive(passwd);
 		return -ENOMEM;
 	}
 	ret = tlmi_simple_call(LENOVO_CERT_TO_PASSWORD_GUID, auth_str);
 	kfree(auth_str);
-	kfree(passwd);
+	kfree_sensitive(passwd);
 
 	return ret ?: count;
 }