public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Armin Wolf <W_Armin@gmx.de>
Cc: markpearson@lenovo.com, Hans de Goede <hdegoede@redhat.com>,
	markgross@kernel.org, platform-driver-x86@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] platform/x86: think-lmi: Fix reference leak
Date: Mon, 25 Sep 2023 15:00:10 +0300 (EEST)	[thread overview]
Message-ID: <7e68e66f-40a2-1ac7-416b-bf63bafa6fe7@linux.intel.com> (raw)
In-Reply-To: <20230923204154.86815-1-W_Armin@gmx.de>

[-- 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.

  reply	other threads:[~2023-09-25 12:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-23 20:41 [PATCH] platform/x86: think-lmi: Fix reference leak Armin Wolf
2023-09-25 12:00 ` Ilpo Järvinen [this message]
2023-09-25 14:00 ` [External] " Mark Pearson
2023-09-25 14:26   ` Armin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7e68e66f-40a2-1ac7-416b-bf63bafa6fe7@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=W_Armin@gmx.de \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=markpearson@lenovo.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox