CVE-2026-98764: usb: gadget: f_fs: Fix NULL pointer dereference in FUNCTIONFS_ENDPOINT_DESC
In the Linux kernel, the following vulnerability has been resolved:
usb: gadget: ffs: Fix NULL pointer dereference in FUNCTIONFSENDPOINTDESC
When user space sets up FunctionFS with only full-speed descriptors (e.g., flags = FUNCTIONFSHASFSDESC) and the gadget operates at a higher speed (such as USBSPEEDHIGH or USBSPEEDSUPER), configepbyspeed() detects that the function lacks descriptors for the current speed, logs a warning, and falls back to full-speed descriptors. The endpoint is then successfully enabled via usbepenable(), and epfile->ep becomes valid.
However, when user space subsequently issues the FUNCTIONFSENDPOINTDESC ioctl to query the endpoint descriptor, ffsepfileioctl() selects the descriptor index solely based on gadget->speed:
switch (epfile->ffs->gadget->speed) { case USBSPEEDSUPER: case USBSPEEDSUPERPLUS: descidx = 2; break; case USBSPEEDHIGH: descidx = 1; break; default: descidx = 0; } desc = epfile->ep->descs[descidx]; memcpy(&desc1, desc, desc->bLength);
Because user space only supplied full-speed descriptors, epfile->ep->descs[1] is NULL. Dereferencing desc->bLength triggers an immediate kernel NULL pointer dereference panic.
Fix this by falling back through lower speed descriptors if the current speed descriptor was not supplied, matching the fallback logic in configepbyspeed() and historical ffs behavior. If still missing, fall back to epfile->ep->ep->desc (the active descriptor), and return -EINVAL safely if no valid descriptor is found. In addition, mark desc as const to match struct usbep::desc and avoid discarding qualifiers.