Skip to contentSkip to conversation

HID: magicmouse: fix null pointer dereference in magicmouse_event()

PATCH Superseded Nehuen Lian Bova 2 participants 3 messages Oct 3 – Oct 16 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: magicmouse: fix null pointer dereference in magicmouse_event()

Add a guard clause to check if 'msc' is NULL before attempting to access its fields, preventing a general protection fault.

Fixes b8d56ef91cc3 ("HID: magicmouse: Apple Magic Mouse 2 USB-C support")
Reported-by [email protected]
---
 drivers/hid/hid-magicmouse.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hid/hid-magicmouse.c +4 -0
index d637c0477379..85454250355f 100644
@@ -553,6 +553,10 @@ static int magicmouse_event(struct hid_device *hdev, struct hid_field *field,
 		struct hid_usage *usage, __s32 value)
 {
 	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
+
+	if (!msc)
+		return 0;
+
 	if ((msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
 	     msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) &&
 	    field->report->id == MOUSE2_REPORT_ID) {
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/1 HID: magicmouse: fix null pointer dereference in magicmouse_event()

Add a guard clause to check if 'msc' and 'msc->input' is NULL before attempting to access its fields, preventing a general protection fault.

Fixes b8d56ef91cc3 ("HID: magicmouse: Apple Magic Mouse 2 USB-C support")
Reported-by [email protected]

---
Changes in v2:
- Also check msc->input before dereferencing it, not just msc

 drivers/hid/hid-magicmouse.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hid/hid-magicmouse.c +4 -0
index d637c0477379..e6d4d4930526 100644
@@ -553,6 +553,10 @@ static int magicmouse_event(struct hid_device *hdev, struct hid_field *field,
 		struct hid_usage *usage, __s32 value)
 {
 	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
+
+	if (!msc || !msc->input)
+		return 0;
+
 	if ((msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
 	     msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) &&
 	    field->report->id == MOUSE2_REPORT_ID) {
Signature · 1 line
2.43.0
maintainer Applied
#2 lore raw
Quoted 8 lines · Nehuen Lian Bova

Add a guard clause to check if 'msc' and 'msc->input' is NULL before attempting to access its fields, preventing a general protection fault.

Fixes b8d56ef91cc3 ("HID: magicmouse: Apple Magic Mouse 2 USB-C support")
Reported-by [email protected]

Applied, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs