From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.142 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179213; b=gqxq/qpDsXBRwn6GOpWOMGrC2f2qGohHmNHLSUM8uVHjbx09dcLSR4aQDLRkpEenfIgZ Q398JKLb+a05w56WplzxTtgeuEhw/US34Tr5cg46QP+uStLvBbELOcVoqCOLZdBQVJhvP nzdieEmWf9B3d8PZPYGtrsAcXG6lppvJ05QAg/iIH5VCIzt7ylmXvLS9pDfMDCczu2rRx NtPF5pe53x/t91gi/fso5/IdDaNLgf5G0oiRxM0p9V8UdW371pQjBVA0LOGKx4AmNY6Pc 4iytTXAkXPdChak/A9DNNbnIGsC5ToMSK5SQKe79QwzTw47tASVUfIZHszaWkrRHrMQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179213; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=MxmCwdVjh0D6lgfz0UFz/aotWsmNx7B4zfUxb2G85E0=; b=Se8hWGgY8OlG8qDeMO8NpFtcAKRG1z27jjNcVBrcAvVFZr+lK8Xf7YBKP1mkig+LS0OK IMGmP5e81Ejj4cktfSHVHhIwL4tezARQAIwSsx3O4tBw+/zni8WVP5HHNhJcmx0g1Rl4o sYtsf9KpZ+shu2LASu2Q8pjoi+x9w8bLKH/RVlO8r8IJIAHRTf2lwotBpjkxJ1Z6xi1zV 8TwL/6J25WfqpFnFkwTEC7ACFqnj6ne6YNukT3L54/Dm2qEIovdiaQaahdCffqaSteYyj gwfJJ6nJvgaehGAX1ioZhOwyIiH4sxeTmcK0NLCKFMQ8rphZrab35h+1l8/CPn/w0GA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=btfT+rst; arc=none smtp.remote-ip=95.215.58.142 Received: from mta1.migadu.com (out-142.mta1.migadu.com [95.215.58.142]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36C96606A6A8 for ; Wed, 2 Dec 2026 02:40:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 36C96606A6A8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=btfT+rst X-Envelope-To: platform-driver-x86@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=zKU9CQQVN3T7IMET2xDluMn9DO+v3uu9XN2/gUoQCzs=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796179210; v=1; x=1796784010; b=btfT+rstZ/Uppw5uhAwYMozNV2z58UB3dQIa588EVaMoO9QuFYnJlqgRTmJtyiReZ8q57q78 UfHkUGQgNnPEv/T41V/HMBlcJr3PxAm6Dcy8lz/Dh7kqDdT+KE9dbjIP2uzdIfc6SToPUEJPVrd buFbiYZ1UqW19z6+kUpOyWDg= X-Envelope-To: platform-driver-x86@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 0398d00fc27f573a; Wed, 02 Dec 2026 02:40:09 +0000 X-Mizu-Trace-ID: 0398d00fc27f573a X-Migadu-Flow: FLOW_OUT Message-ID: <37360523-462d-42f0-98e0-cf45d4646398@linux.dev> Date: Wed, 2 Dec 2026 03:40:08 +0100 X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf() To: Bartu Alev , Corentin Chary , "Luke D. Jones" , Hans de Goede , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261202-asus-wmi-eval-buf-v1-0-640c12d437dc@gmail.com> <20261202-asus-wmi-eval-buf-v1-1-640c12d437dc@gmail.com> Content-Language: en-US From: Denis Benato In-Reply-To: <20261202-asus-wmi-eval-buf-v1-1-640c12d437dc@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/2/26 00:31, Bartu Alev wrote: > 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 > --- > 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; > + } Hi and thanks for improving this code! I leave my review below. This code, after applying the patch reads as this: if obj is null and no memory is allocated go to deallocate memory of obj. I understand that you are preparing for patch 2 and the __free conversion here... but probably converting it into __free right away would have been better. You can still split it up, but patches need to have coherent code, if you really think the dual patch is the way to go rename out_free into asus_wmi_evaluate_method_err and move it below the kfree and that way the will be coherent again. > + > 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) { >