From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388845; b=cXxfXypgLjQ0xp16cu4N5+w9nJR66uLqHCfylnoYBDJbqtaWc3qnYtyzG0beSlNg9x33 aAxKWeTtqds5zMGvpgEQuxqSE0WRuqCVEPr+MnghjanqbW7gdj8pNn1W1WBGx5p/Am4j4 C1e64xJs/h5JawMXRctBIB37GdVRi7neMGCmLRS7D4luA7NTW8h/twxvnuT3F7uyG/ZbR 8THT9pHLWofEnEjQ6dsvNhk96rHULb2HK5HGIZ5lOyz6lXIC0D8ITV28nr859p2ovNx+w m1J149EnyMQSjmB8s1V4LDjdYCxrjh8H2sxOs6g9IOxR3QgivFM8ET+t38hEq8p4KNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388845; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=CnJVxgQWXSAi5UlJGMvDKZzrqjn/fOAOPv1LAO42Ow0=; b=ebjdNgWOOolkgHsyPQtHuxa87RXsLJOt+qc5S7bThaIaWxYUkkOnTcmRqiS4nz6q3Hoo W7QBB3fFM6/huGMTlPnBgekzWEevNDyMu3SvTSYhPQZaPL/HfnfFdHWdEfgguHrvnwjfj aF3b4pCx9j4m7onFCafiwipWcob3bcJG+jKOkR19edrzfn7a8pNprAirwK7AvlCx5vf+R Qa3gylN6SD4y5wuGfpAgS57BpVfzBUNTm3rJVWBk0WO+l3NSlvTi8ocYqPaqhSOO49Ryp k7dhy4nob8TszqcWkaB+d4awVgwGcwXxSq5NPt1CqtDBJ7IF94q20q0TRsngTl3bHAg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=n3CVeOtl; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 000DA606A32D; Fri, 4 Dec 2026 12:54:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=n3CVeOtl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BDD81F0092C; Fri, 4 Dec 2026 12:54:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388844; bh=CnJVxgQWXSAi5UlJGMvDKZzrqjn/fOAOPv1LAO42Ow0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n3CVeOtlUt9far2iHMrfq0YZgMHaWOs/cRRd6g23ssxEQoxYppJ/Aj3G72zVZJj8/ tXJe6VfIceGySXGHnKK1Nc6El+znL11zLbIejse14ncQqAYH1sjmOQ1gJQjRNWXekq paCXeBDM8DM5o1Z14dI6Xr3PEVhSY2FO0Ia6JwaE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thinh Nguyen , Pei Xiao , Radhey Shyam Pandey , Sasha Levin Subject: [PATCH 6.1 0756/1059] usb: dwc3: gadget: Fix use-after-free in dwc3_gadget_free_endpoints due to race condition Date: Fri, 4 Dec 2026 19:04:47 +0900 Message-ID: <20261204100703.590064856@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pei Xiao [ Upstream commit 9c855832790cd488d87de1885974f4c37cfe7358 ] In dwc3_gadget_init_endpoint, &dep->nostream_work is bound with dwc3_nostream_work, and dwc3_gadget_endpoint_stream_event can queue this delayed work on system_percpu_wq when a DEPEVT_STREAM_NOSTREAM event is received. If we remove the gadget, dwc3_gadget_free_endpoints makes cleanup and the memory allocated for dep with kzalloc() is released by kfree(dep), while the delayed work mentioned above may still be pending or running. The sequence of operations that may lead to a UAF bug is as follows: CPU0 CPU1 | dwc3_thread_interrupt | dwc3_endpoint_interrupt | dwc3_gadget_endpoint_stream_event | queue_delayed_work(system_percpu_wq, | &dep->nostream_work) dwc3_gadget_free_endpoints | dwc3_free_trb_pool(dep) | list_del(&dep->endpoint.ep_list) | dwc3_debugfs_remove_endpoint_dir(dep) | kfree(dep) | // dep is freed | | dwc3_nostream_work | // use dep (use-after-free) Fix it by canceling the delayed work before kfree(dep) in dwc3_gadget_free_endpoints. Fixes: dcfe437492e2 ("usb: dwc3: gadget: Reinitiate stream for all host NoStream behavior") Assisted-by: Codex:deepseek-v4-flash Acked-by: Thinh Nguyen Cc: stable@vger.kernel.org Signed-off-by: Pei Xiao Reviewed-by: Radhey Shyam Pandey Link: https://patch.msgid.link/331d1d5133496d2b4184e05f8848adb06930a138.1785893865.git.xiaopei01@kylinos.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/dwc3/gadget.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 01f2729bcbfb5..4a232280936e1 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3377,6 +3377,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) } dwc3_debugfs_remove_endpoint_dir(dep); + cancel_delayed_work_sync(&dep->nostream_work); kfree(dep); } } -- 2.53.0