In the Linux kernel, the following vulnerability has been resolved:
HID: universal-pidff: stop the device when force-feedback init fails
universalpidffprobe() starts the device with hidhwstart() and then, if force-feedback initialisation fails, returns the error through a label that only does "return error". The device is left started.
The HID core does not unwind on the driver's behalf. hiddeviceprobe() releases the devres group, closes the report and clears hdev->driver:
if (ret) { devresreleasegroup(&hdev->dev, hdev->devresgroupid); hidclosereport(hdev); hdev->driver = NULL; }
The hidraw character device that hidhwstart() registered through hidconnect() is allocated with kzalloc() and added with cdevdeviceadd(), so it is not devres-managed and survives that. With hdev->driver NULL, hiddeviceremove() skips hidhwstop() as well, because it only unwinds while a driver is still attached. The registration therefore outlives the device on both paths.
Opening the surviving /dev/hidrawX writes into freed memory. KASAN reports a use-after-free write from hidrawopen() -> hidhwopen() -> the transport's open callback, which takes a spinlock inside the freed object. A descriptor that carries a PID usage page and no input reports is enough: hidraw claims the device so hidhwstart() succeeds, while hid->inputs stays empty so force-feedback init fails. The other failure returns in hidpidffinitwithquirks() - no output reports, an allocation failure, pidffinitfields(), pidffcheckautocenter(), an unusable effect count, inputffcreate() - all reach the same label.
Stop the device on that path. hid-dr.c and hid-emsff.c, which start the device with the same HIDCONNECTDEFAULT & ~HIDCONNECTFF mask, already do this. The two earlier gotos must keep returning without hidhwstop(), since neither has a started device, so give the path that fails after the start its own label.
Discovered by XBOW, triaged by Baul Lee <baul.lee@xbow.com>