{"id":"CVE-2022-49398","state":"PUBLISHED","title":"usb: dwc3: gadget: Replace list_for_each_entry_safe() if using giveback","description":"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","publishedAt":"2025-02-26T02:12:27.141Z","updatedAt":"2026-05-23T15:22:06.437Z","severity":null,"assigner":"Linux","products":["Linux Linux"],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"d4f1afe5e896c18ae01099a85dab5e1a198bd2a8","status":"affected","lessThan":"1c6e5dc3b639c96e6839a8d1b8e951923fdfd34a","versionType":"git"},{"version":"d4f1afe5e896c18ae01099a85dab5e1a198bd2a8","status":"affected","lessThan":"2424307cdf421ac72075a1384eae4e4199ab6457","versionType":"git"},{"version":"d4f1afe5e896c18ae01099a85dab5e1a198bd2a8","status":"affected","lessThan":"26a7e6832afe9d9a991cfd9015177f083cf959cc","versionType":"git"},{"version":"d4f1afe5e896c18ae01099a85dab5e1a198bd2a8","status":"affected","lessThan":"bf594d1d0c1d7b895954018043536ffd327844f9","versionType":"git"},{"version":"d7ff2e3ff0e09d57b43014fe26b13bb3c9677254","status":"affected","versionType":"git"},{"version":"4.19.57","status":"affected","lessThan":"4.20","versionType":"semver"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/usb/dwc3/gadget.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"5.0","status":"affected"},{"version":"0","status":"unaffected","lessThan":"5.0","versionType":"semver"},{"version":"5.15.47","status":"unaffected","lessThanOrEqual":"5.15.*","versionType":"semver"},{"version":"5.17.15","status":"unaffected","lessThanOrEqual":"5.17.*","versionType":"semver"},{"version":"5.18.4","status":"unaffected","lessThanOrEqual":"5.18.*","versionType":"semver"},{"version":"5.19","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/usb/dwc3/gadget.c"]}],"references":["https://git.kernel.org/stable/c/1c6e5dc3b639c96e6839a8d1b8e951923fdfd34a","https://git.kernel.org/stable/c/2424307cdf421ac72075a1384eae4e4199ab6457","https://git.kernel.org/stable/c/26a7e6832afe9d9a991cfd9015177f083cf959cc","https://git.kernel.org/stable/c/bf594d1d0c1d7b895954018043536ffd327844f9"],"weaknesses":[],"ingestedAt":"2026-10-29T20:05:26.763Z","source":{"repository":"CVEProject/cvelistV5","path":"cves/2022/49xxx/CVE-2022-49398.json","commit":"556c9d3a8cd17e218bb8e452ba7cd619a384ff47"},"raw":{"dataType":"CVE_RECORD","dataVersion":"5.2","cveMetadata":{"cveId":"CVE-2022-49398","state":"PUBLISHED","datePublished":"2025-02-26T02:12:27.141Z","dateUpdated":"2026-05-23T15:22:06.437Z","assignerShortName":"Linux","assignerOrgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateReserved":"2025-02-26T02:08:31.563Z"},"containers":{"cna":{"title":"usb: dwc3: gadget: Replace list_for_each_entry_safe() if using giveback","descriptions":[{"lang":"en","value":"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"}],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"d4f1afe5e896c18ae01099a85dab5e1a198bd2a8","status":"affected","lessThan":"1c6e5dc3b639c96e6839a8d1b8e951923fdfd34a","versionType":"git"},{"version":"d4f1afe5e896c18ae01099a85dab5e1a198bd2a8","status":"affected","lessThan":"2424307cdf421ac72075a1384eae4e4199ab6457","versionType":"git"},{"version":"d4f1afe5e896c18ae01099a85dab5e1a198bd2a8","status":"affected","lessThan":"26a7e6832afe9d9a991cfd9015177f083cf959cc","versionType":"git"},{"version":"d4f1afe5e896c18ae01099a85dab5e1a198bd2a8","status":"affected","lessThan":"bf594d1d0c1d7b895954018043536ffd327844f9","versionType":"git"},{"version":"d7ff2e3ff0e09d57b43014fe26b13bb3c9677254","status":"affected","versionType":"git"},{"version":"4.19.57","status":"affected","lessThan":"4.20","versionType":"semver"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/usb/dwc3/gadget.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"5.0","status":"affected"},{"version":"0","status":"unaffected","lessThan":"5.0","versionType":"semver"},{"version":"5.15.47","status":"unaffected","lessThanOrEqual":"5.15.*","versionType":"semver"},{"version":"5.17.15","status":"unaffected","lessThanOrEqual":"5.17.*","versionType":"semver"},{"version":"5.18.4","status":"unaffected","lessThanOrEqual":"5.18.*","versionType":"semver"},{"version":"5.19","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/usb/dwc3/gadget.c"]}],"references":[{"url":"https://git.kernel.org/stable/c/1c6e5dc3b639c96e6839a8d1b8e951923fdfd34a"},{"url":"https://git.kernel.org/stable/c/2424307cdf421ac72075a1384eae4e4199ab6457"},{"url":"https://git.kernel.org/stable/c/26a7e6832afe9d9a991cfd9015177f083cf959cc"},{"url":"https://git.kernel.org/stable/c/bf594d1d0c1d7b895954018043536ffd327844f9"}],"providerMetadata":{"shortName":"Linux","orgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateUpdated":"2026-05-23T15:22:06.437Z"},"cpeApplicability":[{"nodes":[{"operator":"OR","negate":false,"cpeMatch":[{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"5.0","versionEndExcluding":"5.15.47"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"5.0","versionEndExcluding":"5.17.15"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"5.0","versionEndExcluding":"5.18.4"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"5.0","versionEndExcluding":"5.19"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"4.19.57"}]}]}],"x_generator":{"engine":"bippy-1.2.0"}}}}}