CVE-2026-138844: usb: core: don't set drvdata to NULL in usb_unbind_interface()
In the Linux kernel, the following vulnerability has been resolved:
usb: core: don't set drvdata to NULL in usbunbindinterface()
usbunbindinterface() serves as the remove() callback of struct usbdriver and calls usbsetintfdata(intf, NULL) to clear the bus device private data pointer.
However, the driver core code already sets the bus device private data pointer to NULL in deviceunbindcleanup() after devresreleaseall(), which makes the call redundant.
In addition, it can create unexpected NULL pointer dereference scenarios when drivers use managed APIs.
int probe(struct usbinterface intf, const struct usbdeviceid id) { struct data data; int ret;
data = devmkzalloc(&intf->dev, sizeof(data), GFPKERNEL); if (!data) return -ENOMEM;
ret = devmdeviceaddgroup(&intf->dev, &fooattrgroup); if (ret) return ret;
... }
ssizet foovalueshow(struct device dev, struct deviceattribute attr, char buf) { struct usbinterface intf = tousbinterface(dev); struct data data = usbgetintfdata(intf);
/ Potential NULL pointer dereference / return sysfsemit(buf, "%u\n", data->value); }
Nothing prevents usbunbindinterface() to race with foovalueshow() and set usbsetintfdata(intf, NULL).
The same applies to the unwind path of usbprobeinterface(), which also calls usbsetintfdata(intf, NULL).
Besides that, the Rust driver core code manages a driver's bus device private data and destroys it in deviceunbindcleanup().
If usbunbindinterface() sets the pointer to NULL prematurely, the Rust driver core code sees NULL, and hence skips the destructor of the bus device private data, which leaks all its resources.
Thus, drop usbsetintfdata(intf, NULL) from usbprobeinterface() and usbunbindinterface(), and move it to usbdriverreleaseinterface(), which manually calls the remove() callback of struct usbdriver and hence can't rely on the driver core.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
Do not clear the USB interface driver data in usb_unbind_interface(); move usb_set_intfdata(intf, NULL) to usb_driver_release_interface().
Event History
Frequently Asked Questions
Which drivers are exposed to the NULL dereference race?
The issue affects USB interface drivers that use managed APIs and have callbacks, such as sysfs attribute handlers, that retrieve driver state with usb_get_intfdata(). A callback can observe a NULL pointer if it runs while the interface is being unbound.
What must occur for the failure to happen?
usb_unbind_interface() must race with a handler that reads the interface private-data pointer. In the example, foo_value_show() reads usb_get_intfdata() after unbind has cleared it, then dereferences the resulting NULL data pointer.
How can I assess whether a driver is affected?
Review USB interface driver callbacks that call usb_get_intfdata(), especially sysfs handlers backed by managed resources. They are potentially affected if they can execute concurrently with interface removal or unbinding and dereference the returned pointer without handling NULL.