Re: [PATCH] HID: magicmouse: reject devices that bind without an input device
Alec Hall <[email protected]>
| Newsgroups | org.kernel.vger.linux-input,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Jul 15, 2026, Jose Villaseñor Montfort wrote: > Move the msc->input check ahead of the early return so it covers every > bind path. Legitimate devices register an input during hid_hw_start() > and are unaffected. The second half of that turns out not to hold on real hardware. A USB Magic Trackpad 2 exposes four HID interfaces, and only the first two register an input; interfaces 2 and 3 are vendor-defined, hiddev/hidraw only. With this patch applied (stacked on the pending battery series, kernel 7.1.5), plugging in a Magic Trackpad 2 over USB rejects both of them: magicmouse 0003:05AC:0265.001F: magicmouse input not registered magicmouse 0003:05AC:0265.0020: magicmouse input not registered I confirmed with a temporary printk in probe that interfaces 2/3 reach the moved check with msc->input == NULL and hdev->claimed == 0x6 (hiddev|hidraw, no input), while interfaces 0/1 probe with an input and claimed == 0x7 and keep working, battery included. The rejected interfaces then end up bound to nothing -- hid-generic declines them because a specific driver matches the ID -- so their hidraw nodes disappear, and every cable plug logs two -ENOMEM probe failures for a healthy device. Nothing user-facing breaks (touch and battery live on interfaces 0/1), but the driver has claimed those interfaces ever since 0b91b4e4dae6, and silently unbinding them with an error doesn't seem right for a stable-tagged fix. Bluetooth is unaffected: that path already required an input before the early return, and a Magic Trackpad 2 + Magic Keyboard over BT show no change with this patch. > I went with fixing the probe path (rejecting a bind without an input) > rather than adding per-callback "if (!msc->input) return 0;" guards, > since a single check at probe covers both ->raw_event and ->event and > addresses the root asymmetry. Happy to switch to per-callback guards if > reviewers prefer that. Given the above I think the per-callback guard is the better shape after all: it keeps the legitimate input-less USB interfaces bound exactly as today, while still closing the NULL deref in ->raw_event/->event -- and those interfaces demonstrate that a bind with msc->input == NULL is a state real devices reach, not only spoofed ones. Happy to re-test a v2 on the same hardware over both USB and Bluetooth.