linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen Zhongjin <chenzhongjin@huawei.com>
To: <linux-kernel@vger.kernel.org>, <linux-acpi@vger.kernel.org>,
	<devel@acpica.org>
Cc: <robert.moore@intel.com>, <rafael.j.wysocki@intel.com>,
	<lenb@kernel.org>, <lv.zheng@intel.com>,
	<chenzhongjin@huawei.com>
Subject: [PATCH] ACPICA: Fix use-after-free in acpi_ps_parse_aml()
Date: Wed, 19 Oct 2022 15:34:43 +0800	[thread overview]
Message-ID: <20221019073443.248215-1-chenzhongjin@huawei.com> (raw)

KASAN reports a use-after-free problem and causes kernel panic
triggered by: modprobe acpiphp_ibm

BUG: KASAN:
use-after-free in acpi_ds_dump_method_stack (drivers/acpi/acpica/dsdebug.c:145)
Read of size 8 at addr ffff888002f843f0 by task modprobe/519

CPU: 2 PID: 519 Comm: modprobe Not tainted 6.0.0+
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
    Call Trace:
    <TASK>
    acpi_ds_dump_method_stack (drivers/acpi/acpica/dsdebug.c:145)
    acpi_ds_method_error (drivers/acpi/acpica/dsmethod.c:232)
    acpi_ps_parse_aml (drivers/acpi/acpica/psparse.c:607)
    ...
    </TASK>

    Allocated by task 519:
    ...
    __kasan_kmalloc (mm/kasan/common.c:526)
    acpi_ds_create_walk_state (drivers/acpi/acpica/dswstate.c:519)
    acpi_ds_call_control_method (drivers/acpi/acpica/dsmethod.c:498)
    acpi_ps_parse_aml (drivers/acpi/acpica/psparse.c:607)
    ...

    Freed by task 519:
    ...
    __kmem_cache_free+0xb6/0x3c0
    acpi_ds_delete_walk_state (drivers/acpi/acpica/dswstate.c:722)
    acpi_ds_call_control_method (drivers/acpi/acpica/dsmethod.c:586)
    acpi_ps_parse_aml (drivers/acpi/acpica/psparse.c:607)
    ...
---[ end Kernel panic - not syncing: Fatal exception ]---

In the error path in acpi_ps_parse_aml():

    acpi_ds_call_control_method()
        acpi_ds_create_walk_state()
            acpi_ds_push_walk_state()
	    # thread->walk_state_list = walk_state

        acpi_ds_init_aml_walk # *fail*
        goto cleanup:
        acpi_ds_delete_walk_state() # ACPI_FREE(walk_state)

    acpi_ds_method_error()
        acpi_ds_dump_method_stack()
        # using freed thread->walk_state_list

Briefly, the walk_state is pushed to thread, and freed without being poped.
Then it is used in acpi_ds_dump_method_stack() and causes use-after-free.

Add acpi_ds_pop_walk_state(thread) to the error path to fix the problem.

Fixes: 0bac4295526c ("ACPICA: Dispatcher: Move stack traversal code to dispatcher")

Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
---
 drivers/acpi/acpica/dsmethod.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/acpi/acpica/dsmethod.c b/drivers/acpi/acpica/dsmethod.c
index ae2e768830bf..19da7fc73186 100644
--- a/drivers/acpi/acpica/dsmethod.c
+++ b/drivers/acpi/acpica/dsmethod.c
@@ -581,6 +581,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
 
 	acpi_ds_terminate_control_method(obj_desc, next_walk_state);
 	acpi_ds_delete_walk_state(next_walk_state);
+	acpi_ds_pop_walk_state(thread);
 
 	return_ACPI_STATUS(status);
 }
-- 
2.17.1


             reply	other threads:[~2022-10-19  7:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19  7:34 Chen Zhongjin [this message]
2022-10-28 15:46 ` [PATCH] ACPICA: Fix use-after-free in acpi_ps_parse_aml() Rafael J. Wysocki
2022-11-05 19:00   ` Rafael J. Wysocki
2022-11-07  9:30     ` Chen Zhongjin
2022-11-07 17:51       ` Rafael J. Wysocki

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=20221019073443.248215-1-chenzhongjin@huawei.com \
    --to=chenzhongjin@huawei.com \
    --cc=devel@acpica.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lv.zheng@intel.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robert.moore@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).