CVE-2022-50568
Description
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.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
In the Linux kernel's USB f_hid gadget driver, the cdev lifetime is not tied to the f_hidg struct, causing a use-after-free when the gadget is removed while /dev/hidgN is open.
Vulnerability
The Linux kernel's USB gadget function driver for HID (f_hid) contains a lifetime management flaw. The embedded struct cdev (character device) does not have its lifetime correctly tied to the enclosing struct f_hidg. This leads to a use-after-free condition if /dev/hidgN is held open while the USB gadget is deleted [1][2][3].
Exploitation
An attacker with local access to the system can exploit this by opening the /dev/hidgN device file (e.g., via exec 3<> /dev/hidg0) and then triggering the removal of the USB gadget (e.g., via gadget-vid-pid-remove). No special privileges beyond the ability to open the device file and trigger gadget removal are required, though the attacker must be able to interact with the USB gadget subsystem [1][2][3].
Impact
Successful exploitation results in a use-after-free, which can lead to memory corruption, system crash (denial of service), or potentially arbitrary code execution in kernel context. The vulnerability is rated with a CVSS score of 7.8 (High) [1][2][3].
Mitigation
The fix involves pulling the existing device object into struct f_hidg and using the cdev_device_{add,del}() helpers to properly tie the character device's lifetime to the gadget function. This ensures that the device object's lifetime matches struct f_hidg, preventing the use-after-free. The patch has been applied to the stable kernel tree [1][2][3].
AI Insight generated on May 19, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected products
1Patches
7d3136b79705c9e4b85d815b19e08b7f5fa0089ff3dfac6041cd7f156f638c78c87c4e3891b6a53e447ecVulnerability mechanics
Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
7- git.kernel.org/stable/c/1b6a53e447ec3d81623610c8c7ec5082b47dfdcenvd
- git.kernel.org/stable/c/1cd7f156f6389918f760687fbbf133c86da93162nvd
- git.kernel.org/stable/c/89ff3dfac604614287ad5aad9370c3f984ea3f4bnvd
- git.kernel.org/stable/c/9e08b7f5fa00e9d550851352bd0d1ba74ccffef2nvd
- git.kernel.org/stable/c/9e4b85d815b14bd4db2deea2a54264a23de8b896nvd
- git.kernel.org/stable/c/c78c87c4e389b62f8892af7f59857447aa6d9797nvd
- git.kernel.org/stable/c/d3136b79705c2e3bba9c76adc5628af0215d798envd
News mentions
0No linked articles in our index yet.