Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2163223rwb; Mon, 7 Nov 2022 09:53:31 -0800 (PST) X-Google-Smtp-Source: AMsMyM56bi9wGsaGZ1zNKCBdQ3RKNEU4n+j71tPKRj4FgXGX/O8drLP2D19Ch5Sv4bKFo8pDpkJS X-Received: by 2002:a17:90a:ca18:b0:213:98e7:3af with SMTP id x24-20020a17090aca1800b0021398e703afmr54860833pjt.174.1667843611289; Mon, 07 Nov 2022 09:53:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667843611; cv=none; d=google.com; s=arc-20160816; b=NoyyffgfSr3rXnihna1k+ajtXc66SkhBWNrSSJ6BNHHhWMKGL4/a7rwSXiJVkHAyqQ 7vin0EERN5XWw2Z2uY2MXA2C4nEsKVSqZ1PeI1P5crR9YKIwQq7Qscly11HppyMnKuJq JnWYYWLMjyJFYU+UcOZGcuy7F8LjTz5I2KUROd5l8kLq3YWjzFwewGc+FDZqwwxMaY1O 5eG956bHcrgnnvSvzL8OFbajyHtzN13sMvjXxMx5b76fyP5TOM0FHakVNWwn6/3wo95k pDCCYthGPGtP0yZ8bQLnS6xxW7Hih8iQKTiYbgHkDxGCExF+N/SbMmYwHPIczsFz3r06 mpNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=+UnPEombRM4bFHsehp/hCd9FFfeHpW+f73e4iMMVafs=; b=rtZJemfe7q52or0uhGfrgJomym5SzUkcIRf2kmPH/YZs44+otwLlPJzESeS5/tI12x dyYy8K4t4Wg89L87HthiYUUKeoDM9hiB8YSOtue/A81AcnEsWi7hDTLOcS2t1ScG4dDj Q1uWXduUNwOJKtdJG+VM8eG61ccHtnpaXM3UWFsDMhqH2y937/KZZYQmvxrAduzQ7/o9 xHjC2noO4C0DM/Kw1tn/pJShm8ZmCsc6tGWMaqjtMAh0INJTEw1aP4HHCd9EnEuMTdg9 4Bp9i1YBd1bYGaP2dY15134yCf6N6AO5hucU2ZNC8li7myCv5qsktLZXVmXlcS6+JNmc OOlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t41-20020a056a0013a900b0056cd93aac47si11531092pfg.358.2022.11.07.09.53.18; Mon, 07 Nov 2022 09:53:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232476AbiKGRmq (ORCPT + 92 others); Mon, 7 Nov 2022 12:42:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231403AbiKGRmp (ORCPT ); Mon, 7 Nov 2022 12:42:45 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 583B41A383; Mon, 7 Nov 2022 09:42:43 -0800 (PST) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.0.0) id 4ff0f43161b321cf; Mon, 7 Nov 2022 18:42:40 +0100 Received: from kreacher.localnet (unknown [213.134.188.205]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id A7CCD66EB64; Mon, 7 Nov 2022 18:42:39 +0100 (CET) Authentication-Results: v370.home.net.pl; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: v370.home.net.pl; spf=fail smtp.mailfrom=rjwysocki.net From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Bob Moore , Chen Zhongjin Subject: [PATCH] ACPICA: Fix error code path in acpi_ds_call_control_method() Date: Mon, 07 Nov 2022 18:42:36 +0100 Message-ID: <2669303.mvXUDI8C0e@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.188.205 X-CLIENT-HOSTNAME: 213.134.188.205 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvgedrvdekgddutddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepgeffhfdujeelhfdtgeffkeetudfhtefhhfeiteethfekvefgvdfgfeeikeeigfehnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepvddufedrudefgedrudekkedrvddtheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvudefrddufeegrddukeekrddvtdehpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeegpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhosggvrhhtrdhmohhorhgvsehinhhtvghlrdgtohhmpdhrtghpthhtoheptghhvghniihhohhnghhj ihhnsehhuhgrfigvihdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=4 Fuz1=4 Fuz2=4 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki A use-after-free in acpi_ps_parse_aml() after a failing invocaion of acpi_ds_call_control_method() is reported by KASAN [1] and code inspection reveals that next_walk_state pushed to the thread by acpi_ds_create_walk_state() is freed on errors, but it is not popped from the thread beforehand. Thus acpi_ds_get_current_walk_state() called by acpi_ps_parse_aml() subsequently returns it as the new walk state which is incorrect. To address this, make acpi_ds_call_control_method() call acpi_ds_pop_walk_state() to pop next_walk_state from the thread before returning an error. Link: https://lore.kernel.org/linux-acpi/20221019073443.248215-1-chenzhongjin@huawei.com/ Reported-by: Chen Zhongjin Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/dsmethod.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) Index: linux-pm/drivers/acpi/acpica/dsmethod.c =================================================================== --- linux-pm.orig/drivers/acpi/acpica/dsmethod.c +++ linux-pm/drivers/acpi/acpica/dsmethod.c @@ -517,7 +517,7 @@ acpi_ds_call_control_method(struct acpi_ info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); if (!info) { status = AE_NO_MEMORY; - goto cleanup; + goto pop_walk_state; } info->parameters = &this_walk_state->operands[0]; @@ -529,7 +529,7 @@ acpi_ds_call_control_method(struct acpi_ ACPI_FREE(info); if (ACPI_FAILURE(status)) { - goto cleanup; + goto pop_walk_state; } next_walk_state->method_nesting_depth = @@ -575,6 +575,12 @@ acpi_ds_call_control_method(struct acpi_ return_ACPI_STATUS(status); +pop_walk_state: + + /* On error, pop the walk state to be deleted from thread */ + + acpi_ds_pop_walk_state(thread); + cleanup: /* On error, we must terminate the method properly */