Skip to contentSkip to conversation

HID: magicmouse: fix crash when disconnecting Magic Trackpad 2

PATCH Superseded José Expósito 2 participants 3 messages May 9, 2021 – May 26, 2021 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: magicmouse: fix crash when disconnecting Magic Trackpad 2

When the Apple Magic Trackpad 2 is connected over USB it registers four hid_device interfaces, however, the driver only handles the one with type HID_TYPE_USBMOUSE and ignores the other three, thus, no driver data is attached to them.

When the device is disconnected, the remove method is called for the four hid_device interfaces, crashing when the driver data is NULL.

Check that the driver data is not NULL before using it on the remove callback.

---
 linux/drivers/hid/hid-magicmouse.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
linux/drivers/hid/hid-magicmouse.c +4 -1
index 2bb473d..097870e 100644
@@ -779,7 +779,10 @@ err_stop_hw:
 static void magicmouse_remove(struct hid_device *hdev)
 {
 	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
-	cancel_delayed_work_sync(&msc->work);
+
+	if (msc)
+		cancel_delayed_work_sync(&msc->work);
+
 	hid_hw_stop(hdev);
 }
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/1 HID: magicmouse: fix crash when disconnecting Magic Trackpad 2

When the Apple Magic Trackpad 2 is connected over USB it registers four hid_device report descriptors, however, the driver only handles the one with type HID_TYPE_USBMOUSE and ignores the other three, thus, no driver data is attached to them.

When the device is disconnected, the remove callback is called for the four hid_device report descriptors, crashing when the driver data is NULL.

Check that the driver data is not NULL before using it in the remove callback.

---
 drivers/hid/hid-magicmouse.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hid/hid-magicmouse.c +4 -1
index 2bb473d8c424..097870e43cfe 100644
@@ -779,7 +779,10 @@ static int magicmouse_probe(struct hid_device *hdev,
 static void magicmouse_remove(struct hid_device *hdev)
 {
 	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
-	cancel_delayed_work_sync(&msc->work);
+
+	if (msc)
+		cancel_delayed_work_sync(&msc->work);
+
 	hid_hw_stop(hdev);
 }
 
Signature · 1 line
2.25.1
maintainer Applied
#2 lore raw
Quoted 11 lines · José Expósito

When the Apple Magic Trackpad 2 is connected over USB it registers four hid_device report descriptors, however, the driver only handles the one with type HID_TYPE_USBMOUSE and ignores the other three, thus, no driver data is attached to them.

When the device is disconnected, the remove callback is called for the four hid_device report descriptors, crashing when the driver data is NULL.

Check that the driver data is not NULL before using it in the remove callback.

Applied, thank you.

Signature · 2 lines
Jiri Kosina
SUSE Labs