HID: mcp-2221: prevent UAF in delayed work
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>
Thu, 16 Feb 2023 10:22:58 +0000 (11:22 +0100)
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>
Mon, 20 Feb 2023 09:21:01 +0000 (10:21 +0100)
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: 960f9df7c620 ("HID: mcp2221: add ADC/DAC support via iio subsystem")
CC: stable@vger.kernel.org
Acked-by: Jiri Kosina <jkosina@suse.cz>
Link: https://lore.kernel.org/r/20230215-wip-mcp2221-v2-1-109f71fd036e@redhat.com
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
drivers/hid/hid-mcp2221.c

index e61dd039354b8f72750855f52da8a0b40d91f304..f74a977cf8f873c421de623a4d8f152a217de85c 100644 (file)
@@ -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)