mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Winiarska, Iwona" <iwona.winiarska@intel.com>
To: "niejianglei2021@163.com" <niejianglei2021@163.com>
Cc: "openbmc@lists.ozlabs.org" <openbmc@lists.ozlabs.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] peci: fix potential memory leak in devm_adev_add()
Date: Tue, 5 Jul 2022 10:18:51 +0000	[thread overview]
Message-ID: <d4bfcbfa4fbbb1acdd8110287744a39d6525306d.camel@intel.com> (raw)
In-Reply-To: <20220704125922.2240585-1-niejianglei2021@163.com>

On Mon, 2022-07-04 at 20:59 +0800, Jianglei Nie wrote:
> devm_adev_add() allocates a memory chunk for "adev" and "adev->name"
> with adev_alloc(). When auxiliary_device_add() fails, the function calls
> auxiliary_device_uninit(), which doesn't release the allocated "adev"
> and "adev->name", thus leading to a memory leak bug.
> 
> We should call adev_release() instead of auxiliary_device_uninit() to
> release the "adev" and "adev->name".
> 
> Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
> ---
>  drivers/peci/cpu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/peci/cpu.c b/drivers/peci/cpu.c
> index 68eb61c65d34..de865997ccde 100644
> --- a/drivers/peci/cpu.c
> +++ b/drivers/peci/cpu.c
> @@ -248,7 +248,7 @@ static int devm_adev_add(struct device *dev, int idx)
>  
>         ret = auxiliary_device_add(adev);
>         if (ret) {
> -               auxiliary_device_uninit(adev);
> +               adev_release(&adev->dev);
>                 return ret;
>         }
>  

When we call auxiliary_device_uninit() the .release callback (adev_release())
will be triggered, so there's no memory leak here.

But thank you for pointing to this - it made me realize that we have a bug in
adev_release(), because we call auxiliary_device_uninit() there, which will
cause a use-after-free with refcount underflow in this case.

I'd appreciate if you could review it:
https://lore.kernel.org/lkml/20220705101501.298395-1-iwona.winiarska@intel.com/

Thanks
-Iwona

      reply	other threads:[~2022-07-05 10:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04 12:59 Jianglei Nie
2022-07-05 10:18 ` Winiarska, Iwona [this message]

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=d4bfcbfa4fbbb1acdd8110287744a39d6525306d.camel@intel.com \
    --to=iwona.winiarska@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=niejianglei2021@163.com \
    --cc=openbmc@lists.ozlabs.org \
    /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

all inboxes | Powered by JetHome®