Skip to contentSkip to conversation

platform/x86: Fix various issues inside Dell WMI drivers

PATCH In review Armin Wolf 2 participants 8 messages Jun 12 – Jul 2

Subsystems (4)
lore
Share & tools
lore

Armin Wolf

author maintainer
#0 lore raw

cover platform/x86: Fix various issues inside Dell WMI drivers

During the review of a previous patch series, Sashiko found multiple preexisting issues in multiple Dell WMI drivers. The first three patches aim to fix those issues, while the last patch is based on a suggestion of Ilpo himself.

All patches where tested on a Dell Inspiron 3505 and appear to work just fine.

Armin Wolf (4):
platform/x86: dell-privacy: Fix race condition platform/x86: dell-wmi-base: Fix resource leak on module load failure platform/x86: dell-wmi-base: Fix handling of ultra performance key platform/x86: dell-ddv: Use no_free_ptr() to simplify error handling

 drivers/platform/x86/dell/dell-wmi-base.c    | 19 ++++++++++++++---
 drivers/platform/x86/dell/dell-wmi-ddv.c     | 22 ++++++--------------
 drivers/platform/x86/dell/dell-wmi-privacy.c |  4 ++--
 3 files changed, 24 insertions(+), 21 deletions(-)
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 1/4 platform/x86: dell-privacy: Fix race condition

Accessing priv->features_present needs to happen with the list mutex being held, otherwise priv can be freed at any moment.

Fixes 8af9fa37b8a3 ("platform/x86: dell-privacy: Add support for Dell hardware privacy")
---
 drivers/platform/x86/dell/dell-wmi-privacy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/dell/dell-wmi-privacy.c +2 -2
index f9d275b2f900..366e5b8dc868 100644
@@ -92,11 +92,11 @@ bool dell_privacy_has_mic_mute(void)
 {
 	struct privacy_wmi_data *priv;
 
-	mutex_lock(&list_mutex);
+	guard(mutex)(&list_mutex);
+
 	priv = list_first_entry_or_null(&wmi_list,
 			struct privacy_wmi_data,
 			list);
-	mutex_unlock(&list_mutex);
 
 	return priv && (priv->features_present & BIT(DELL_PRIVACY_TYPE_AUDIO));
 }
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH 2/4 platform/x86: dell-wmi-base: Fix resource leak on module load failure

In reply to Armin Wolf

We need to properly clean up the SMBIOS request and the privacy driver when the module load fails.

Fixes 8af9fa37b8a3 ("platform/x86: dell-privacy: Add support for Dell hardware privacy")
---
 drivers/platform/x86/dell/dell-wmi-base.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/platform/x86/dell/dell-wmi-base.c +15 -2
index 997383ba1846..fd6a508cd902 100644
@@ -843,9 +843,22 @@ static int __init dell_wmi_init(void)
 
 	err = dell_privacy_register_driver();
 	if (err)
-		return err;
+		goto out_smbios;
 
-	return wmi_driver_register(&dell_wmi_driver);
+	err = wmi_driver_register(&dell_wmi_driver);
+	if (err)
+		goto out_privacy;
+
+	return 0;
+
+out_privacy:
+	dell_privacy_unregister_driver();
+
+out_smbios:
+	if (wmi_requires_smbios_request)
+		dell_wmi_events_set_enabled(false);
+
+	return err;
 }
 late_initcall(dell_wmi_init);
 
Signature · 1 line
2.39.5
author maintainer
#3 lore raw

PATCH 3/4 platform/x86: dell-wmi-base: Fix handling of ultra performance key

In reply to Armin Wolf

The commit message of commit 5fbd827eb9c2 ("platform/x86: dell-wmi: Recognise or support new switches") states that the ultra performance key contains additional data
after the type and code fields. The event data passed to
dell_wmi_process_key() is already parsed, so "buffer" already
starts after those two fields.

Use the correct index for accessing the first data field to avoid a potential buffer overread.

Fixes 5fbd827eb9c2 ("platform/x86: dell-wmi: Recognise or support new switches")
---
 drivers/platform/x86/dell/dell-wmi-base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/dell/dell-wmi-base.c +1 -1
index fd6a508cd902..38a6b3ae2f75 100644
@@ -456,7 +456,7 @@ static int dell_wmi_process_key(struct wmi_device *wdev, int type, int code, __l
 			key++;
 		used = 1;
 	} else if (type == 0x0012 && code == 0x000d && remaining > 0) {
-		value = (le16_to_cpu(buffer[2]) == 2);
+		value = (le16_to_cpu(buffer[0]) == 2);
 		used = 1;
 	}
 
Signature · 1 line
2.39.5
author maintainer
#4 lore raw

PATCH 4/4 platform/x86: dell-ddv: Use no_free_ptr() to simplify error handling

In reply to Armin Wolf

Use no_free_ptr() inside dell_wmi_ddv_query_buffer() in order to be able to use __free() with the result of the WMI call.

---
 drivers/platform/x86/dell/dell-wmi-ddv.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)
drivers/platform/x86/dell/dell-wmi-ddv.c +6 -16
index 736d9b1fdcfb..f8903ced461b 100644
@@ -196,40 +196,30 @@ static int dell_wmi_ddv_query_integer(struct wmi_device *wdev, enum dell_ddv_met
 static int dell_wmi_ddv_query_buffer(struct wmi_device *wdev, enum dell_ddv_method method,
 				     u32 arg, struct dell_wmi_buffer **result)
 {
-	struct dell_wmi_buffer *buffer;
 	struct wmi_buffer output;
 	size_t buffer_size;
 	int ret;
 
-	ret = dell_wmi_ddv_query(wdev, method, arg, &output, sizeof(*buffer));
+	ret = dell_wmi_ddv_query(wdev, method, arg, &output, sizeof(struct dell_wmi_buffer));
 	if (ret < 0)
 		return ret;
 
-	buffer = output.data;
-	if (!le32_to_cpu(buffer->raw_size)) {
-		ret = -ENODATA;
+	struct dell_wmi_buffer *buffer __free(kfree) = output.data;
 
-		goto err_free;
-	}
+	if (!le32_to_cpu(buffer->raw_size))
+		return -ENODATA;
 
 	buffer_size = struct_size(buffer, raw_data, le32_to_cpu(buffer->raw_size));
 	if (buffer_size > output.length) {
 		dev_warn(&wdev->dev,
 			 FW_WARN "Dell WMI buffer size (%zu) exceeds WMI buffer size (%zu)\n",
 			 buffer_size, output.length);
-		ret = -EMSGSIZE;
-
-		goto err_free;
+		return -EMSGSIZE;
 	}
 
-	*result = buffer;
+	*result = no_free_ptr(buffer);
 
 	return 0;
-
-err_free:
-	kfree(output.data);
-
-	return ret;
 }
 
 static ssize_t dell_wmi_ddv_query_string(struct wmi_device *wdev, enum dell_ddv_method method,
Signature · 1 line
2.39.5
author maintainer
#5 lore raw
In reply to Armin Wolf

Am 12.06.26 um 19:34 schrieb Armin Wolf:

Quoted 7 lines

During the review of a previous patch series, Sashiko found multiple preexisting issues in multiple Dell WMI drivers. The first three patches aim to fix those issues, while the last patch is based on a suggestion of Ilpo himself.

All patches where tested on a Dell Inspiron 3505 and appear to work just fine.

Gentle ping for the series.

Quoted 11 lines

Armin Wolf (4):
platform/x86: dell-privacy: Fix race condition platform/x86: dell-wmi-base: Fix resource leak on module load failure platform/x86: dell-wmi-base: Fix handling of ultra performance key platform/x86: dell-ddv: Use no_free_ptr() to simplify error handling

  drivers/platform/x86/dell/dell-wmi-base.c    | 19 ++++++++++++++---
  drivers/platform/x86/dell/dell-wmi-ddv.c     | 22 ++++++--------------
  drivers/platform/x86/dell/dell-wmi-privacy.c |  4 ++--
  3 files changed, 24 insertions(+), 21 deletions(-)
maintainer
#6 lore raw
In reply to Armin Wolf
Quoted 9 lines · Armin Wolf

During the review of a previous patch series, Sashiko found multiple preexisting issues in multiple Dell WMI drivers. The first three patches aim to fix those issues, while the last patch is based on a suggestion of Ilpo himself.

All patches where tested on a Dell Inspiron 3505 and appear to work just fine.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent or clearly a regression fix.

The list of commits applied:
[1/4] platform/x86: dell-privacy: Fix race condition

      commit: a3ec96c8b7bc3a643779ddd7daa8a6f482e4917c
[2/4] platform/x86: dell-wmi-base: Fix resource leak on module load failure
      commit: f58553cda9aa84e1598a640870b137350cc24027
[3/4] platform/x86: dell-wmi-base: Fix handling of ultra performance key
      commit: cfe467c730f658e080ffc57bef36f0260333c5aa
[4/4] platform/x86: dell-ddv: Use no_free_ptr() to simplify error handling
      commit: 74850eb0012b94c77366b0476e4f3b1db349a4d2

--
i.

author maintainer
#7 lore raw

Am 01.07.26 um 13:30 schrieb Ilpo Järvinen:

Quoted 11 lines · Armin Wolf
Quoted 10 lines

During the review of a previous patch series, Sashiko found multiple preexisting issues in multiple Dell WMI drivers. The first three patches aim to fix those issues, while the last patch is based on a suggestion of Ilpo himself.

All patches where tested on a Dell Inspiron 3505 and appear to work just fine.

[...]

Quoted 8 lines

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent or clearly a regression fix.

Thank you :)

Quoted 14 lines

The list of commits applied:
[1/4] platform/x86: dell-privacy: Fix race condition

       commit: a3ec96c8b7bc3a643779ddd7daa8a6f482e4917c
[2/4] platform/x86: dell-wmi-base: Fix resource leak on module load failure
       commit: f58553cda9aa84e1598a640870b137350cc24027
[3/4] platform/x86: dell-wmi-base: Fix handling of ultra performance key
       commit: cfe467c730f658e080ffc57bef36f0260333c5aa
[4/4] platform/x86: dell-ddv: Use no_free_ptr() to simplify error handling
       commit: 74850eb0012b94c77366b0476e4f3b1db349a4d2

--
i.