Jiri Slaby 902601
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Jiri Slaby 902601
Date: Thu, 16 Feb 2023 11:22:58 +0100
Jiri Slaby 902601
Subject: [PATCH] HID: mcp-2221: prevent UAF in delayed work
Jiri Slaby 902601
References: bsc#1012628
Jiri Slaby 902601
Patch-mainline: 6.2.1
Jiri Slaby 902601
Git-commit: 47e91fdfa511139f2549687edb0d8649b123227b
Jiri Slaby 902601
Jiri Slaby 902601
commit 47e91fdfa511139f2549687edb0d8649b123227b upstream.
Jiri Slaby 902601
Jiri Slaby 902601
If the device is plugged/unplugged without giving time for mcp_init_work()
Jiri Slaby 902601
to complete, we might kick in the devm free code path and thus have
Jiri Slaby 902601
unavailable struct mcp_2221 while in delayed work.
Jiri Slaby 902601
Jiri Slaby 902601
Canceling the delayed_work item is enough to solve the issue, because
Jiri Slaby 902601
cancel_delayed_work_sync will prevent the work item to requeue itself.
Jiri Slaby 902601
Jiri Slaby 902601
Fixes: 960f9df7c620 ("HID: mcp2221: add ADC/DAC support via iio subsystem")
Jiri Slaby 902601
CC: stable@vger.kernel.org
Jiri Slaby 902601
Acked-by: Jiri Kosina <jkosina@suse.cz>
Jiri Slaby 902601
Link: https://lore.kernel.org/r/20230215-wip-mcp2221-v2-1-109f71fd036e@redhat.com
Jiri Slaby 902601
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Jiri Slaby 902601
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Jiri Slaby 902601
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Jiri Slaby 902601
---
Jiri Slaby 902601
 drivers/hid/hid-mcp2221.c | 3 +++
Jiri Slaby 902601
 1 file changed, 3 insertions(+)
Jiri Slaby 902601
Jiri Slaby 902601
diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
Jiri Slaby 902601
index e61dd039..f74a977c 100644
Jiri Slaby 902601
--- a/drivers/hid/hid-mcp2221.c
Jiri Slaby 902601
+++ b/drivers/hid/hid-mcp2221.c
Jiri Slaby 902601
@@ -922,6 +922,9 @@ static void mcp2221_hid_unregister(void *ptr)
Jiri Slaby 902601
 /* This is needed to be sure hid_hw_stop() isn't called twice by the subsystem */
Jiri Slaby 902601
 static void mcp2221_remove(struct hid_device *hdev)
Jiri Slaby 902601
 {
Jiri Slaby 902601
+	struct mcp2221 *mcp = hid_get_drvdata(hdev);
Jiri Slaby 902601
+
Jiri Slaby 902601
+	cancel_delayed_work_sync(&mcp->init_work);
Jiri Slaby 902601
 }
Jiri Slaby 902601
 
Jiri Slaby 902601
 #if IS_REACHABLE(CONFIG_IIO)
Jiri Slaby 902601
-- 
Jiri Slaby 902601
2.35.3
Jiri Slaby 902601