From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCAB7215774 for ; Wed, 26 Feb 2025 02:13:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740536030; cv=none; b=PV8q6Y3P7Tp30Z6FqZTTm7VM5OAXTkufHwZK3LtXt5mjckz9dTVQ3/GdA+qDFNTZg1OTpa+WfoZCanxqXkOHFbM8qISFj7uFBGRPBZX2YNvZ9Cza9woN4C1ga5xhi0WyRU7N9Sj2w/e2D1Leim6exuEijkbw0gw2nUSGe8tG1eU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740536030; c=relaxed/simple; bh=PxPhsyCzeZnNBE+rUtGmm53dDDj4hB6whijzC3AR28w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=W1F+0yCL3XI7pzGkIVUG8G1qcE1QE3pCqBV4zG/QrK673PQXp4FAJlkFzzBj/dagj0vafnw5+sjg55S9wwKWUyotKEw/5MoygRzMG9hJemdMmmz39cH2xO/j7/L6ek1y/XuagP/FVZtuGWkt7rijBnGYlgDpYtSZaUq8W2Nqc4g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Yr7PAVxg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Yr7PAVxg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2D75C4CEDD; Wed, 26 Feb 2025 02:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1740536030; bh=PxPhsyCzeZnNBE+rUtGmm53dDDj4hB6whijzC3AR28w=; h=From:To:Cc:Subject:Date:Reply-to:From; b=Yr7PAVxgIPiLBQD5FqLh/MTlW3ArzrFz8x1Qw9sCFgrc7SxcNqkXdxoRMNqdY4QsJ HJuUQcK1xiiov/XCNymg5omGz803NRShBXuJyYdg8EZwzr0cJS/EmaofWSi8wAUYlH 344rMpi9NgbcDG8XGXaaO9DyJSF0POODBZ1M68pU= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-49398: usb: dwc3: gadget: Replace list_for_each_entry_safe() if using giveback Date: Wed, 26 Feb 2025 03:11:12 +0100 Message-ID: <2025022650-CVE-2022-49398-9274@gregkh> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=3877; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=PxPhsyCzeZnNBE+rUtGmm53dDDj4hB6whijzC3AR28w=; b=owGbwMvMwCRo6H6F97bub03G02pJDOn7yt/VZItrhC98errF6cKVEJO/8x5MXn/RQlx40YHMu KjuSWG3OmJZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiGUUM80x3PY0X3N6j+/Sw lvuv+Z0hE799SGBYcITXatqTP3nWy07dvuWVJbL9wqn7DgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: usb: dwc3: gadget: Replace list_for_each_entry_safe() if using giveback The list_for_each_entry_safe() macro saves the current item (n) and the item after (n+1), so that n can be safely removed without corrupting the list. However, when traversing the list and removing items using gadget giveback, the DWC3 lock is briefly released, allowing other routines to execute. There is a situation where, while items are being removed from the cancelled_list using dwc3_gadget_ep_cleanup_cancelled_requests(), the pullup disable routine is running in parallel (due to UDC unbind). As the cleanup routine removes n, and the pullup disable removes n+1, once the cleanup retakes the DWC3 lock, it references a request who was already removed/handled. With list debug enabled, this leads to a panic. Ensure all instances of the macro are replaced where gadget giveback is used. Example call stack: Thread#1: __dwc3_gadget_ep_set_halt() - CLEAR HALT -> dwc3_gadget_ep_cleanup_cancelled_requests() ->list_for_each_entry_safe() ->dwc3_gadget_giveback(n) ->dwc3_gadget_del_and_unmap_request()- n deleted[cancelled_list] ->spin_unlock ->Thread#2 executes ... ->dwc3_gadget_giveback(n+1) ->Already removed! Thread#2: dwc3_gadget_pullup() ->waiting for dwc3 spin_lock ... ->Thread#1 released lock ->dwc3_stop_active_transfers() ->dwc3_remove_requests() ->fetches n+1 item from cancelled_list (n removed by Thread#1) ->dwc3_gadget_giveback() ->dwc3_gadget_del_and_unmap_request()- n+1 deleted[cancelled_list] ->spin_unlock The Linux kernel CVE team has assigned CVE-2022-49398 to this issue. Affected and fixed versions =========================== Issue introduced in 5.0 with commit d4f1afe5e896c18ae01099a85dab5e1a198bd2a8 and fixed in 5.15.47 with commit 1c6e5dc3b639c96e6839a8d1b8e951923fdfd34a Issue introduced in 5.0 with commit d4f1afe5e896c18ae01099a85dab5e1a198bd2a8 and fixed in 5.17.15 with commit 2424307cdf421ac72075a1384eae4e4199ab6457 Issue introduced in 5.0 with commit d4f1afe5e896c18ae01099a85dab5e1a198bd2a8 and fixed in 5.18.4 with commit 26a7e6832afe9d9a991cfd9015177f083cf959cc Issue introduced in 5.0 with commit d4f1afe5e896c18ae01099a85dab5e1a198bd2a8 and fixed in 5.19 with commit bf594d1d0c1d7b895954018043536ffd327844f9 Issue introduced in 4.19.57 with commit d7ff2e3ff0e09d57b43014fe26b13bb3c9677254 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2022-49398 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: drivers/usb/dwc3/gadget.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: 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