From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.75 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796179560; b=pWUBQraA1IRaZaG+WY4c96DfsQvixSGEZHAKXG0my5XO382r+1g4B7rlPtqfwZLV+EgK p9CzYLEwosGcSZYGEPP4k6Uv2P/ee+UJ6SKrAla8JsWTVxMByCvh1VrYb0mmt2Y7GfnVH AcSrDLeFl8873/8spIP7UJCE912JRO50jxzJoLxaMunFUuDftybD8vo+foJLopzeXyn0/ MCn8mVyPVVFMoF8Gn+gn2pLvMPG/AUAaxIDeA2wVKjsAzJFScRC7TLh+tiwtCxUV4ptTY vP8RtdR4s6t3HBzbxQbKdXGnynGDflk5tY+nqYKSHDuX8VROjW0B+9IhJIXvRw2MmSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179560; 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=Aqt1phuEJeG0Hec47qtK0AzKNDyobjXELKoBNEMGIC4=; b=VBzml4+uhaHbtBE4xk5+lMxy44DnIOrF2haOL2LCvR8fmlsUyf6BX1V0oSQjx6Ooa3D0 u3kPuxr7knmxXUAkD6382aRPwubdzvz/DXGf7M/3nh9X4Go0jt8uRxOATsJPrBFt/HRgO IPZvWOOwWxd4psXUB5JWyubg8KjVrkTW89k75UYie3mfyNXpEBTzvJY915jAHjP3whryw E2+r/g0IpFYWCAS6EwkXw4VA1G2GKQ2bKfBgU/XwgNNKNcnVZJoj+xj0YfEGmNJ1xNR1n Yi3tJzSnMowATJu8zsY5OMoIVw4P2I5kfi590TRw+paR4bEKRaIY4sRBXfxijj88WQg== 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=KsOt0i0O; arc=none smtp.remote-ip=91.218.175.75 Received: from mta0.migadu.com (out-75.mta0.migadu.com [91.218.175.75]) (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 6118D606A31A for ; Wed, 2 Dec 2026 02:45:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6118D606A31A 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=KsOt0i0O X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=E2vX34cmQ/jyHzz+r+iyIjnFR+GybBiYkOwfqxjPAo8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796179557; v=1; x=1796784357; b=KsOt0i0O7DU6j/2+ACcASCupXVbOTrZ2M+sBBZ1BGTMp1i4KjOD2g5WXH8OdNfc6qlWBRaOm 2mlW/vl4L1duupVPRvpWr/QUyf8As/ehn5CeCmcBu4ItZLwNS31VFLdQakep58SRZqXTSgKE8o4 K75gL+PLdvpGlWZzwsTM/IqU= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id e0897e367666039a; Wed, 02 Dec 2026 02:45:57 +0000 X-Mizu-Trace-ID: e0897e367666039a X-Migadu-Flow: FLOW_OUT Message-ID: Date: Wed, 2 Dec 2026 03:45:56 +0100 X-Mailing-List: linux-kernel@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 2/3] platform/asus: asus-wmi: Use __free(kfree) 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 References: <20261202-asus-wmi-eval-buf-v1-0-640c12d437dc@gmail.com> <20261202-asus-wmi-eval-buf-v1-2-640c12d437dc@gmail.com> Content-Language: en-US From: Denis Benato In-Reply-To: <20261202-asus-wmi-eval-buf-v1-2-640c12d437dc@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/2/26 00:31, Bartu Alev wrote: > Replace the manual kfree(obj) and the out_free: goto with a __free(kfree) > cleanup attribute, as include/linux/cleanup.h asks not to mix goto with > scope-based cleanup in the same routine. > > Declare the buffer right after the evaluation and before the > ACPI_FAILURE(status) check, so that ownership is taken on every path. > This also covers a leak inside ACPICA: acpi_evaluate_object() in > nsxfeval.c allocates return_buffer->pointer through > acpi_ut_initialize_buffer() and, if acpi_ut_copy_iobject_to_eobject() > then fails with AE_TYPE or AE_SUPPORT (utcopy.c), returns without > freeing it. The ACPI_FAILURE path now releases that buffer as well. > > Signed-off-by: Bartu Alev > --- > drivers/platform/asus/asus-wmi.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c > index 4f74fdfd7a0c2..015e207e840e6 100644 > --- a/drivers/platform/asus/asus-wmi.c > +++ b/drivers/platform/asus/asus-wmi.c > @@ -477,11 +477,15 @@ static int asus_wmi_evaluate_method_buf(u32 method_id, > struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; > 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); > + /* > + * Take ownership of the reply buffer right away: ACPICA may leave it > + * allocated even when reporting a failure. > + */ > + union acpi_object *obj __free(kfree) = output.pointer; > > pr_debug("%s called (0x%08x) with args: 0x%08x, 0x%08x\n", > __func__, method_id, arg0, arg1); > @@ -491,15 +495,14 @@ static int asus_wmi_evaluate_method_buf(u32 method_id, > return -EIO; > } > > - obj = (union acpi_object *)output.pointer; > - obj was assigned here, you moved it up but I can't see any reason for that, in fact moving it up only increase the possibility of an allocation immediately freed due to an error (like the return -EIO). Move the obj __free line here. > /* > * 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; > + pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n", > + __func__, method_id, arg0, -ENODATA); > + return -ENODATA; > } > > switch (obj->type) { > @@ -533,9 +536,6 @@ static int asus_wmi_evaluate_method_buf(u32 method_id, > break; > } > > -out_free: > - kfree(obj); > - Yeah... I think that this should be patch 1, but Ilpo might have a different opinion... At the same time 8 lines changes in two patches where half of the first patch gets dropped on the second looks like a bit of an overkill to me. > if (err) { > pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n", > __func__, method_id, arg0, err); >