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 8886B2563F for ; Wed, 28 Feb 2024 08:15:18 +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=1709108118; cv=none; b=TiWIDr+gV6S9tgVvaS81SQffhathVjGAuy+E1aTj0OrwquF1ViWvBm0+RVwrUNfQnpQF0lE56bx3mUxHJlciGPVYYwBDVfqg19ldLz491lsjh3cYfVqP4SBI2uDLDn1gd/w4HBqmC9t5wmrcN8JthETnfNTurfbkdhDYEqN54Io= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709108118; c=relaxed/simple; bh=/kAtCRkGqwRjI8jhNQGMxy3HeYEGo7jAu3ZGVOB7jQo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Yytqw/znV2ttG9l/1iyzc/Ourh9novxcO7kYVzSFOJFV54ye5Q5lb9bCutySfainWCSyOUV6CS5ITSjgL2vELL980WPcyvRpamjtT5oaMpgMTqPOCsHmWaCze/cPAT/t/vDR4DExVscvZ+bMUksXUaM1Dzw2kqVFPqpWVupo9Rs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cSe7vLNp; 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="cSe7vLNp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9AB9C433F1; Wed, 28 Feb 2024 08:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709108118; bh=/kAtCRkGqwRjI8jhNQGMxy3HeYEGo7jAu3ZGVOB7jQo=; h=From:To:Cc:Subject:Date:Reply-to:From; b=cSe7vLNpLWb4l1MyIC0IsXU+8HOHLGQJUt7gs209jL7229AF99V0329SUzzDzkiv7 a/7GFz1qZZ68z46+CRW8Ccq2JCzmCCml/PZl7xxWkQ7QP1fVuWTj19xVKT7pvoc1Fm 4BkcUEoTs4q5u0T1Dedie1HCCczC4/pf7n24KTFM= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: gregkh@kernel.org Subject: CVE-2021-46986: usb: dwc3: gadget: Free gadget structure only after freeing endpoints Date: Wed, 28 Feb 2024 09:14:36 +0100 Message-ID: <2024022824-CVE-2021-46986-1d6e@gregkh> X-Mailer: git-send-email 2.44.0 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=3393; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=jmCrNfkOkiXs4wAP0cjZYCiQER4zdQe08nY2gwRhHeA=; b=owGbwMvMwCRo6H6F97bub03G02pJDKn3XifMMdzi18uuvWnpnwqZpeJbfN98vNH+Ze3CdgFrV +cdVTv0OmJZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiM/YyzA91vBZez7Us3/7Z Eg9pbzUpqY3rBBgWNE3lZGr+6Wa3w/Qk2+TK9Q/XTf9xGQA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: gregkh@kernel.org Description =========== In the Linux kernel, the following vulnerability has been resolved: usb: dwc3: gadget: Free gadget structure only after freeing endpoints As part of commit e81a7018d93a ("usb: dwc3: allocate gadget structure dynamically") the dwc3_gadget_release() was added which will free the dwc->gadget structure upon the device's removal when usb_del_gadget_udc() is called in dwc3_gadget_exit(). However, simply freeing the gadget results a dangling pointer situation: the endpoints created in dwc3_gadget_init_endpoints() have their dep->endpoint.ep_list members chained off the list_head anchored at dwc->gadget->ep_list. Thus when dwc->gadget is freed, the first dwc3_ep in the list now has a dangling prev pointer and likewise for the next pointer of the dwc3_ep at the tail of the list. The dwc3_gadget_free_endpoints() that follows will result in a use-after-free when it calls list_del(). This was caught by enabling KASAN and performing a driver unbind. The recent commit 568262bf5492 ("usb: dwc3: core: Add shutdown callback for dwc3") also exposes this as a panic during shutdown. There are a few possibilities to fix this. One could be to perform a list_del() of the gadget->ep_list itself which removes it from the rest of the dwc3_ep chain. Another approach is what this patch does, by splitting up the usb_del_gadget_udc() call into its separate "del" and "put" components. This allows dwc3_gadget_free_endpoints() to be called before the gadget is finally freed with usb_put_gadget(). The Linux kernel CVE team has assigned CVE-2021-46986 to this issue. Affected and fixed versions =========================== Issue introduced in 5.10 with commit e81a7018d93a and fixed in 5.10.38 with commit 1ea775021282 Issue introduced in 5.10 with commit e81a7018d93a and fixed in 5.11.22 with commit bc0cdd724932 Issue introduced in 5.10 with commit e81a7018d93a and fixed in 5.12.5 with commit b4b8e9601d7e Issue introduced in 5.10 with commit e81a7018d93a and fixed in 5.13 with commit bb9c74a5bd14 Please see https://www.kernel.org or 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-2021-46986 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/1ea775021282d90e1d08d696b7ab54aa75d688e5 https://git.kernel.org/stable/c/bc0cdd72493236fb72b390ad38ce581e353c143c https://git.kernel.org/stable/c/b4b8e9601d7ee8806d2687f081a42485d27674a1 https://git.kernel.org/stable/c/bb9c74a5bd1462499fe5ccb1e3c5ac40dcfa9139