Re: [PATCH] HID: magicmouse: do not keep a stale msc->input if no input is claimed
[email protected] Wed, 29 Jul 2026 04:31:35 +0000
| Newsgroups | org.kernel.vger.linux-input |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Deterministic NULL pointer dereference in event handlers after a failed input registration. -- --- Patch [1]: [PATCH] HID: magicmouse: do not keep a stale msc->input if no input is claimed --- commit 6fea999082f28bca408072a6788f3616b0ebbd9f Author: Jose Villaseñor Montfort <[email protected]> HID: magicmouse: do not keep a stale msc->input if no input is claimed This patch clears msc->input when the HID core does not claim an input device. This is intended to ensure existing NULL checks safely handle the failure path where hidinput_connect() frees the input devices. Link: https://lore.kernel.org/linux-input/[email protected]/ > diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c > index 802a3479e24b9..2f14094a63b1e 100644 > --- a/drivers/hid/hid-magicmouse.c > +++ b/drivers/hid/hid-magicmouse.c > @@ -900,6 +900,16 @@ static int magicmouse_probe(struct hid_device *hdev, > return ret; > } > > + /* > + * When hidinput_connect() fails it frees every input device it > + * created, but that does not fail hid_hw_start(): the core simply > + * does not claim an input. msc->input, cached in ->input_mapping > + * while the report descriptor was parsed, would then be a dangling > + * pointer that passes every NULL check. Trust the core's claim. > + */ > + if (!(hdev->claimed & HID_CLAIMED_INPUT)) > + msc->input = NULL; > + [Severity: High] If msc->input is set to NULL here due to a failure, could this cause a NULL pointer dereference for certain USB devices? Looking further down in magicmouse_probe(), there is an early return on success for specific devices that bypasses the failure check: drivers/hid/hid-magicmouse.c:magicmouse_probe() { ... if (!(hdev->claimed & HID_CLAIMED_INPUT)) msc->input = NULL; ... if (is_usb_magicmouse2(id->vendor, id->product) || (is_usb_magictrackpad2(id->vendor, id->product) && hdev->type != HID_TYPE_USBMOUSE)) return 0; if (!msc->input) { hid_err(hdev, "magicmouse input not registered\n"); ... } If the probe succeeds by returning 0, the driver remains bound. When an input report is later received, will magicmouse_raw_event() and magicmouse_event() unconditionally dereference the NULL msc->input pointer? For example, looking at magicmouse_raw_event(): drivers/hid/hid-magicmouse.c:magicmouse_raw_event() { ... struct input_dev *input = msc->input; ... if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || ... } And similarly in magicmouse_event(): drivers/hid/hid-magicmouse.c:magicmouse_event() { ... struct magicmouse_sc *msc = hid_get_drvdata(hdev); if ((msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || ... } > if (is_usb_magicmouse2(id->vendor, id->product) || > is_usb_magictrackpad2(id->vendor, id->product)) { > timer_setup(&msc->battery_timer, magicmouse_battery_timer_tick, 0); -- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1