* [PATCH] Revert "hwmon: (ibmpex) fix use-after-free in high/low store"
@ 2026-02-07 16:21 Guenter Roeck
2026-02-10 8:55 ` Jean Delvare
0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2026-02-07 16:21 UTC (permalink / raw)
To: Hardware Monitoring; +Cc: Guenter Roeck, Jean Delvare, Junrui Luo
This reverts commit 6946c726c3f4c36f0f049e6f97e88c510b15f65d.
Jean Delvare points out that the patch does not completely
fix the reported problem, that it in fact introduces a
(new) race condition, and that it may actually not be needed in
the first place.
Various AI reviews agree. Specific and relevant AI feedback:
"
This reordering sets the driver data to NULL before removing the sensor
attributes in the loop below.
ibmpex_show_sensor() retrieves this driver data via dev_get_drvdata() but
does not check if it is NULL before dereferencing it to access
data->sensors[].
If a userspace process reads a sensor file (like temp1_input) while this
delete function is running, could it race with the dev_set_drvdata(...,
NULL) call here and crash in ibmpex_show_sensor()?
Would it be safer to keep the original order where device_remove_file() is
called before clearing the driver data? device_remove_file() should wait
for any active sysfs callbacks to complete, which might already prevent the
use-after-free this patch intends to fix.
"
Revert the offending patch. If it can be shown that the originally reported
alleged race condition does indeed exist, it can always be re-introduced
with a complete fix.
Reported-by: Jean Delvare <jdelvare@suse.de>
Closes: https://lore.kernel.org/linux-hwmon/20260121095342.73e723cb@endymion/
Cc: Jean Delvare <jdelvare@suse.de>
Cc: Junrui Luo <moonafterrain@outlook.com>
Fixes: 6946c726c3f4 ("hwmon: (ibmpex) fix use-after-free in high/low store")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/ibmpex.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c
index 129f3a9e8fe9..228c5f6c6f38 100644
--- a/drivers/hwmon/ibmpex.c
+++ b/drivers/hwmon/ibmpex.c
@@ -277,9 +277,6 @@ static ssize_t ibmpex_high_low_store(struct device *dev,
{
struct ibmpex_bmc_data *data = dev_get_drvdata(dev);
- if (!data)
- return -ENODEV;
-
ibmpex_reset_high_low_data(data);
return count;
@@ -511,9 +508,6 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data)
{
int i, j;
- hwmon_device_unregister(data->hwmon_dev);
- dev_set_drvdata(data->bmc_device, NULL);
-
device_remove_file(data->bmc_device,
&sensor_dev_attr_reset_high_low.dev_attr);
device_remove_file(data->bmc_device, &dev_attr_name.attr);
@@ -527,7 +521,8 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data)
}
list_del(&data->list);
-
+ dev_set_drvdata(data->bmc_device, NULL);
+ hwmon_device_unregister(data->hwmon_dev);
ipmi_destroy_user(data->user);
kfree(data->sensors);
kfree(data);
--
2.45.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Revert "hwmon: (ibmpex) fix use-after-free in high/low store"
2026-02-07 16:21 [PATCH] Revert "hwmon: (ibmpex) fix use-after-free in high/low store" Guenter Roeck
@ 2026-02-10 8:55 ` Jean Delvare
0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2026-02-10 8:55 UTC (permalink / raw)
To: Guenter Roeck, Hardware Monitoring; +Cc: Junrui Luo
Hi Guenter,
On Sat, 2026-02-07 at 08:21 -0800, Guenter Roeck wrote:
> This reverts commit 6946c726c3f4c36f0f049e6f97e88c510b15f65d.
>
> Jean Delvare points out that the patch does not completely
> fix the reported problem, that it in fact introduces a
> (new) race condition, and that it may actually not be needed in
> the first place.
>
> Various AI reviews agree. Specific and relevant AI feedback:
>
> "
> This reordering sets the driver data to NULL before removing the sensor
> attributes in the loop below.
>
> ibmpex_show_sensor() retrieves this driver data via dev_get_drvdata() but
> does not check if it is NULL before dereferencing it to access
> data->sensors[].
>
> If a userspace process reads a sensor file (like temp1_input) while this
> delete function is running, could it race with the dev_set_drvdata(...,
> NULL) call here and crash in ibmpex_show_sensor()?
>
> Would it be safer to keep the original order where device_remove_file() is
> called before clearing the driver data? device_remove_file() should wait
> for any active sysfs callbacks to complete, which might already prevent the
> use-after-free this patch intends to fix.
> "
>
> Revert the offending patch. If it can be shown that the originally reported
> alleged race condition does indeed exist, it can always be re-introduced
> with a complete fix.
>
> Reported-by: Jean Delvare <jdelvare@suse.de>
> Closes: https://lore.kernel.org/linux-hwmon/20260121095342.73e723cb@endymion/
> Cc: Jean Delvare <jdelvare@suse.de>
> Cc: Junrui Luo <moonafterrain@outlook.com>
> Fixes: 6946c726c3f4 ("hwmon: (ibmpex) fix use-after-free in high/low store")
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/hwmon/ibmpex.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c
> index 129f3a9e8fe9..228c5f6c6f38 100644
> --- a/drivers/hwmon/ibmpex.c
> +++ b/drivers/hwmon/ibmpex.c
> @@ -277,9 +277,6 @@ static ssize_t ibmpex_high_low_store(struct device *dev,
> {
> struct ibmpex_bmc_data *data = dev_get_drvdata(dev);
>
> - if (!data)
> - return -ENODEV;
> -
> ibmpex_reset_high_low_data(data);
>
> return count;
> @@ -511,9 +508,6 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data)
> {
> int i, j;
>
> - hwmon_device_unregister(data->hwmon_dev);
> - dev_set_drvdata(data->bmc_device, NULL);
> -
> device_remove_file(data->bmc_device,
> &sensor_dev_attr_reset_high_low.dev_attr);
> device_remove_file(data->bmc_device, &dev_attr_name.attr);
> @@ -527,7 +521,8 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data)
> }
>
> list_del(&data->list);
> -
> + dev_set_drvdata(data->bmc_device, NULL);
> + hwmon_device_unregister(data->hwmon_dev);
> ipmi_destroy_user(data->user);
> kfree(data->sensors);
> kfree(data);
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Thanks,
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-10 8:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-07 16:21 [PATCH] Revert "hwmon: (ibmpex) fix use-after-free in high/low store" Guenter Roeck
2026-02-10 8:55 ` Jean Delvare
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox