All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPICA: Fix use-after-free in acpi_ut_copy_ipackage_to_ipackage()
@ 2022-12-01  8:05 Li Zetao
  2022-12-02 19:36 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Li Zetao @ 2022-12-01  8:05 UTC (permalink / raw)
  To: robert.moore, rafael.j.wysocki, lenb, lv.zheng, david.e.box
  Cc: lizetao1, linux-acpi, devel, linux-kernel

There is an use-after-free reported by KASAN:

  BUG: KASAN: use-after-free in acpi_ut_remove_reference+0x3b/0x82
  Read of size 1 at addr ffff888112afc460 by task modprobe/2111
  CPU: 0 PID: 2111 Comm: modprobe Not tainted 6.1.0-rc7-dirty
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
  Call Trace:
   <TASK>
   kasan_report+0xae/0xe0
   acpi_ut_remove_reference+0x3b/0x82
   acpi_ut_copy_iobject_to_iobject+0x3be/0x3d5
   acpi_ds_store_object_to_local+0x15d/0x3a0
   acpi_ex_store+0x78d/0x7fd
   acpi_ex_opcode_1A_1T_1R+0xbe4/0xf9b
   acpi_ps_parse_aml+0x217/0x8d5
   ...
   </TASK>

The root cause of the problem is that the acpi_operand_object
is freed when acpi_ut_walk_package_tree() fails in
acpi_ut_copy_ipackage_to_ipackage(), lead to repeated release in
acpi_ut_copy_iobject_to_iobject(). The problem was introduced
by "8aa5e56eeb61" commit, this commit is to fix memory leak in
acpi_ut_copy_iobject_to_iobject(), repeatedly adding remove
operation, lead to "acpi_operand_object" used after free.

Fix it by removing acpi_ut_remove_reference() in
acpi_ut_copy_ipackage_to_ipackage(). acpi_ut_copy_ipackage_to_ipackage()
is called to copy an internal package object into another internal
package object, when it fails, the memory of acpi_operand_object
should be freed by the caller.

Fixes: 8aa5e56eeb61 ("ACPICA: Utilities: Fix memory leak in acpi_ut_copy_iobject_to_iobject")
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/acpi/acpica/utcopy.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/acpi/acpica/utcopy.c b/drivers/acpi/acpica/utcopy.c
index 400b9e15a709..63c17f420fb8 100644
--- a/drivers/acpi/acpica/utcopy.c
+++ b/drivers/acpi/acpica/utcopy.c
@@ -916,13 +916,6 @@ acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
 	status = acpi_ut_walk_package_tree(source_obj, dest_obj,
 					   acpi_ut_copy_ielement_to_ielement,
 					   walk_state);
-	if (ACPI_FAILURE(status)) {
-
-		/* On failure, delete the destination package object */
-
-		acpi_ut_remove_reference(dest_obj);
-	}
-
 	return_ACPI_STATUS(status);
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ACPICA: Fix use-after-free in acpi_ut_copy_ipackage_to_ipackage()
  2022-12-01  8:05 [PATCH] ACPICA: Fix use-after-free in acpi_ut_copy_ipackage_to_ipackage() Li Zetao
@ 2022-12-02 19:36 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2022-12-02 19:36 UTC (permalink / raw)
  To: Li Zetao
  Cc: robert.moore, rafael.j.wysocki, lenb, lv.zheng, david.e.box,
	linux-acpi, devel, linux-kernel

On Thu, Dec 1, 2022 at 8:00 AM Li Zetao <lizetao1@huawei.com> wrote:
>
> There is an use-after-free reported by KASAN:
>
>   BUG: KASAN: use-after-free in acpi_ut_remove_reference+0x3b/0x82
>   Read of size 1 at addr ffff888112afc460 by task modprobe/2111
>   CPU: 0 PID: 2111 Comm: modprobe Not tainted 6.1.0-rc7-dirty
>   Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
>   Call Trace:
>    <TASK>
>    kasan_report+0xae/0xe0
>    acpi_ut_remove_reference+0x3b/0x82
>    acpi_ut_copy_iobject_to_iobject+0x3be/0x3d5
>    acpi_ds_store_object_to_local+0x15d/0x3a0
>    acpi_ex_store+0x78d/0x7fd
>    acpi_ex_opcode_1A_1T_1R+0xbe4/0xf9b
>    acpi_ps_parse_aml+0x217/0x8d5
>    ...
>    </TASK>
>
> The root cause of the problem is that the acpi_operand_object
> is freed when acpi_ut_walk_package_tree() fails in
> acpi_ut_copy_ipackage_to_ipackage(), lead to repeated release in
> acpi_ut_copy_iobject_to_iobject(). The problem was introduced
> by "8aa5e56eeb61" commit, this commit is to fix memory leak in
> acpi_ut_copy_iobject_to_iobject(), repeatedly adding remove
> operation, lead to "acpi_operand_object" used after free.
>
> Fix it by removing acpi_ut_remove_reference() in
> acpi_ut_copy_ipackage_to_ipackage(). acpi_ut_copy_ipackage_to_ipackage()
> is called to copy an internal package object into another internal
> package object, when it fails, the memory of acpi_operand_object
> should be freed by the caller.
>
> Fixes: 8aa5e56eeb61 ("ACPICA: Utilities: Fix memory leak in acpi_ut_copy_iobject_to_iobject")
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
>  drivers/acpi/acpica/utcopy.c | 7 -------
>  1 file changed, 7 deletions(-)
>
> diff --git a/drivers/acpi/acpica/utcopy.c b/drivers/acpi/acpica/utcopy.c
> index 400b9e15a709..63c17f420fb8 100644
> --- a/drivers/acpi/acpica/utcopy.c
> +++ b/drivers/acpi/acpica/utcopy.c
> @@ -916,13 +916,6 @@ acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
>         status = acpi_ut_walk_package_tree(source_obj, dest_obj,
>                                            acpi_ut_copy_ielement_to_ielement,
>                                            walk_state);
> -       if (ACPI_FAILURE(status)) {
> -
> -               /* On failure, delete the destination package object */
> -
> -               acpi_ut_remove_reference(dest_obj);
> -       }
> -
>         return_ACPI_STATUS(status);
>  }
>
> --

Applied as 6.2 material.

Normally, I would ask for a corresponding pull request to be submitted
to the upstream project on GitHub, but this looks serious enough to be
fast-tracked.

Anyway, it would help if you submitted a pull request with this change
to upstream ACPICA on GitHub.  Otherwise, I'll take care of that.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-02 19:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01  8:05 [PATCH] ACPICA: Fix use-after-free in acpi_ut_copy_ipackage_to_ipackage() Li Zetao
2022-12-02 19:36 ` Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.