Skip to content

Commit 47e91fd

Browse files
committed
HID: mcp-2221: prevent UAF in delayed work
If the device is plugged/unplugged without giving time for mcp_init_work() to complete, we might kick in the devm free code path and thus have unavailable struct mcp_2221 while in delayed work. Canceling the delayed_work item is enough to solve the issue, because cancel_delayed_work_sync will prevent the work item to requeue itself. Fixes: 960f9df ("HID: mcp2221: add ADC/DAC support via iio subsystem") CC: [email protected] Acked-by: Jiri Kosina <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 0b02818 commit 47e91fd

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/hid/hid-mcp2221.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,9 @@ static void mcp2221_hid_unregister(void *ptr)
922922
/* This is needed to be sure hid_hw_stop() isn't called twice by the subsystem */
923923
static void mcp2221_remove(struct hid_device *hdev)
924924
{
925+
struct mcp2221 *mcp = hid_get_drvdata(hdev);
926+
927+
cancel_delayed_work_sync(&mcp->init_work);
925928
}
926929

927930
#if IS_REACHABLE(CONFIG_IIO)

0 commit comments

Comments
 (0)