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 62D7B284695 for ; Wed, 18 Jun 2025 11:02:11 +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=1750244531; cv=none; b=pvVFBlTTFOVzq0M7U7P61WU3DTDY53FDAiwF3aHxbXi7tTJdCsVcZKeTUSVQxR+KkXCfocsV/wTbu/Qig+eReIUmpJFVFs4iAxChlHCo0Kjab9Og587L0WoNIB+fL+KCyCyLS8jDr3mqXm2CKCDJwRXD9F43FUiV01Hujl+LsL0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750244531; c=relaxed/simple; bh=WI22hU0LNDIRBcw+wU097I9HNFj2zryDCGXyHR4DCH4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=NgU8G4BrTwte5A0eMSnghTNynO8vKWQmDnI0fY6u9u89hvekSvD+SpcFydAL66i3RkBHDQbpSE1iNZTVFlo/OFNOilLSNawil/SWuIFaCLrpCNAzaZQnIbXxHzkIgQb4UdykLAj6QjYRgvkt6WVp+YAz65hoBhGYKj2REy6g3og= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=yK/oqUIi; 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="yK/oqUIi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FC71C4CEE7; Wed, 18 Jun 2025 11:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750244530; bh=WI22hU0LNDIRBcw+wU097I9HNFj2zryDCGXyHR4DCH4=; h=From:To:Cc:Subject:Date:Reply-to:From; b=yK/oqUIiZGwE5F1Km5aUYIVRLmiAK1yU0P2CkvNRaUskNYzzN9hZdUrheEmFMUQFQ 108Fg2EMyt99Pmuaxgu7wObfK5UTdW0YoLKaANYk32JWk7hw6IiYhIrDczKB+IFjE6 +2WVQbjxBreycnuAOwAGYHzsz3y87r/LxZQtgQZ8= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-49943: USB: gadget: Fix obscure lockdep violation for udc_mutex Date: Wed, 18 Jun 2025 13:00:08 +0200 Message-ID: <2025061807-CVE-2022-49943-7809@gregkh> X-Mailer: git-send-email 2.49.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=5503; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=zF16re2f4zt5X5QhSKSxO9PRvkCXY5M9noDPiNevFFo=; b=owGbwMvMwCRo6H6F97bub03G02pJDBlBc8wnpv2ZmVzZvOdWseCVrkcPFiUfXZXHv35Cn+rOE 42aYkuSOmJZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiOyQZFtzYe+ZzzK8Pi5sF s93+vXadO2s/kwDD/PLgrPLbfB/2Tt+f6qV/+FbMn2lrLQA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: USB: gadget: Fix obscure lockdep violation for udc_mutex A recent commit expanding the scope of the udc_lock mutex in the gadget core managed to cause an obscure and slightly bizarre lockdep violation. In abbreviated form: ====================================================== WARNING: possible circular locking dependency detected 5.19.0-rc7+ #12510 Not tainted ------------------------------------------------------ udevadm/312 is trying to acquire lock: ffff80000aae1058 (udc_lock){+.+.}-{3:3}, at: usb_udc_uevent+0x54/0xe0 but task is already holding lock: ffff000002277548 (kn->active#4){++++}-{0:0}, at: kernfs_seq_start+0x34/0xe0 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #3 (kn->active#4){++++}-{0:0}:        lock_acquire+0x68/0x84        __kernfs_remove+0x268/0x380        kernfs_remove_by_name_ns+0x58/0xac        sysfs_remove_file_ns+0x18/0x24        device_del+0x15c/0x440 -> #2 (device_links_lock){+.+.}-{3:3}:        lock_acquire+0x68/0x84        __mutex_lock+0x9c/0x430        mutex_lock_nested+0x38/0x64        device_link_remove+0x3c/0xa0        _regulator_put.part.0+0x168/0x190        regulator_put+0x3c/0x54        devm_regulator_release+0x14/0x20 -> #1 (regulator_list_mutex){+.+.}-{3:3}:        lock_acquire+0x68/0x84        __mutex_lock+0x9c/0x430        mutex_lock_nested+0x38/0x64        regulator_lock_dependent+0x54/0x284        regulator_enable+0x34/0x80        phy_power_on+0x24/0x130        __dwc2_lowlevel_hw_enable+0x100/0x130        dwc2_lowlevel_hw_enable+0x18/0x40        dwc2_hsotg_udc_start+0x6c/0x2f0        gadget_bind_driver+0x124/0x1f4 -> #0 (udc_lock){+.+.}-{3:3}:        __lock_acquire+0x1298/0x20cc        lock_acquire.part.0+0xe0/0x230        lock_acquire+0x68/0x84        __mutex_lock+0x9c/0x430        mutex_lock_nested+0x38/0x64        usb_udc_uevent+0x54/0xe0 Evidently this was caused by the scope of udc_mutex being too large. The mutex is only meant to protect udc->driver along with a few other things. As far as I can tell, there's no reason for the mutex to be held while the gadget core calls a gadget driver's ->bind or ->unbind routine, or while a UDC is being started or stopped. (This accounts for link #1 in the chain above, where the mutex is held while the dwc2_hsotg_udc is started as part of driver probing.) Gadget drivers' ->disconnect callbacks are problematic. Even though usb_gadget_disconnect() will now acquire the udc_mutex, there's a window in usb_gadget_bind_driver() between the times when the mutex is released and the ->bind callback is invoked. If a disconnect occurred during that window, we could call the driver's ->disconnect routine before its ->bind routine. To prevent this from happening, it will be necessary to prevent a UDC from connecting while it has no gadget driver. This should be done already but it doesn't seem to be; currently usb_gadget_connect() has no check for this. Such a check will have to be added later. Some degree of mutual exclusion is required in soft_connect_store(), which can dereference udc->driver at arbitrary times since it is a sysfs callback. The solution here is to acquire the gadget's device lock rather than the udc_mutex. Since the driver core guarantees that the device lock is always held during driver binding and unbinding, this will make the accesses in soft_connect_store() mutually exclusive with any changes to udc->driver. Lastly, it turns out there is one place which should hold the udc_mutex but currently does not: The function_show() routine needs protection while it dereferences udc->driver. The missing lock and unlock calls are added. The Linux kernel CVE team has assigned CVE-2022-49943 to this issue. Affected and fixed versions =========================== Issue introduced in 5.19.7 with commit f44b0b95d50fffeca036e1ba36770390e0b519dd and fixed in 5.19.8 with commit 1a065e4673cbdd9f222a05f85e17d78ea50c8d9c 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-49943 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/gadget/udc/core.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/1a065e4673cbdd9f222a05f85e17d78ea50c8d9c https://git.kernel.org/stable/c/1016fc0c096c92dd0e6e0541daac7a7868169903