FAILED: patch "[PATCH] platform/x86: think-lmi: Fix current password length check" failed to apply to 6.1-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 54745d563114b74f6fecebce68cd020d06c1772b
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090342-duct-salutary-5524@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 54745d563114b74f6fecebce68cd020d06c1772b Mon Sep 17 00:00:00 2001
From: Thorsten Blum <[email protected]>
Date: Tue, 18 Aug 2026 17:16:35 +0200
Subject: [PATCH] platform/x86: think-lmi: Fix current password length check
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
current_password_store() checks the password length before removing the trailing newline, which can reject valid passwords that are exactly ->maxlen bytes long.
It also passes ->maxlen to strscpy(), which truncates passwords without a newline.
Use strchrnul() to measure the password length up to the newline, then copy that many bytes and add a trailing NUL terminator using strscpy().
drivers/platform/x86/lenovo/think-lmi.c +3 -4
@@ -438,14 +438,13 @@ static ssize_t current_password_store(struct kobject *kobj,struct tlmi_pwd_setting *setting =to_tlmi_pwd_setting (kobj);size_t pwdlen; - pwdlen =strlen (buf); +/* Strip newline; setting password won't work if one is present. */ + pwdlen =strchrnul (buf,'\n' ) - buf;/* pwdlen == 0 is allowed to clear the password */ if (pwdlen && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen)))return -EINVAL ; -strscpy (setting->password, buf, setting->maxlen); -/* Strip out CR if one is present, setting password won't work if it is present */ -strreplace (setting->password,'\n' ,'\0' ); +strscpy (setting->password, buf, pwdlen +1 );return count; }
Sasha Levin
maintainerPATCH 1/4 lib/string_helpers: Add kstrdup_and_replace() helper
From: Andy Shevchenko <[email protected]>
[ Upstream commit 045ad46441a1cf2ff358af0126f8c57f337804fa ]
Duplicate a NULL-terminated string and replace all occurrences of the old character with a new one. In other words, provide functionality of kstrdup() + strreplace().
Stable-dep-of: 54745d563114 ("platform/x86: think-lmi: Fix current password length check")
--- include/linux/string_helpers.h | 2 ++ lib/string_helpers.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+)
include/linux/string_helpers.h +2 -0
@@ -103,6 +103,8 @@ char *kstrdup_quotable(const char *src, gfp_t gfp);char *kstrdup_quotable_cmdline (struct task_struct *task,gfp_t gfp);char *kstrdup_quotable_file (struct file *file,gfp_t gfp); +char *kstrdup_and_replace (const char *src,char old,char new,gfp_t gfp); +char **kasprintf_strarray (gfp_t gfp,const char *prefix,size_t n);void kfree_strarray (char **array,size_t n);
lib/string_helpers.c +15 -0
@@ -719,6 +719,21 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp) }EXPORT_SYMBOL_GPL (kstrdup_quotable_file); +/* +* Returns duplicate string in which the @old characters are replaced by @new. +*/ +char *kstrdup_and_replace (const char *src,char old,char new,gfp_t gfp) +{ +char *dst; + + dst =kstrdup (src, gfp); +if (!dst) +return NULL ; + +return strreplace (dst, old, new); +} +EXPORT_SYMBOL_GPL (kstrdup_and_replace); +/** * kasprintf_strarray - allocate and fill array of sequential strings * @gfp: flags for the slab allocator
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 platform/x86: think-lmi: Replace kstrdup() + strreplace() with kstrdup_and_replace()
From: Andy Shevchenko <[email protected]>
[ Upstream commit e621198016e99cddc097d32cd3b56b15cee27d91 ]
Replace open coded functionalify of kstrdup_and_replace() with a call.
Adapt the current_value_store() conversion to the 6.1 tree, which lacks bulk-save support. Keep the existing permission and save behavior instead of introducing references to absent save_mode and reboot_required fields.
Also replace the remaining strip_cr() call in current_password_store() with strreplace() and remove the now-unused helper. This supplies the context expected by 54745d563114 ("platform/x86: think-lmi: Fix current password length check") without adding functions or changing the password length checks in this dependency.
The earlier kstrdup_and_replace() dependency also assumes the upstream strreplace() return-value change from d01a77afd6be. In this stable tree, strreplace() still returns the string's end, so explicitly return dst from kstrdup_and_replace() after performing the replacement. This preserves the allocation pointer for the newly converted callers and their frees.
Stable-dep-of: 54745d563114 ("platform/x86: think-lmi: Fix current password length check")
--- drivers/platform/x86/think-lmi.c | 53 ++++++++++---------------------- lib/string_helpers.c | 3 +- 2 files changed, 18 insertions(+), 38 deletions(-)
drivers/platform/x86/think-lmi.c +16 -37
@@ -15,7 +15,7 @@#include <linux/errno.h> #include <linux/fs.h> #include <linux/mutex.h> -#include <linux/string.h> +#include <linux/string_helpers.h> #include <linux/types.h> #include <linux/dmi.h> #include <linux/wmi.h>
@@ -198,14 +198,6 @@ static struct think_lmi tlmi_priv;static struct class *fw_attr_class;static DEFINE_MUTEX (tlmi_mutex); -/* ------ Utility functions ------------*/ -/* Strip out CR if one is present */ -static void strip_cr (char *str) -{ -char *p =strchrnul (str,'\n' ); - *p ='\0' ; -} -/* Convert BIOS WMI error string to suitable error code */ static int tlmi_errstr_to_err (const char *errstr) {
@@ -411,7 +403,7 @@ static ssize_t current_password_store(struct kobject *kobj,strscpy (setting->password, buf, setting->maxlen);/* Strip out CR if one is present, setting password won't work if it is present */ -strip_cr (setting->password); +strreplace (setting->password,'\n' ,'\0' );return count; }
@@ -432,13 +424,11 @@ static ssize_t new_password_store(struct kobject *kobj,if (!tlmi_priv.can_set_bios_password)return -EOPNOTSUPP ; - new_pwd =kstrdup (buf,GFP_KERNEL ); +/* Strip out CR if one is present, setting password won't work if it is present */ + new_pwd =kstrdup_and_replace (buf,'\n' ,'\0' ,GFP_KERNEL );if (!new_pwd)return -ENOMEM ; -/* Strip out CR if one is present, setting password won't work if it is present */ -strip_cr (new_pwd); -/* Use lock in case multiple WMI operations needed */ mutex_lock (&tlmi_mutex);
@@ -709,13 +699,11 @@ static ssize_t cert_to_password_store(struct kobject *kobj,if (!setting->signature || !setting->signature[0 ])return -EACCES ; - passwd =kstrdup (buf,GFP_KERNEL ); +/* Strip out CR if one is present */ + passwd =kstrdup_and_replace (buf,'\n' ,'\0' ,GFP_KERNEL );if (!passwd)return -ENOMEM ; -/* Strip out CR if one is present */ -strip_cr (passwd); -/* Format: 'Password,Signature' */ auth_str =kasprintf (GFP_KERNEL ,"%s,%s" , passwd, setting->signature);if (!auth_str) {
@@ -765,11 +753,10 @@ static ssize_t certificate_store(struct kobject *kobj,return ret ?: count; } - new_cert =kstrdup (buf,GFP_KERNEL ); +/* Strip out CR if one is present */ + new_cert =kstrdup_and_replace (buf,'\n' ,'\0' ,GFP_KERNEL );if (!new_cert)return -ENOMEM ; -/* Strip out CR if one is present */ -strip_cr (new_cert);if (setting->cert_installed) {/* Certificate is installed so this is an update */
@@ -817,13 +804,11 @@ static ssize_t signature_store(struct kobject *kobj,if (!tlmi_priv.certificate_support)return -EOPNOTSUPP ; - new_signature =kstrdup (buf,GFP_KERNEL ); +/* Strip out CR if one is present */ + new_signature =kstrdup_and_replace (buf,'\n' ,'\0' ,GFP_KERNEL );if (!new_signature)return -ENOMEM ; -/* Strip out CR if one is present */ -strip_cr (new_signature); -/* Free any previous signature */ kfree (setting->signature); setting->signature = new_signature;
@@ -846,13 +831,11 @@ static ssize_t save_signature_store(struct kobject *kobj,if (!tlmi_priv.certificate_support)return -EOPNOTSUPP ; - new_signature =kstrdup (buf,GFP_KERNEL ); +/* Strip out CR if one is present */ + new_signature =kstrdup_and_replace (buf,'\n' ,'\0' ,GFP_KERNEL );if (!new_signature)return -ENOMEM ; -/* Strip out CR if one is present */ -strip_cr (new_signature); -/* Free any previous signature */ kfree (setting->save_signature); setting->save_signature = new_signature;
@@ -981,13 +964,11 @@ static ssize_t current_value_store(struct kobject *kobj,if (!tlmi_priv.can_set_bios_settings)return -EOPNOTSUPP ; - new_setting =kstrdup (buf,GFP_KERNEL ); +/* Strip out CR if one is present */ + new_setting =kstrdup_and_replace (buf,'\n' ,'\0' ,GFP_KERNEL );if (!new_setting)return -ENOMEM ; -/* Strip out CR if one is present */ -strip_cr (new_setting); -/* Use lock in case multiple WMI operations needed */ mutex_lock (&tlmi_mutex);
@@ -1160,13 +1141,11 @@ static ssize_t debug_cmd_store(struct kobject *kobj, struct kobj_attribute *attrif (!tlmi_priv.can_debug_cmd)return -EOPNOTSUPP ; - new_setting =kstrdup (buf,GFP_KERNEL ); +/* Strip out CR if one is present */ + new_setting =kstrdup_and_replace (buf,'\n' ,'\0' ,GFP_KERNEL );if (!new_setting)return -ENOMEM ; -/* Strip out CR if one is present */ -strip_cr (new_setting); -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,
lib/string_helpers.c +2 -1
@@ -730,7 +730,8 @@ char *kstrdup_and_replace(const char *src, char old, char new, gfp_t gfp)if (!dst)return NULL ; -return strreplace (dst, old, new); +strreplace (dst, old, new); +return dst; }EXPORT_SYMBOL_GPL (kstrdup_and_replace);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 platform/x86: think-lmi: Use strreplace() to replace a character by nul
In reply to Sasha LevinFrom: Andy Shevchenko <[email protected]>
[ Upstream commit 6cb9c8637c672584d4915559001020237840acba ]
We can replace
p = strchrnul(str, '$OLD'); *p = '\0'; with strreplace(str, '$OLD', '\0');
that does the compatible modification without a need of the temporary variable.
Stable-dep-of: 54745d563114 ("platform/x86: think-lmi: Fix current password length check")
--- drivers/platform/x86/think-lmi.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/platform/x86/think-lmi.c +3 -6
@@ -909,7 +909,7 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *atstatic ssize_t current_value_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) {struct tlmi_attr_setting *setting =to_tlmi_attr_setting (kobj); -char *item, *value, *p; +char *item, *value;int ret; ret =tlmi_setting (setting->index, &item,LENOVO_BIOS_SETTING_GUID );
@@ -922,8 +922,7 @@ static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *a ret = -EINVAL ; else {/* On Workstations remove the Options part after the value */ - p =strchrnul (value,';' ); - *p ='\0' ; +strreplace (value,';' ,'\0' ); ret =sysfs_emit (buf,"%s\n" , value +1 ); }kfree (item);
@@ -1430,7 +1429,6 @@ static int tlmi_analyze(void)for (i =0 ; i <TLMI_SETTINGS_COUNT ; ++i) {struct tlmi_attr_setting *setting;char *item =NULL ; -char *p; tlmi_priv.setting[i] =NULL ; status =tlmi_setting (i, &item,LENOVO_BIOS_SETTING_GUID );
@@ -1447,8 +1445,7 @@ static int tlmi_analyze(void)strreplace (item,'/' ,'\\' );/* Remove the value part */ - p =strchrnul (item,',' ); - *p ='\0' ; +strreplace (item,',' ,'\0' );/* Create a setting entry */ setting =kzalloc (sizeof (*setting),GFP_KERNEL );
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 platform/x86: think-lmi: Fix current password length check
In reply to Sasha LevinFrom: Thorsten Blum <[email protected]>
[ Upstream commit 54745d563114b74f6fecebce68cd020d06c1772b ]
current_password_store() checks the password length before removing the trailing newline, which can reject valid passwords that are exactly ->maxlen bytes long.
It also passes ->maxlen to strscpy(), which truncates passwords without a newline.
Use strchrnul() to measure the password length up to the newline, then copy that many bytes and add a trailing NUL terminator using strscpy().
--- drivers/platform/x86/think-lmi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/platform/x86/think-lmi.c +3 -4
@@ -396,14 +396,13 @@ static ssize_t current_password_store(struct kobject *kobj,struct tlmi_pwd_setting *setting =to_tlmi_pwd_setting (kobj);size_t pwdlen; - pwdlen =strlen (buf); +/* Strip newline; setting password won't work if one is present. */ + pwdlen =strchrnul (buf,'\n' ) - buf;/* pwdlen == 0 is allowed to clear the password */ if (pwdlen && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen)))return -EINVAL ; -strscpy (setting->password, buf, setting->maxlen); -/* Strip out CR if one is present, setting password won't work if it is present */ -strreplace (setting->password,'\n' ,'\0' ); +strscpy (setting->password, buf, pwdlen +1 );return count; }
Signature · 1 line
2.53.0