All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guenter Roeck" <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2 1/2] hwmon: (lm90) Stop work before releasing hwmon device
Date: Fri, 15 May 2026 00:37:03 +0000	[thread overview]
Message-ID: <20260515003704.0CC5BC2BCB3@smtp.kernel.org> (raw)
In-Reply-To: <20260514235626.1403695-1-linux@roeck-us.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Race condition in `lm90_stop_work()` allows canceled workers to be re-armed via concurrent sysfs accesses, leading to a Use-After-Free.
--

commit e9b97015cb5267aa1cbf5c4dd89535d551b6b503
Author: Guenter Roeck <linux@roeck-us.net>
hwmon: (lm90) Stop work before releasing hwmon device

This commit fixes a use-after-free issue by canceling the workers after
registering the hwmon device and before registering the interrupt handler.
It introduces a shutdown flag to prevent workers from being re-armed during
device teardown.

> diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
> index 3c10a5066b53d..08a568f7b56f9 100644
> --- a/drivers/hwmon/lm90.c
> +++ b/drivers/hwmon/lm90.c
[ ... ]
> @@ -2584,15 +2588,21 @@ static void lm90_restore_conf(void *_data)
>  	struct lm90_data *data = _data;
>  	struct i2c_client *client = data->client;
>  
> -	cancel_delayed_work_sync(&data->alert_work);
> -	cancel_work_sync(&data->report_work);
> -
>  	/* Restore initial configuration */
>  	if (data->flags & LM90_HAVE_CONVRATE)
>  		lm90_write_convrate(data, data->convrate_orig);
>  	lm90_write_reg(client, LM90_REG_CONFIG1, data->config_orig);
>  }
>  
> +static void lm90_stop_work(void *_data)
> +{
> +	struct lm90_data *data = _data;
> +
> +	data->shutdown = true;

Can this race with a concurrent sysfs read, allowing the workers to be
re-armed after they are canceled?

Since devres unwinds in reverse order, lm90_stop_work() executes before the
hwmon device is unregistered. This leaves the sysfs attributes fully
accessible.

If a sysfs read happens concurrently, the hwmon core will acquire the hwmon
lock, and the driver could call lm90_update_alarms_locked(). Because
lm90_stop_work() sets data->shutdown without acquiring hwmon_lock(), the
concurrent sysfs read might read data->shutdown as false before it is updated.

If the sysfs thread blocks on I2C reads, lm90_stop_work() could set
data->shutdown to true and call cancel_delayed_work_sync(). Since the work is
not yet queued, the cancellation returns immediately.

When the sysfs thread finishes its I2C transfers, it could call
schedule_work() or schedule_delayed_work(), successfully re-arming the workers
after they were supposedly canceled.

As the devres unbind continues, it unregisters the hwmon device and frees the
data structure. When the newly scheduled work executes, it would dereference
the freed memory, causing a use-after-free.

Should lm90_stop_work() hold hwmon_lock(data->hwmon_dev) while setting
data->shutdown to synchronize with sysfs reads, releasing it before calling
the sync cancellation functions to avoid deadlocks?

> +	cancel_delayed_work_sync(&data->alert_work);
> +	cancel_work_sync(&data->report_work);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260514235626.1403695-1-linux@roeck-us.net?part=1

      parent reply	other threads:[~2026-05-15  0:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-14 23:56 [PATCH v2 1/2] hwmon: (lm90) Stop work before releasing hwmon device Guenter Roeck
2026-05-14 23:56 ` [PATCH v2 2/2] hwmon: (lm90) Add lock protection to lm90_alert Guenter Roeck
2026-05-15  1:18   ` sashiko-bot
2026-05-15  0:37 ` sashiko-bot [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=20260515003704.0CC5BC2BCB3@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.