Skip to content

Commit

Permalink
HID: mcp-2221: prevent UAF in delayed work
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bentiss committed Feb 20, 2023
1 parent 0b02818 commit 47e91fd
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/hid/hid-mcp2221.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@ static void mcp2221_hid_unregister(void *ptr)
/* This is needed to be sure hid_hw_stop() isn't called twice by the subsystem */
static void mcp2221_remove(struct hid_device *hdev)
{
struct mcp2221 *mcp = hid_get_drvdata(hdev);

cancel_delayed_work_sync(&mcp->init_work);
}

#if IS_REACHABLE(CONFIG_IIO)
Expand Down

0 comments on commit 47e91fd

Please sign in to comment.