linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Mark Asselstine <mark.asselstine@windriver.com>
Cc: ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Erik Kaneda <erik.kaneda@intel.com>,
	Robert Moore <robert.moore@intel.com>
Subject: Re: [PATCH] ACPICA: avoid double free when object already has a zero reference count
Date: Thu, 29 Oct 2020 15:05:46 +0100	[thread overview]
Message-ID: <CAJZ5v0hr4xFA9bGJM+0e4i-QpESPnwy5ZT4KPwfJgby5Sz3UBw@mail.gmail.com> (raw)
In-Reply-To: <20201028200523.111028-1-mark.asselstine@windriver.com>

+Erik and Bob

On Thu, Oct 29, 2020 at 3:05 AM Mark Asselstine
<mark.asselstine@windriver.com> wrote:
>
> The first trip into acpi_ut_update_ref_count() for an object where
> 'object->common.reference_count' is 1 and we are performing a
> REF_DECREMENT will result in 'new_count' being 0 and thus the object
> is deleted via acpi_ut_delete_internal_obj().
>
> If for some reason we make a subsequent trip into
> acpi_ut_update_ref_count() with the same object,
> object->common.reference_count' will be 0 and performing a
> REF_DECREMENT will produce a warning msg "Reference Count is already
> zero, cannot decrement", 'new_count' will again be 0 and the already
> deleted object will be attempted to be deleted again via
> acpi_ut_delete_internal_obj().
>
> Since the object deletion doesn't NULL the object the calls to
> acpi_ut_delete_internal_obj(), acpi_ut_delete_object_desc(),
> acpi_os_release_object(), kmem_cache_free() will operate on the object
> as if it hasn't been deleted. In many cases this can result in no
> issues, but if you are using the slab and a new object has been
> created with the same address this can be the cause slab corruption.
>
> Adding a check if we are decrementing to 0 for the first time and only
> calling acpi_ut_delete_internal_obj() in this case will prevent
> another attempt at deleting the object.
>
> Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
> ---
>  drivers/acpi/acpica/utdelete.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/acpica/utdelete.c b/drivers/acpi/acpica/utdelete.c
> index 4c0d4e434196..c6b860fd9eb5 100644
> --- a/drivers/acpi/acpica/utdelete.c
> +++ b/drivers/acpi/acpica/utdelete.c
> @@ -421,9 +421,9 @@ acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action)
>                                       ACPI_GET_FUNCTION_NAME, object,
>                                       object->common.type, new_count));
>
> -               /* Actually delete the object on a reference count of zero */
> +               /* If we haven't already, actually delete the object on a reference count of zero */
>
> -               if (new_count == 0) {
> +               if (new_count == 0 && original_count != 0) {
>                         acpi_ut_delete_internal_obj(object);
>                 }
>                 message = "Decrement";
> --
> 2.17.1
>

  reply	other threads:[~2020-10-29 14:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28 20:05 [PATCH] ACPICA: avoid double free when object already has a zero reference count Mark Asselstine
2020-10-29 14:05 ` Rafael J. Wysocki [this message]
2020-11-02 18:11   ` Kaneda, Erik
2020-11-02 18:51     ` Mark Asselstine
2020-11-03 18:28       ` Kaneda, Erik
2020-11-03 18:52         ` Mark Asselstine
2020-11-19 22:30           ` Mark Asselstine

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=CAJZ5v0hr4xFA9bGJM+0e4i-QpESPnwy5ZT4KPwfJgby5Sz3UBw@mail.gmail.com \
    --to=rafael@kernel.org \
    --cc=erik.kaneda@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=mark.asselstine@windriver.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).