All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/x86: think-lmi: Fix reference leak
@ 2023-09-23 20:41 Armin Wolf
  2023-09-25 12:00 ` Ilpo Järvinen
  2023-09-25 14:00 ` [External] " Mark Pearson
  0 siblings, 2 replies; 4+ messages in thread
From: Armin Wolf @ 2023-09-23 20:41 UTC (permalink / raw)
  To: markpearson
  Cc: hdegoede, markgross, ilpo.jarvinen, platform-driver-x86, linux-kernel

If a duplicate attribute is found using kset_find_obj(), a reference
to that attribute is returned which needs to be disposed accordingly
using kobject_put(). Move the setting name validation into a separate
function to allow for this change without having to duplicate the
cleanup code for this setting.
As a side note, a very similar bug was fixed in
commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak"),
so it seems that the bug was copied from that driver.

Compile-tested only.

Fixes: 1bcad8e510b2 ("platform/x86: think-lmi: Fix issues with duplicate attributes")
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/platform/x86/think-lmi.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index 4be6f28d4600..3a396b763c49 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -1344,6 +1344,24 @@ static void tlmi_release_attr(void)
 	kset_unregister(tlmi_priv.authentication_kset);
 }

+static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
+{
+	struct kobject *duplicate;
+
+	if (!strcmp(name, "Reserved"))
+		return -EINVAL;
+
+	duplicate = kset_find_obj(attribute_kset, name);
+	if (duplicate) {
+		pr_debug("Duplicate attribute name found - %s\n", name);
+		/* kset_find_obj() returns a reference */
+		kobject_put(duplicate);
+		return -EBUSY;
+	}
+
+	return 0;
+}
+
 static int tlmi_sysfs_init(void)
 {
 	int i, ret;
@@ -1372,10 +1390,8 @@ static int tlmi_sysfs_init(void)
 			continue;

 		/* check for duplicate or reserved values */
-		if (kset_find_obj(tlmi_priv.attribute_kset, tlmi_priv.setting[i]->display_name) ||
-		    !strcmp(tlmi_priv.setting[i]->display_name, "Reserved")) {
-			pr_debug("duplicate or reserved attribute name found - %s\n",
-				tlmi_priv.setting[i]->display_name);
+		if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
+					       tlmi_priv.setting[i]->display_name) < 0) {
 			kfree(tlmi_priv.setting[i]->possible_values);
 			kfree(tlmi_priv.setting[i]);
 			tlmi_priv.setting[i] = NULL;
--
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] platform/x86: think-lmi: Fix reference leak
  2023-09-23 20:41 [PATCH] platform/x86: think-lmi: Fix reference leak Armin Wolf
@ 2023-09-25 12:00 ` Ilpo Järvinen
  2023-09-25 14:00 ` [External] " Mark Pearson
  1 sibling, 0 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2023-09-25 12:00 UTC (permalink / raw)
  To: Armin Wolf
  Cc: markpearson, Hans de Goede, markgross, platform-driver-x86, LKML

[-- Attachment #1: Type: text/plain, Size: 2412 bytes --]

On Sat, 23 Sep 2023, Armin Wolf wrote:

> If a duplicate attribute is found using kset_find_obj(), a reference
> to that attribute is returned which needs to be disposed accordingly
> using kobject_put(). Move the setting name validation into a separate
> function to allow for this change without having to duplicate the
> cleanup code for this setting.
> As a side note, a very similar bug was fixed in
> commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak"),
> so it seems that the bug was copied from that driver.
> 
> Compile-tested only.
> 
> Fixes: 1bcad8e510b2 ("platform/x86: think-lmi: Fix issues with duplicate attributes")
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
>  drivers/platform/x86/think-lmi.c | 24 ++++++++++++++++++++----
>  1 file changed, 20 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
> index 4be6f28d4600..3a396b763c49 100644
> --- a/drivers/platform/x86/think-lmi.c
> +++ b/drivers/platform/x86/think-lmi.c
> @@ -1344,6 +1344,24 @@ static void tlmi_release_attr(void)
>  	kset_unregister(tlmi_priv.authentication_kset);
>  }
> 
> +static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
> +{
> +	struct kobject *duplicate;
> +
> +	if (!strcmp(name, "Reserved"))
> +		return -EINVAL;
> +
> +	duplicate = kset_find_obj(attribute_kset, name);
> +	if (duplicate) {
> +		pr_debug("Duplicate attribute name found - %s\n", name);
> +		/* kset_find_obj() returns a reference */
> +		kobject_put(duplicate);
> +		return -EBUSY;
> +	}
> +
> +	return 0;
> +}
> +
>  static int tlmi_sysfs_init(void)
>  {
>  	int i, ret;
> @@ -1372,10 +1390,8 @@ static int tlmi_sysfs_init(void)
>  			continue;
> 
>  		/* check for duplicate or reserved values */
> -		if (kset_find_obj(tlmi_priv.attribute_kset, tlmi_priv.setting[i]->display_name) ||
> -		    !strcmp(tlmi_priv.setting[i]->display_name, "Reserved")) {
> -			pr_debug("duplicate or reserved attribute name found - %s\n",
> -				tlmi_priv.setting[i]->display_name);
> +		if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
> +					       tlmi_priv.setting[i]->display_name) < 0) {
>  			kfree(tlmi_priv.setting[i]->possible_values);
>  			kfree(tlmi_priv.setting[i]);
>  			tlmi_priv.setting[i] = NULL;

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

There seem to be two more of these in hp-bioscfg.

-- 
 i.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [External] [PATCH] platform/x86: think-lmi: Fix reference leak
  2023-09-23 20:41 [PATCH] platform/x86: think-lmi: Fix reference leak Armin Wolf
  2023-09-25 12:00 ` Ilpo Järvinen
@ 2023-09-25 14:00 ` Mark Pearson
  2023-09-25 14:26   ` Armin Wolf
  1 sibling, 1 reply; 4+ messages in thread
From: Mark Pearson @ 2023-09-25 14:00 UTC (permalink / raw)
  To: Armin Wolf
  Cc: hdegoede, markgross, ilpo.jarvinen, platform-driver-x86, linux-kernel

Thanks Armin,

On 9/23/23 16:41, Armin Wolf wrote:
> If a duplicate attribute is found using kset_find_obj(), a reference
> to that attribute is returned which needs to be disposed accordingly
> using kobject_put(). Move the setting name validation into a separate
> function to allow for this change without having to duplicate the
> cleanup code for this setting.
> As a side note, a very similar bug was fixed in
> commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak"),
> so it seems that the bug was copied from that driver.
>
> Compile-tested only.
>
> Fixes: 1bcad8e510b2 ("platform/x86: think-lmi: Fix issues with duplicate attributes")
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
>   drivers/platform/x86/think-lmi.c | 24 ++++++++++++++++++++----
>   1 file changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
> index 4be6f28d4600..3a396b763c49 100644
> --- a/drivers/platform/x86/think-lmi.c
> +++ b/drivers/platform/x86/think-lmi.c
> @@ -1344,6 +1344,24 @@ static void tlmi_release_attr(void)
>   	kset_unregister(tlmi_priv.authentication_kset);
>   }
>
> +static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
> +{
> +	struct kobject *duplicate;
> +
> +	if (!strcmp(name, "Reserved"))
> +		return -EINVAL;
> +
> +	duplicate = kset_find_obj(attribute_kset, name);
> +	if (duplicate) {
> +		pr_debug("Duplicate attribute name found - %s\n", name);
> +		/* kset_find_obj() returns a reference */
> +		kobject_put(duplicate);
> +		return -EBUSY;
> +	}
> +
> +	return 0;
> +}
> +
>   static int tlmi_sysfs_init(void)
>   {
>   	int i, ret;
> @@ -1372,10 +1390,8 @@ static int tlmi_sysfs_init(void)
>   			continue;
>
>   		/* check for duplicate or reserved values */
> -		if (kset_find_obj(tlmi_priv.attribute_kset, tlmi_priv.setting[i]->display_name) ||
> -		    !strcmp(tlmi_priv.setting[i]->display_name, "Reserved")) {
> -			pr_debug("duplicate or reserved attribute name found - %s\n",
> -				tlmi_priv.setting[i]->display_name);
> +		if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
> +					       tlmi_priv.setting[i]->display_name) < 0) {
>   			kfree(tlmi_priv.setting[i]->possible_values);
>   			kfree(tlmi_priv.setting[i]);
>   			tlmi_priv.setting[i] = NULL;
> --
> 2.39.2
>

Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>

Do you have any reports of our platforms where these are seen? If so I'd like to get it fixed in FW too (and I can get it tested on HW if that helps)

Mark


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [External] [PATCH] platform/x86: think-lmi: Fix reference leak
  2023-09-25 14:00 ` [External] " Mark Pearson
@ 2023-09-25 14:26   ` Armin Wolf
  0 siblings, 0 replies; 4+ messages in thread
From: Armin Wolf @ 2023-09-25 14:26 UTC (permalink / raw)
  To: Mark Pearson
  Cc: hdegoede, markgross, ilpo.jarvinen, platform-driver-x86, linux-kernel

Am 25.09.23 um 16:00 schrieb Mark Pearson:

> Thanks Armin,
>
> On 9/23/23 16:41, Armin Wolf wrote:
>> If a duplicate attribute is found using kset_find_obj(), a reference
>> to that attribute is returned which needs to be disposed accordingly
>> using kobject_put(). Move the setting name validation into a separate
>> function to allow for this change without having to duplicate the
>> cleanup code for this setting.
>> As a side note, a very similar bug was fixed in
>> commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak"),
>> so it seems that the bug was copied from that driver.
>>
>> Compile-tested only.
>>
>> Fixes: 1bcad8e510b2 ("platform/x86: think-lmi: Fix issues with
>> duplicate attributes")
>> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
>> ---
>>   drivers/platform/x86/think-lmi.c | 24 ++++++++++++++++++++----
>>   1 file changed, 20 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/platform/x86/think-lmi.c
>> b/drivers/platform/x86/think-lmi.c
>> index 4be6f28d4600..3a396b763c49 100644
>> --- a/drivers/platform/x86/think-lmi.c
>> +++ b/drivers/platform/x86/think-lmi.c
>> @@ -1344,6 +1344,24 @@ static void tlmi_release_attr(void)
>>       kset_unregister(tlmi_priv.authentication_kset);
>>   }
>>
>> +static int tlmi_validate_setting_name(struct kset *attribute_kset,
>> char *name)
>> +{
>> +    struct kobject *duplicate;
>> +
>> +    if (!strcmp(name, "Reserved"))
>> +        return -EINVAL;
>> +
>> +    duplicate = kset_find_obj(attribute_kset, name);
>> +    if (duplicate) {
>> +        pr_debug("Duplicate attribute name found - %s\n", name);
>> +        /* kset_find_obj() returns a reference */
>> +        kobject_put(duplicate);
>> +        return -EBUSY;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>>   static int tlmi_sysfs_init(void)
>>   {
>>       int i, ret;
>> @@ -1372,10 +1390,8 @@ static int tlmi_sysfs_init(void)
>>               continue;
>>
>>           /* check for duplicate or reserved values */
>> -        if (kset_find_obj(tlmi_priv.attribute_kset,
>> tlmi_priv.setting[i]->display_name) ||
>> -            !strcmp(tlmi_priv.setting[i]->display_name, "Reserved")) {
>> -            pr_debug("duplicate or reserved attribute name found -
>> %s\n",
>> -                tlmi_priv.setting[i]->display_name);
>> +        if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
>> + tlmi_priv.setting[i]->display_name) < 0) {
>>               kfree(tlmi_priv.setting[i]->possible_values);
>>               kfree(tlmi_priv.setting[i]);
>>               tlmi_priv.setting[i] = NULL;
>> --
>> 2.39.2
>>
>
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>
> Do you have any reports of our platforms where these are seen? If so
> I'd like to get it fixed in FW too (and I can get it tested on HW if
> that helps)
>
> Mark
>
No, i do not have any reports regarding this issue. I stumbled upon this bug by chance, after fixing a similar bug in dell-wmi-sysman.
I suspect that the bug was copied from there to the other drivers, like think-lmi and hp-bioscfg.

Armin Wolf


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-25 14:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-23 20:41 [PATCH] platform/x86: think-lmi: Fix reference leak Armin Wolf
2023-09-25 12:00 ` Ilpo Järvinen
2023-09-25 14:00 ` [External] " Mark Pearson
2023-09-25 14:26   ` Armin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.