usb: gadget: f_hid: fix f_hidg lifetime vs cdev
Linux
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
Linux
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
≥ 71adf118946957839a13aa4d1094183e05c6c094 · < 9e08b7f5fa00e9d550851352bd0d1ba74ccffef2| No fix yet |
| Linux Linux |
|
|
In the Linux kernel, the following vulnerability has been resolved:
usb: gadget: f_hid: fix f_hidg lifetime vs cdev
The embedded struct cdev does not have its lifetime correctly tied to the enclosing struct f_hidg, so there is a use-after-free if /dev/hidgN is held open while the gadget is deleted.
This can readily be replicated with libusbgx's example programs (for conciseness - operating directly via configfs is equivalent):
gadget-hid exec 3<> /dev/hidg0 gadget-vid-pid-remove exec 3<&-
Pull the existing device up in to struct f_hidg and make use of the cdev_device_{add,del}() helpers. This changes the lifetime of the device object to match struct f_hidg, but note that it is still added and deleted at the same time.
From the CVE record · Linux
The Linux kernel USB HID gadget has a device-lifetime flaw. A local user can trigger a use-after-free if /dev/hidgN remains open while the gadget is deleted; no network access is involved.
Engineers running Linux kernels with the USB HID gadget should check whether their kernel is affected; affected versions were not provided.