2021-04-27 01:42:38

by Lv Yunlong

[permalink] [raw]
Subject: [PATCH] ACPICA:dbnames: Fix a error free in acpi_db_walk_for_fields

In acpi_db_walk_for_fields, buffer.pointer is freed in the first
time via ACPI_FREE() after acpi_os_printf("%s ", (char *)buffer.pointer).
But later, buffer.pointer is assigned to ret_value, and the freed
pointer is dereferenced by ret_value, which is use after free.

In addition, buffer.pointer is freed by ACPI_FREE() again after
acpi_os_printf("}\n"), which is a double free.

My patch removes the first ACPI_FREE() to avoid the uaf and double
free bugs.

Fixes: 5fd033288a866 ("ACPICA: debugger: add command to dump all fields of particular subtype")
Signed-off-by: Lv Yunlong <[email protected]>
---
drivers/acpi/acpica/dbnames.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/drivers/acpi/acpica/dbnames.c b/drivers/acpi/acpica/dbnames.c
index 3615e1a6efd8..dabd76df15ec 100644
--- a/drivers/acpi/acpica/dbnames.c
+++ b/drivers/acpi/acpica/dbnames.c
@@ -547,7 +547,6 @@ acpi_db_walk_for_fields(acpi_handle obj_handle,
}

acpi_os_printf("%s ", (char *)buffer.pointer);
- ACPI_FREE(buffer.pointer);

buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
acpi_evaluate_object(obj_handle, NULL, NULL, &buffer);
--
2.25.1



2021-04-29 18:02:26

by Kaneda, Erik

[permalink] [raw]
Subject: RE: [PATCH] ACPICA:dbnames: Fix a error free in acpi_db_walk_for_fields



> -----Original Message-----
> From: Lv Yunlong <[email protected]>
> Sent: Monday, April 26, 2021 6:42 PM
> To: Moore, Robert <[email protected]>; Kaneda, Erik
> <[email protected]>; Wysocki, Rafael J <[email protected]>;
> [email protected]
> Cc: [email protected]; [email protected]; linux-
> [email protected]; Lv Yunlong <[email protected]>
> Subject: [PATCH] ACPICA:dbnames: Fix a error free in
> acpi_db_walk_for_fields
>
> In acpi_db_walk_for_fields, buffer.pointer is freed in the first
> time via ACPI_FREE() after acpi_os_printf("%s ", (char *)buffer.pointer).
> But later, buffer.pointer is assigned to ret_value, and the freed
> pointer is dereferenced by ret_value, which is use after free.
>
> In addition, buffer.pointer is freed by ACPI_FREE() again after
> acpi_os_printf("}\n"), which is a double free.
>
> My patch removes the first ACPI_FREE() to avoid the uaf and double
> free bugs.
>

I'll take a look

Thanks

> Fixes: 5fd033288a866 ("ACPICA: debugger: add command to dump all fields
> of particular subtype")
> Signed-off-by: Lv Yunlong <[email protected]>
> ---
> drivers/acpi/acpica/dbnames.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/acpi/acpica/dbnames.c b/drivers/acpi/acpica/dbnames.c
> index 3615e1a6efd8..dabd76df15ec 100644
> --- a/drivers/acpi/acpica/dbnames.c
> +++ b/drivers/acpi/acpica/dbnames.c
> @@ -547,7 +547,6 @@ acpi_db_walk_for_fields(acpi_handle obj_handle,
> }
>
> acpi_os_printf("%s ", (char *)buffer.pointer);
> - ACPI_FREE(buffer.pointer);
>
> buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
> acpi_evaluate_object(obj_handle, NULL, NULL, &buffer);
> --
> 2.25.1
>

2021-05-05 23:49:46

by Kaneda, Erik

[permalink] [raw]
Subject: RE: [PATCH] ACPICA:dbnames: Fix a error free in acpi_db_walk_for_fields



> -----Original Message-----
> From: Kaneda, Erik <[email protected]>
> Sent: Thursday, April 29, 2021 11:01 AM
> To: Lv Yunlong <[email protected]>; Moore, Robert
> <[email protected]>; Wysocki, Rafael J <[email protected]>;
> [email protected]
> Cc: [email protected]; [email protected]; linux-
> [email protected]
> Subject: RE: [PATCH] ACPICA:dbnames: Fix a error free in
> acpi_db_walk_for_fields
>
>
>
> > -----Original Message-----
> > From: Lv Yunlong <[email protected]>
> > Sent: Monday, April 26, 2021 6:42 PM
> > To: Moore, Robert <[email protected]>; Kaneda, Erik
> > <[email protected]>; Wysocki, Rafael J <[email protected]>;
> > [email protected]
> > Cc: [email protected]; [email protected]; linux-
> > [email protected]; Lv Yunlong <[email protected]>
> > Subject: [PATCH] ACPICA:dbnames: Fix a error free in
> > acpi_db_walk_for_fields
> >
> > In acpi_db_walk_for_fields, buffer.pointer is freed in the first
> > time via ACPI_FREE() after acpi_os_printf("%s ", (char *)buffer.pointer).
> > But later, buffer.pointer is assigned to ret_value, and the freed
> > pointer is dereferenced by ret_value, which is use after free.
> >
> > In addition, buffer.pointer is freed by ACPI_FREE() again after
> > acpi_os_printf("}\n"), which is a double free.
> >
> > My patch removes the first ACPI_FREE() to avoid the uaf and double
> > free bugs.
> >
>
> I'll take a look
>
> Thanks
>
> > Fixes: 5fd033288a866 ("ACPICA: debugger: add command to dump all fields
> > of particular subtype")
> > Signed-off-by: Lv Yunlong <[email protected]>
> > ---
> > drivers/acpi/acpica/dbnames.c | 1 -
> > 1 file changed, 1 deletion(-)
> >
> > diff --git a/drivers/acpi/acpica/dbnames.c b/drivers/acpi/acpica/dbnames.c
> > index 3615e1a6efd8..dabd76df15ec 100644
> > --- a/drivers/acpi/acpica/dbnames.c
> > +++ b/drivers/acpi/acpica/dbnames.c
> > @@ -547,7 +547,6 @@ acpi_db_walk_for_fields(acpi_handle obj_handle,
> > }
> >
> > acpi_os_printf("%s ", (char *)buffer.pointer);
> > - ACPI_FREE(buffer.pointer);

This is freeing the pointer allocated by acpi_ns_handle_to_pathname

> >
> > buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
> > acpi_evaluate_object(obj_handle, NULL, NULL, &buffer);

This call to acpi_evaluate_object will allocate an object in Buffer.Pointer object so the dereference of buffer->pointer is not a use after free

> > --
> > 2.25.1
> >