Skip to contentSkip to conversation

HID: hid-steam: Fix use-after-free when detaching device

PATCH Applied Vicki Pfau 2 participants 2 messages Feb 27, 2025 – Mar 4, 2025

Subsystems (2)
lore
Share & tools
lore

Vicki Pfau

author maintainer
#0 lore raw

PATCH 1/1 HID: hid-steam: Fix use-after-free when detaching device

When a hid-steam device is removed it must clean up the client_hdev used for intercepting hidraw access. This can lead to scheduling deferred work to reattach the input device. Though the cleanup cancels the deferred work, this was done before the client_hdev itself is cleaned up, so it gets rescheduled. This patch fixes the ordering to make sure the deferred work is properly canceled.

Reported-by [email protected]
Fixes 79504249d7e2 ("HID: hid-steam: Move hidraw input (un)registering to work")
---
 drivers/hid/hid-steam.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-steam.c +1 -1
index c9e65e9088b3..10460b7bde1a 100644
@@ -1327,11 +1327,11 @@ static void steam_remove(struct hid_device *hdev)
 		return;
 	}
 
+	hid_destroy_device(steam->client_hdev);
 	cancel_delayed_work_sync(&steam->mode_switch);
 	cancel_work_sync(&steam->work_connect);
 	cancel_work_sync(&steam->rumble_work);
 	cancel_work_sync(&steam->unregister_work);
-	hid_destroy_device(steam->client_hdev);
 	steam->client_hdev = NULL;
 	steam->client_opened = 0;
 	if (steam->quirks & STEAM_QUIRK_WIRELESS) {
Signature · 1 line
2.48.1
maintainer Applied
#1 lore raw
Quoted 10 lines · Vicki Pfau

When a hid-steam device is removed it must clean up the client_hdev used for intercepting hidraw access. This can lead to scheduling deferred work to reattach the input device. Though the cleanup cancels the deferred work, this was done before the client_hdev itself is cleaned up, so it gets rescheduled. This patch fixes the ordering to make sure the deferred work is properly canceled.

Reported-by [email protected]
Fixes 79504249d7e2 ("HID: hid-steam: Move hidraw input (un)registering to work")

Applied to hid.git#for-6.14/upstream-fixes. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs