From: Bartu Alev <bartualev@gmail.com>
To: "Corentin Chary" <corentin.chary@gmail.com>,
"Luke D. Jones" <luke@ljones.dev>,
"Denis Benato" <denis.benato@linux.dev>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org, Bartu Alev <bartualev@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf()
Date: Wed, 02 Dec 2026 02:31:42 +0300 [thread overview]
Message-ID: <20261202-asus-wmi-eval-buf-v1-1-640c12d437dc@gmail.com> (raw)
In-Reply-To: <20261202-asus-wmi-eval-buf-v1-0-640c12d437dc@gmail.com>
acpi_evaluate_object() reports AE_OK and leaves output.pointer NULL when
the evaluated WMI method returns no object at all, but
asus_wmi_evaluate_method_buf() dereferenced the pointer in
switch (obj->type) unconditionally, causing an oops during probe via
asus_wmi_custom_fan_curve_init() -> fan_curve_check_present() and on
writes to pwmN_enable via fan_curve_enable_store().
The ACPI_TYPE_INTEGER case also stored the firmware's u32 reply in the
signed int err. A value with bit 31 set therefore aliased a negative
errno (0xffffffff became -EPERM) and any other value leaked out as a
positive number: a DSTS reply carrying only ASUS_WMI_DSTS_UNKNOWN_BIT
(0x2), seen on ASUS hardware for unsupported device IDs, was returned as
+2 through fan_curve_enable_store() on writes of 2 and 3 to pwmN_enable,
which sysfs treats as a successful write. fan_curve_check_present()
swallows the error at probe, so only the NULL dereference is fatal
there.
Treat a missing object as -ENODATA, decode integer replies via u32 and
map ASUS_WMI_UNSUPPORTED_METHOD and 0xffffffff to -ENODEV, matching
asus_wmi_get_devstate(), and any other integer to -ENODATA. A survey of
102 ASUS DSDTs and the SMM path of a recent model found unsupported
methods answering 0xfffffffe or 0 rather than no object or 0xffffffff,
so both defects are latent rather than observed in the field.
Fixes: 0f0ac158d28ff ("platform/x86: asus-wmi: Add support for custom fan curves")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/228df241-da5e-49cb-b29f-6b9158557f55@gmail.com/
Signed-off-by: Bartu Alev <bartualev@gmail.com>
---
drivers/platform/asus/asus-wmi.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c
index 552080ff5be25..4f74fdfd7a0c2 100644
--- a/drivers/platform/asus/asus-wmi.c
+++ b/drivers/platform/asus/asus-wmi.c
@@ -478,6 +478,7 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
acpi_status status;
union acpi_object *obj;
+ u32 retval;
int err = 0;
status = asus_wmi_evaluate_method_locked(method_id, &input, &output);
@@ -492,6 +493,15 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
obj = (union acpi_object *)output.pointer;
+ /*
+ * acpi_evaluate_object() reports AE_OK with a NULL buffer when the
+ * method returned no object at all.
+ */
+ if (!obj) {
+ err = -ENODATA;
+ goto out_free;
+ }
+
switch (obj->type) {
case ACPI_TYPE_BUFFER:
if (obj->buffer.length > size) {
@@ -506,15 +516,16 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
memcpy(ret_buffer, obj->buffer.pointer, obj->buffer.length);
break;
case ACPI_TYPE_INTEGER:
- err = (u32)obj->integer.value;
-
- if (err == ASUS_WMI_UNSUPPORTED_METHOD)
- err = -ENODEV;
+ retval = (u32)obj->integer.value;
/*
- * At least one method returns a 0 with no buffer if no arg
- * is provided, such as ASUS_WMI_DEVID_CPU_FAN_CURVE
+ * ASUS_WMI_UNSUPPORTED_METHOD (0xfffffffe) and 0xffffffff
+ * mean the device or method is not implemented. Any other
+ * integer, such as the 0 some methods return when called
+ * without an argument, is not usable data either.
*/
- if (err == 0)
+ if (retval == ASUS_WMI_UNSUPPORTED_METHOD || retval == ~0U)
+ err = -ENODEV;
+ else
err = -ENODATA;
break;
default:
@@ -522,6 +533,7 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
break;
}
+out_free:
kfree(obj);
if (err) {
--
2.56.1
next prev parent reply other threads:[~2026-12-01 23:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 23:31 [PATCH 0/3] platform/asus: asus-wmi: harden asus_wmi_evaluate_method_buf() Bartu Alev
2026-12-01 23:31 ` Bartu Alev [this message]
2026-12-01 23:31 ` [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) in asus_wmi_evaluate_method_buf() Bartu Alev
2026-12-01 23:31 ` [PATCH 3/3] platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf() Bartu Alev
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=20261202-asus-wmi-eval-buf-v1-1-640c12d437dc@gmail.com \
--to=bartualev@gmail.com \
--cc=corentin.chary@gmail.com \
--cc=denis.benato@linux.dev \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luke@ljones.dev \
--cc=platform-driver-x86@vger.kernel.org \
--cc=stable@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
all inboxes | Powered by JetHome®