In the Linux kernel, the following vulnerability has been resolved:
usb: gadget: ffs: Fix race between aiocancel() and AIO request complete
FFS based applications can utilize the aio_cancel() callback to dequeue pending USB requests submitted to the UDC. There is a scenario where the FFS application issues an AIO cancel call, while the UDC is handling a soft disconnect. For a DWC3 based implementation, the callstack looks like the following:
DWC3 Gadget                               FFS Application
dwc3gadgetsoftdisconnect() ... --> dwc3stopactivetransfers() --> dwc3gadgetgiveback(-ESHUTDOWN) --> ffsepfileasynciocomplete() ffsaiocancel() --> usbepfreerequest() --> usbep_dequeue()
There is currently no locking implemented between the AIO completion handler and AIO cancel, so the issue occurs if the completion routine is running in parallel to an AIO cancel call coming from the FFS application. As the completion call frees the USB request (iodata->req) the FFS application is also referencing it for the usbep_dequeue() call. This can lead to accessing a stale/hanging pointer.
commit b566d38857fc ("usb: gadget: ffs: use iodata->status consistently") relocated the usbepfreerequest() into ffsepfileasynciocomplete(). However, in order to properly implement locking to mitigate this issue, the spinlock can't be added to ffsepfileasynciocomplete(), as usbep_dequeue() (if successfully dequeuing a USB request) will call the function driver's completion handler in the same context. Hence, leading into a deadlock.
Fix this issue by moving the usbepfreerequest() back to ffsusercopyworker(), and ensuring that it explicitly sets iodata->req to NULL after freeing it within the ffs->epslock. This resolves the race condition above, as the ffsaiocancel() routine will not continue attempting to dequeue a request that has already been freed, or the ffsusercopy_work() not freeing the USB request until the AIO cancel is done referencing it.
This fix depends on commit b566d38857fc ("usb: gadget: ffs: use iodata->status consistently")
[
    {
        "signature_version": "v1",
        "target": {
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-0896377a",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d7461830823242702f5d84084bcccb25159003f4",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "132002269117360682774230372189265426724",
                "260530629141567428252102902620174736378",
                "291069310209560834226885158354879642845",
                "324996791517942964857762190319444400233",
                "148983557165213077245661920412995932276",
                "57534253631354336770345553391787404328",
                "135965342915026901165311939420769603104",
                "281701739187094673859843222663885773559",
                "111748137593359661534332645332437349324",
                "194199724344163242714025547172349593922",
                "77271585275770927287309269537309199905"
            ]
        },
        "deprecated": false,
        "signature_type": "Line"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_user_copy_worker",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-10ed44cc",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@73c05ad46bb4fbbdb346004651576d1c8dbcffbb",
        "digest": {
            "function_hash": "162060021804806253459620559157688170603",
            "length": 635.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-2735e352",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@73c05ad46bb4fbbdb346004651576d1c8dbcffbb",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "132002269117360682774230372189265426724",
                "260530629141567428252102902620174736378",
                "291069310209560834226885158354879642845",
                "324996791517942964857762190319444400233",
                "120855515629066411297160799140350708722",
                "34860481310577406914219645257164150377",
                "95445551030929445888837451620828701075",
                "281701739187094673859843222663885773559",
                "111748137593359661534332645332437349324",
                "194199724344163242714025547172349593922",
                "77271585275770927287309269537309199905"
            ]
        },
        "deprecated": false,
        "signature_type": "Line"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_epfile_async_io_complete",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-29e6817d",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@a0fdccb1c9e027e3195f947f61aa87d6d0d2ea14",
        "digest": {
            "function_hash": "117503523898866991920370520230340780202",
            "length": 340.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_user_copy_worker",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-3f81a21c",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e500b1c4e29ad0bd1c1332a1eaea2913627a92dd",
        "digest": {
            "function_hash": "252145295375960170878714878056583164044",
            "length": 748.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-4136d23f",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@24729b307eefcd7c476065cd7351c1a018082c19",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "132002269117360682774230372189265426724",
                "260530629141567428252102902620174736378",
                "291069310209560834226885158354879642845",
                "324996791517942964857762190319444400233",
                "148983557165213077245661920412995932276",
                "57534253631354336770345553391787404328",
                "135965342915026901165311939420769603104",
                "281701739187094673859843222663885773559",
                "111748137593359661534332645332437349324",
                "194199724344163242714025547172349593922",
                "77271585275770927287309269537309199905"
            ]
        },
        "deprecated": false,
        "signature_type": "Line"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_user_copy_worker",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-73642c3a",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@a0fdccb1c9e027e3195f947f61aa87d6d0d2ea14",
        "digest": {
            "function_hash": "162060021804806253459620559157688170603",
            "length": 635.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_epfile_async_io_complete",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-762b8b56",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@73c05ad46bb4fbbdb346004651576d1c8dbcffbb",
        "digest": {
            "function_hash": "127401856382739609107475801975469777853",
            "length": 325.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-7a77f6d4",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e500b1c4e29ad0bd1c1332a1eaea2913627a92dd",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "328450770617787847026173206395937473932",
                "117639440983217605316500709595043106196",
                "47059987504635283695353633434711340218",
                "324996791517942964857762190319444400233",
                "257348681129608628214590543846805080210",
                "229090330699572275029364137325549323138",
                "66530666441891623012092559574319697165",
                "129060714210769151201453483227124782109"
            ]
        },
        "deprecated": false,
        "signature_type": "Line"
    },
    {
        "signature_version": "v1",
        "target": {
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-7b2ad73a",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@f71a53148ce34898fef099b75386a3a9f4449311",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "328450770617787847026173206395937473932",
                "117639440983217605316500709595043106196",
                "132737905703775883379298468005970449221",
                "206924687399014387372514208272647854261",
                "257348681129608628214590543846805080210",
                "229090330699572275029364137325549323138",
                "66530666441891623012092559574319697165",
                "83265757377119778207113749709306019257"
            ]
        },
        "deprecated": false,
        "signature_type": "Line"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_epfile_async_io_complete",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-7e94592a",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d7461830823242702f5d84084bcccb25159003f4",
        "digest": {
            "function_hash": "127401856382739609107475801975469777853",
            "length": 325.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-935f85c7",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@3613e5023f09b3308545e9d1acda86017ebd418a",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "132002269117360682774230372189265426724",
                "260530629141567428252102902620174736378",
                "291069310209560834226885158354879642845",
                "324996791517942964857762190319444400233",
                "138896459776933303714204028666684646996",
                "34860481310577406914219645257164150377",
                "95445551030929445888837451620828701075",
                "268721269200639235277474551093410396740",
                "225294307919059842778491587877888533152",
                "194199724344163242714025547172349593922",
                "77271585275770927287309269537309199905"
            ]
        },
        "deprecated": false,
        "signature_type": "Line"
    },
    {
        "signature_version": "v1",
        "target": {
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-9414d177",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@a0fdccb1c9e027e3195f947f61aa87d6d0d2ea14",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "132002269117360682774230372189265426724",
                "260530629141567428252102902620174736378",
                "291069310209560834226885158354879642845",
                "324996791517942964857762190319444400233",
                "120855515629066411297160799140350708722",
                "34860481310577406914219645257164150377",
                "95445551030929445888837451620828701075",
                "268721269200639235277474551093410396740",
                "225294307919059842778491587877888533152",
                "194199724344163242714025547172349593922",
                "77271585275770927287309269537309199905"
            ]
        },
        "deprecated": false,
        "signature_type": "Line"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_user_copy_worker",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-9c7e429d",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@9e72ef59cbe61cd1243857a6418ca92104275867",
        "digest": {
            "function_hash": "180818091058003075157590526262555638543",
            "length": 817.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-a7000924",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@9e72ef59cbe61cd1243857a6418ca92104275867",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "328450770617787847026173206395937473932",
                "117639440983217605316500709595043106196",
                "132737905703775883379298468005970449221",
                "206924687399014387372514208272647854261",
                "257348681129608628214590543846805080210",
                "229090330699572275029364137325549323138",
                "66530666441891623012092559574319697165",
                "129060714210769151201453483227124782109"
            ]
        },
        "deprecated": false,
        "signature_type": "Line"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_epfile_async_io_complete",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-b3ceb8a9",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@3613e5023f09b3308545e9d1acda86017ebd418a",
        "digest": {
            "function_hash": "117503523898866991920370520230340780202",
            "length": 340.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_user_copy_worker",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-c29d2703",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@f71a53148ce34898fef099b75386a3a9f4449311",
        "digest": {
            "function_hash": "125949039970426364220643501628215323462",
            "length": 824.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_epfile_async_io_complete",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-c6ccc465",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@24729b307eefcd7c476065cd7351c1a018082c19",
        "digest": {
            "function_hash": "127401856382739609107475801975469777853",
            "length": 325.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_user_copy_worker",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-da74fd91",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d7461830823242702f5d84084bcccb25159003f4",
        "digest": {
            "function_hash": "114570679143673360249943360451747662816",
            "length": 631.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_user_copy_worker",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-ed993574",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@3613e5023f09b3308545e9d1acda86017ebd418a",
        "digest": {
            "function_hash": "235463458658651075258068168154923773031",
            "length": 641.0
        },
        "deprecated": false,
        "signature_type": "Function"
    },
    {
        "signature_version": "v1",
        "target": {
            "function": "ffs_user_copy_worker",
            "file": "drivers/usb/gadget/function/f_fs.c"
        },
        "id": "CVE-2024-36894-f3b24c3f",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@24729b307eefcd7c476065cd7351c1a018082c19",
        "digest": {
            "function_hash": "114570679143673360249943360451747662816",
            "length": 631.0
        },
        "deprecated": false,
        "signature_type": "Function"
    }
]