{"id":"CVE-2022-49398","published":"2025-02-26T02:12:27Z","modified":"2026-05-23T15:22:06Z","title":"usb: dwc3: gadget: Replace list_for_each_entry_safe() if using giveback","vendor":"Linux","product":"Linux","tier":"tail","description":{"text":"In the Linux kernel, the following vulnerability has been resolved:\n\nusb: dwc3: gadget: Replace list_for_each_entry_safe() if using giveback\n\nThe list_for_each_entry_safe() macro saves the current item (n) and\nthe item after (n+1), so that n can be safely removed without\ncorrupting the list.  However, when traversing the list and removing\nitems using gadget giveback, the DWC3 lock is briefly released,\nallowing other routines to execute.  There is a situation where, while\nitems are being removed from the cancelled_list using\ndwc3_gadget_ep_cleanup_cancelled_requests(), the pullup disable\nroutine is running in parallel (due to UDC unbind).  As the cleanup\nroutine removes n, and the pullup disable removes n+1, once the\ncleanup retakes the DWC3 lock, it references a request who was already\nremoved/handled.  With list debug enabled, this leads to a panic.\nEnsure all instances of the macro are replaced where gadget giveback\nis used.\n\nExample call stack:\n\nThread#1:\n__dwc3_gadget_ep_set_halt() - CLEAR HALT\n  -> dwc3_gadget_ep_cleanup_cancelled_requests()\n    ->list_for_each_entry_safe()\n    ->dwc3_gadget_giveback(n)\n      ->dwc3_gadget_del_and_unmap_request()- n deleted[cancelled_list]\n      ->spin_unlock\n      ->Thread#2 executes\n      ...\n    ->dwc3_gadget_giveback(n+1)\n      ->Already removed!\n\nThread#2:\ndwc3_gadget_pullup()\n  ->waiting for dwc3 spin_lock\n  ...\n  ->Thread#1 released lock\n  ->dwc3_stop_active_transfers()\n    ->dwc3_remove_requests()\n      ->fetches n+1 item from cancelled_list (n removed by Thread#1)\n      ->dwc3_gadget_giveback()\n        ->dwc3_gadget_del_and_unmap_request()- n+1 deleted[cancelled_list]\n        ->spin_unlock","provenance":"source","from":"CVE.org"},"cvss":null,"epss":{"score":0.00268,"percentile":0.18804,"provenance":"source"},"cwes":[],"references":[{"url":"https://git.kernel.org/stable/c/1c6e5dc3b639c96e6839a8d1b8e951923fdfd34a","tags":[]},{"url":"https://git.kernel.org/stable/c/2424307cdf421ac72075a1384eae4e4199ab6457","tags":[]},{"url":"https://git.kernel.org/stable/c/26a7e6832afe9d9a991cfd9015177f083cf959cc","tags":[]},{"url":"https://git.kernel.org/stable/c/bf594d1d0c1d7b895954018043536ffd327844f9","tags":[]}],"priority":{"score":3.8,"factors":[{"name":"EPSS percentile","points":3.76}]},"vendorSlug":"linux","affectedVersions":[{"vendor":"Linux","product":"Linux","versions":[">= d4f1afe5e896c18ae01099a85dab5e1a198bd2a8, < 1c6e5dc3b639c96e6839a8d1b8e951923fdfd34a",">= d4f1afe5e896c18ae01099a85dab5e1a198bd2a8, < 2424307cdf421ac72075a1384eae4e4199ab6457",">= d4f1afe5e896c18ae01099a85dab5e1a198bd2a8, < 26a7e6832afe9d9a991cfd9015177f083cf959cc",">= d4f1afe5e896c18ae01099a85dab5e1a198bd2a8, < bf594d1d0c1d7b895954018043536ffd327844f9","d7ff2e3ff0e09d57b43014fe26b13bb3c9677254",">= 4.19.57, < 4.20"]},{"vendor":"Linux","product":"Linux","versions":["5.0"]}],"euvd":{"id":"EUVD-2022-54831","exploited":false,"provenance":"source"}}