Skip to content

Commit 09bd3f3

Browse files
groeckopsiff
authored andcommitted
Revert "hwmon: (ibmpex) fix use-after-free in high/low store"
[ Upstream commit 8bde3e3 ] This reverts commit 6946c72. 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: 6946c72 ("hwmon: (ibmpex) fix use-after-free in high/low store") Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit f448acd86835a650f9ea83460b9ca347d3aafba5) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent b0af98f commit 09bd3f3

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

drivers/hwmon/ibmpex.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@ static ssize_t ibmpex_high_low_store(struct device *dev,
282282
{
283283
struct ibmpex_bmc_data *data = dev_get_drvdata(dev);
284284

285-
if (!data)
286-
return -ENODEV;
287-
288285
ibmpex_reset_high_low_data(data);
289286

290287
return count;
@@ -517,9 +514,6 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data)
517514
{
518515
int i, j;
519516

520-
hwmon_device_unregister(data->hwmon_dev);
521-
dev_set_drvdata(data->bmc_device, NULL);
522-
523517
device_remove_file(data->bmc_device,
524518
&sensor_dev_attr_reset_high_low.dev_attr);
525519
device_remove_file(data->bmc_device, &sensor_dev_attr_name.dev_attr);
@@ -533,7 +527,8 @@ static void ibmpex_bmc_delete(struct ibmpex_bmc_data *data)
533527
}
534528

535529
list_del(&data->list);
536-
530+
dev_set_drvdata(data->bmc_device, NULL);
531+
hwmon_device_unregister(data->hwmon_dev);
537532
ipmi_destroy_user(data->user);
538533
kfree(data->sensors);
539534
kfree(data);

0 commit comments

Comments
 (0)