mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Sven Van Asbroeck <thesven73@gmail.com>,
	Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] max17042_battery: fix potential use-after-free on device remove
Date: Fri, 15 Feb 2019 23:08:19 +0100	[thread overview]
Message-ID: <3e771d70-4e51-114c-6e00-460b34dd0909@redhat.com> (raw)
In-Reply-To: <20190215220344.16604-1-TheSven73@gmail.com>

Hi,

On 2/15/19 11:03 PM, Sven Van Asbroeck wrote:
> The work which is scheduled on a POR boot is potentially left
> pending or running until after the device module is removed,
> which could result in a use-after-free.
> 
> Fix by registering a cancel/sync callback, which gets executed as
> part of standard resource unwinding.
> 
> This issue was detected with the help of Coccinelle.
> 
> Cc: Hans de Goede <hdegoede@redhat.com>
> Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com>

Looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> ---
>   drivers/power/supply/max17042_battery.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
> index 2a8d75e5e930..581c6bd23388 100644
> --- a/drivers/power/supply/max17042_battery.c
> +++ b/drivers/power/supply/max17042_battery.c
> @@ -995,6 +995,13 @@ static const struct power_supply_desc max17042_no_current_sense_psy_desc = {
>   	.num_properties	= ARRAY_SIZE(max17042_battery_props) - 2,
>   };
>   
> +static void max17042_stop_work(void *data)
> +{
> +	struct max17042_chip *chip = data;
> +
> +	cancel_work_sync(&chip->work);
> +}
> +
>   static int max17042_probe(struct i2c_client *client,
>   			const struct i2c_device_id *id)
>   {
> @@ -1101,6 +1108,9 @@ static int max17042_probe(struct i2c_client *client,
>   	regmap_read(chip->regmap, MAX17042_STATUS, &val);
>   	if (val & STATUS_POR_BIT) {
>   		INIT_WORK(&chip->work, max17042_init_worker);
> +		ret = devm_add_action(&client->dev, max17042_stop_work, chip);
> +		if (ret)
> +			return ret;
>   		schedule_work(&chip->work);
>   	} else {
>   		chip->init_complete = 1;
> 

      reply	other threads:[~2019-02-15 22:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-15 22:03 Sven Van Asbroeck
2019-02-15 22:08 ` Hans de Goede [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=3e771d70-4e51-114c-6e00-460b34dd0909@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=thesven73@gmail.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

all inboxes | Powered by JetHome®