History

hwmon: (corsair-cpro) Remove debugfs entries when probe fails

ccp_debugfs_init() registers debugfs files whose private data is the devm allocated ccp. If hwmon_device_register_with_info() fails right after it, ccp_probe() returns without removing them: the HID core then frees ccp, and ccp_remove() is not called for a failed probe, so the files stay behind. Reading one of them dereferences the freed pointer. Remove the debugfs entries on that error path. debugfs_remove_recursive() waits for readers already inside the show callbacks, so ccp is no longer reachable through debugfs by the time probe returns.

Linmao Li committed 2 months ago

Commit 4ee875c1 parent 09a9e171 file · +3 −1Browse files

Unified · Split

drivers/hwmon/corsair-cpro.c+3−1
@@ -642,13 +642,15 @@ static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id) · 641 unmodified lines
642642 ccp, &ccp_chip_info, NULL);
643643 if (IS_ERR(ccp->hwmon_dev)) {
644644 ret = PTR_ERR(ccp->hwmon_dev);
645− goto out_hw_close;
645+ goto out_debugfs_remove;
646646 }
647647
648648 ccp_debugfs_init(ccp, fw_valid, bl_valid);
649649
650650 return 0;
651651
652+out_debugfs_remove:
653+ debugfs_remove_recursive(ccp->debugfs);
652654 out_hw_close:
653655 hid_hw_close(hdev);
654656 hid_device_io_stop(hdev);