Skip to content

Commit 08e57f5

Browse files
Sanman Pradhangroeck
authored andcommitted
hwmon: (powerz) Fix use-after-free on USB disconnect
After powerz_disconnect() frees the URB and releases the mutex, a subsequent powerz_read() call can acquire the mutex and call powerz_read_data(), which dereferences the freed URB pointer. Fix by: - Setting priv->urb to NULL in powerz_disconnect() so that powerz_read_data() can detect the disconnected state. - Adding a !priv->urb check at the start of powerz_read_data() to return -ENODEV on a disconnected device. - Moving usb_set_intfdata() before hwmon registration so the disconnect handler can always find the priv pointer. Fixes: 4381a36 ("hwmon: add POWER-Z driver") Cc: stable@vger.kernel.org Signed-off-by: Sanman Pradhan <psanman@juniper.net> Link: https://lore.kernel.org/r/20260410002521.422645-2-sanman.pradhan@hpe.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent a2981c2 commit 08e57f5

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

drivers/hwmon/powerz.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ static int powerz_read_data(struct usb_device *udev, struct powerz_priv *priv)
108108
{
109109
int ret;
110110

111+
if (!priv->urb)
112+
return -ENODEV;
113+
111114
priv->status = -ETIMEDOUT;
112115
reinit_completion(&priv->completion);
113116

@@ -224,6 +227,8 @@ static int powerz_probe(struct usb_interface *intf,
224227
mutex_init(&priv->mutex);
225228
init_completion(&priv->completion);
226229

230+
usb_set_intfdata(intf, priv);
231+
227232
hwmon_dev =
228233
devm_hwmon_device_register_with_info(parent, DRIVER_NAME, priv,
229234
&powerz_chip_info, NULL);
@@ -232,8 +237,6 @@ static int powerz_probe(struct usb_interface *intf,
232237
return PTR_ERR(hwmon_dev);
233238
}
234239

235-
usb_set_intfdata(intf, priv);
236-
237240
return 0;
238241
}
239242

@@ -244,6 +247,7 @@ static void powerz_disconnect(struct usb_interface *intf)
244247
mutex_lock(&priv->mutex);
245248
usb_kill_urb(priv->urb);
246249
usb_free_urb(priv->urb);
250+
priv->urb = NULL;
247251
mutex_unlock(&priv->mutex);
248252
}
249253

0 commit comments

Comments
 (0)