CVE-2022-50568 usb: gadget: f_hid: fix f_hidg lifetime vs cdev
A use-after-free in the Linux kernel USB HID gadget driver allows local attackers to cause denial of service or escalate privileges by holding a device open during gadget deletion.
- Exploited in the wild
- Not known
- Login needed
- Any signed-in user
- Attackable
- Local or same network only
- Victim action needed
- Not needed
- Fix
- Available
What is CVE-2022-50568?
CVE-2022-50568 is an use after free vulnerability in Linux, published on 22 Oct 2025. It can only be exploited from the same machine or local network, with no action from the victim.
Official 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.
Which versions are affected by CVE-2022-50568?
How do I fix CVE-2022-50568?
Apply the vendor's patch.
Upgrade to the fixed version. These bugs are found with fuzzing and sanitisers and avoided by memory-safe languages. More about Use after free.
Is CVE-2022-50568 being exploited?
There is no known exploitation of CVE-2022-50568 in the wild and no public exploit code.
Sources
Also known as DEBIAN-CVE-2022-50568, GHSA-4jrv-w6c6-f8r5, UBUNTU-CVE-2022-50568.