* [PATCH v4 0/2] platform/x86: Fix reference leaks
@ 2023-09-25 14:28 Armin Wolf
2023-09-25 14:28 ` [PATCH v4 1/2] platform/x86: think-lmi: Fix reference leak Armin Wolf
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Armin Wolf @ 2023-09-25 14:28 UTC (permalink / raw)
To: markpearson, jorge.lopez2
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(). This issue likely first appeared inside the
dell-wmi-sysman driver, see
commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak").
However, it also seems that the bug was copied from this driver into
the think-lmi and hp-bioscfg drivers. Maybe a more abstract
fw_attr_class could prevent such issues in the future by abstracting
away the kobject handling?
Armin Wolf (2):
platform/x86: think-lmi: Fix reference leak
platform/x86: hp-bioscfg: Fix reference leak
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 14 ++++++++----
drivers/platform/x86/think-lmi.c | 24 ++++++++++++++++----
2 files changed, 30 insertions(+), 8 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/2] platform/x86: think-lmi: Fix reference leak
2023-09-25 14:28 [PATCH v4 0/2] platform/x86: Fix reference leaks Armin Wolf
@ 2023-09-25 14:28 ` Armin Wolf
2023-09-25 14:28 ` [PATCH v4 2/2] platform/x86: hp-bioscfg: " Armin Wolf
2023-10-04 9:55 ` [PATCH v4 0/2] platform/x86: Fix reference leaks Hans de Goede
2 siblings, 0 replies; 5+ messages in thread
From: Armin Wolf @ 2023-09-25 14:28 UTC (permalink / raw)
To: markpearson, jorge.lopez2
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")
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
Changes in v4:
- add another Reviewed-by
Changes in v3:
- add Reviewed-by
Changes in v2:
- no changes
---
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] 5+ messages in thread
* [PATCH v4 2/2] platform/x86: hp-bioscfg: Fix reference leak
2023-09-25 14:28 [PATCH v4 0/2] platform/x86: Fix reference leaks Armin Wolf
2023-09-25 14:28 ` [PATCH v4 1/2] platform/x86: think-lmi: Fix reference leak Armin Wolf
@ 2023-09-25 14:28 ` Armin Wolf
2023-09-25 18:50 ` Lopez, Jorge A (Security)
2023-10-04 9:55 ` [PATCH v4 0/2] platform/x86: Fix reference leaks Hans de Goede
2 siblings, 1 reply; 5+ messages in thread
From: Armin Wolf @ 2023-09-25 14:28 UTC (permalink / raw)
To: markpearson, jorge.lopez2
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(). Use kobject_put() to dispose the duplicate
attribute in such a case.
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: a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg")
Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
Chnages in v4:
- fix missing whitespace
- add Reviewed-by
Changes in v3:
- no changes
Changes in v2:
- add patch
---
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
index 8c4f9e12f018..5798b49ddaba 100644
--- a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
+++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
@@ -659,7 +659,7 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type,
const char *guid, int min_elements,
int instance_id)
{
- struct kobject *attr_name_kobj;
+ struct kobject *attr_name_kobj, *duplicate;
union acpi_object *elements;
struct kset *temp_kset;
@@ -704,8 +704,11 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type,
}
/* All duplicate attributes found are ignored */
- if (kset_find_obj(temp_kset, str_value)) {
+ duplicate = kset_find_obj(temp_kset, str_value);
+ if (duplicate) {
pr_debug("Duplicate attribute name found - %s\n", str_value);
+ /* kset_find_obj() returns a reference */
+ kobject_put(duplicate);
goto pack_attr_exit;
}
@@ -768,7 +771,7 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type,
const char *guid, int min_elements,
int instance_id)
{
- struct kobject *attr_name_kobj;
+ struct kobject *attr_name_kobj, *duplicate;
struct kset *temp_kset;
char str[MAX_BUFF_SIZE];
@@ -794,8 +797,11 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type,
temp_kset = bioscfg_drv.main_dir_kset;
/* All duplicate attributes found are ignored */
- if (kset_find_obj(temp_kset, str)) {
+ duplicate = kset_find_obj(temp_kset, str);
+ if (duplicate) {
pr_debug("Duplicate attribute name found - %s\n", str);
+ /* kset_find_obj() returns a reference */
+ kobject_put(duplicate);
goto buff_attr_exit;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH v4 2/2] platform/x86: hp-bioscfg: Fix reference leak
2023-09-25 14:28 ` [PATCH v4 2/2] platform/x86: hp-bioscfg: " Armin Wolf
@ 2023-09-25 18:50 ` Lopez, Jorge A (Security)
0 siblings, 0 replies; 5+ messages in thread
From: Lopez, Jorge A (Security) @ 2023-09-25 18:50 UTC (permalink / raw)
To: Armin Wolf, markpearson
Cc: hdegoede, markgross, ilpo.jarvinen, platform-driver-x86, linux-kernel
Reviewed-by: Jorge Lopez <jorge.lopez2@hp.com>
> -----Original Message-----
> From: Armin Wolf <W_Armin@gmx.de>
> Sent: Monday, September 25, 2023 9:28 AM
> To: markpearson@lenovo.com; Lopez, Jorge A (Security)
> <jorge.lopez2@hp.com>
> Cc: hdegoede@redhat.com; markgross@kernel.org;
> ilpo.jarvinen@linux.intel.com; platform-driver-x86@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: [PATCH v4 2/2] platform/x86: hp-bioscfg: Fix reference leak
>
> CAUTION: External Email
>
> 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().
> Use kobject_put() to dispose the duplicate attribute in such a case.
> 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: a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg")
> Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
> Chnages in v4:
> - fix missing whitespace
> - add Reviewed-by
> Changes in v3:
> - no changes
> Changes in v2:
> - add patch
> ---
> drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> index 8c4f9e12f018..5798b49ddaba 100644
> --- a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> @@ -659,7 +659,7 @@ static int hp_init_bios_package_attribute(enum
> hp_wmi_data_type attr_type,
> const char *guid, int min_elements,
> int instance_id) {
> - struct kobject *attr_name_kobj;
> + struct kobject *attr_name_kobj, *duplicate;
> union acpi_object *elements;
> struct kset *temp_kset;
>
> @@ -704,8 +704,11 @@ static int hp_init_bios_package_attribute(enum
> hp_wmi_data_type attr_type,
> }
>
> /* All duplicate attributes found are ignored */
> - if (kset_find_obj(temp_kset, str_value)) {
> + duplicate = kset_find_obj(temp_kset, str_value);
> + if (duplicate) {
> pr_debug("Duplicate attribute name found - %s\n", str_value);
> + /* kset_find_obj() returns a reference */
> + kobject_put(duplicate);
> goto pack_attr_exit;
> }
>
> @@ -768,7 +771,7 @@ static int hp_init_bios_buffer_attribute(enum
> hp_wmi_data_type attr_type,
> const char *guid, int min_elements,
> int instance_id) {
> - struct kobject *attr_name_kobj;
> + struct kobject *attr_name_kobj, *duplicate;
> struct kset *temp_kset;
> char str[MAX_BUFF_SIZE];
>
> @@ -794,8 +797,11 @@ static int hp_init_bios_buffer_attribute(enum
> hp_wmi_data_type attr_type,
> temp_kset = bioscfg_drv.main_dir_kset;
>
> /* All duplicate attributes found are ignored */
> - if (kset_find_obj(temp_kset, str)) {
> + duplicate = kset_find_obj(temp_kset, str);
> + if (duplicate) {
> pr_debug("Duplicate attribute name found - %s\n", str);
> + /* kset_find_obj() returns a reference */
> + kobject_put(duplicate);
> goto buff_attr_exit;
> }
>
> --
> 2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 0/2] platform/x86: Fix reference leaks
2023-09-25 14:28 [PATCH v4 0/2] platform/x86: Fix reference leaks Armin Wolf
2023-09-25 14:28 ` [PATCH v4 1/2] platform/x86: think-lmi: Fix reference leak Armin Wolf
2023-09-25 14:28 ` [PATCH v4 2/2] platform/x86: hp-bioscfg: " Armin Wolf
@ 2023-10-04 9:55 ` Hans de Goede
2 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2023-10-04 9:55 UTC (permalink / raw)
To: Armin Wolf, markpearson, jorge.lopez2
Cc: markgross, ilpo.jarvinen, platform-driver-x86, linux-kernel
Hi,
On 9/25/23 16:28, 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(). This issue likely first appeared inside the
> dell-wmi-sysman driver, see
> commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak").
> However, it also seems that the bug was copied from this driver into
> the think-lmi and hp-bioscfg drivers. Maybe a more abstract
> fw_attr_class could prevent such issues in the future by abstracting
> away the kobject handling?
>
> Armin Wolf (2):
> platform/x86: think-lmi: Fix reference leak
> platform/x86: hp-bioscfg: Fix reference leak
Thank you for your patch/series, I've applied this patch
(series) to the pdx86 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 the pdx86 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
> drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 14 ++++++++----
> drivers/platform/x86/think-lmi.c | 24 ++++++++++++++++----
> 2 files changed, 30 insertions(+), 8 deletions(-)
>
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-04 9:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-25 14:28 [PATCH v4 0/2] platform/x86: Fix reference leaks Armin Wolf
2023-09-25 14:28 ` [PATCH v4 1/2] platform/x86: think-lmi: Fix reference leak Armin Wolf
2023-09-25 14:28 ` [PATCH v4 2/2] platform/x86: hp-bioscfg: " Armin Wolf
2023-09-25 18:50 ` Lopez, Jorge A (Security)
2023-10-04 9:55 ` [PATCH v4 0/2] platform/x86: Fix reference leaks Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).