All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Eduardo Valentin <eduval@amazon.com>
Cc: Jean Delvare <jdelvare@suse.com>,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCHv2 2/2] hwmon: core: fix potential memory leak in *hwmon_device_register*
Date: Thu, 6 Jun 2019 09:55:55 -0700	[thread overview]
Message-ID: <20190606165555.GA32130@roeck-us.net> (raw)
In-Reply-To: <20190606143509.GF1534@u40b0340c692b58f6553c.ant.amazon.com>

On Thu, Jun 06, 2019 at 07:35:44AM -0700, Eduardo Valentin wrote:
> On Wed, Jun 05, 2019 at 01:38:38PM -0700, Guenter Roeck wrote:
> > On Wed, May 29, 2019 at 07:56:05PM -0700, Eduardo Valentin wrote:
> > > When registering a hwmon device with HWMON_C_REGISTER_TZ flag
> > > in place, the hwmon subsystem will attempt to register the device
> > > also with the thermal subsystem. When the of-thermal registration
> > > fails, __hwmon_device_register jumps to ida_remove, leaving
> > > the locally allocated hwdev pointer.
> > > 
> > > This patch fixes the leak by jumping to a new label that
> > > will first unregister hdev and then fall into the kfree of hwdev
> > > to finally remove the idas and propagate the error code.
> > > 
> > 
> > Hah, actually this is wrong. hwdev is freed indirectly with the
> > device_unregister() call. See commit 74e3512731bd ("hwmon: (core)
> > Fix double-free in __hwmon_device_register()").
> 
> heh.. I see it now. Well, it is not a straight catch though. 
> 
> > 
> > It may make sense to add a respective comment to the code, though.
> > 
> 
> I agree. Or a simple comment saying "dont worry about freeing hwdev
> because hwmon_dev_release() takes care of it".
> 
> Are you patching it ?
> 

Will do. I'll send a patch in a minute.

Thanks,
Guenter

      reply	other threads:[~2019-06-06 16:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-30  2:56 [PATCHv2 0/2] hwmon: couple of fixes on HWMON_C_REGISTER_TZ Eduardo Valentin
2019-05-30  2:56 ` [PATCHv2 1/2] hwmon: core: add thermal sensors only if dev->of_node is present Eduardo Valentin
2019-05-30  2:56 ` [PATCHv2 2/2] hwmon: core: fix potential memory leak in *hwmon_device_register* Eduardo Valentin
2019-06-05 20:29   ` Guenter Roeck
2019-06-05 20:38   ` Guenter Roeck
2019-06-06 14:35     ` Eduardo Valentin
2019-06-06 16:55       ` Guenter Roeck [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=20190606165555.GA32130@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=eduval@amazon.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 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.