From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21586606A322 for ; Fri, 4 Dec 2026 18:52:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Bt5H1LLs; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wO3GzENl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=2YkqTx+crth3Kbd83D+59ziru/VXkGwF3KvpHyENnQ0=; b=Bt5H1LLs+7414UJTSjsuwh2Fjk vU4yHoXKjIPdkKkp6xCodmEQpwOo0vNnkihm9VqdJxmqU4R1HI/r4sRtVfK9W0/ORnM6luFxtpvZ/ GAbbpon5XH8ROQlPIKm4xN8yVBXbo5K3+ZuyCnZD+i0RtQRdx+gNm2gGpB5YWlHY3K3EJtZQDCW3X d186qEJKzLx6HEHpt++mzJl/dpuyWqOT73m4o2oEBHLFrrCPkTK6k+usnGYNyGeUZYk66iq2cbd5J eYyIFxliiTJ5jh7VaNQl91DX1CIEczjajYbK8fi8vn7KQLpbWLRe3WyUpWmruC+vPJ6IYlpjwDsc1 1PIKsaPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZYOA-00000001DM9-3aFa; Fri, 04 Dec 2026 18:52:12 +0000 Received: from mail-dl1-x1229.google.com ([2607:f8b0:4864:20::1229]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZYNY-00000001DJE-39qR for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 18:52:04 +0000 Received: by mail-dl1-x1229.google.com with SMTP id a92af1059eb24-1a2af4c8d00so493211c88.0 for ; Fri, 04 Dec 2026 10:51:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796410292; x=1797015092; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=2YkqTx+crth3Kbd83D+59ziru/VXkGwF3KvpHyENnQ0=; b=wO3GzENlQIDQxEyyCjGmqFdV7xDhnr8XGj7UOHrY/1lfYr3ifZc/2mCtqe91XbVEOX vsdyroAAlLmlqc+x7ARrUX8n5nYErIpNTlgGBW9IN9O2BTKtVsEa9mYA8fdB2E7jDvZ6 E88akD39CEw5yJzYGd7nd66TBfCJSalcQ6jhi6BA1h7J0PbLCblCMXwmJ/cKYSZoTI+o k7zFmI3WvpB0sOUQ7vXi7Z1JmaEd/ivX/Yc0NOpq0VCVtDpaz1EK/VE2WfVYSCBZpWg7 WSw5ChEVdfLy7AJIOBSC9k9XF9v4syeSEqGVHzvDuoUwnslac5DL1B6sBSWb4uZW66Ny W+YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796410292; x=1797015092; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2YkqTx+crth3Kbd83D+59ziru/VXkGwF3KvpHyENnQ0=; b=E+5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K+o9P4C34g4Kp11yFapZH0ZiYOUJiWPB3JFzbzDZ F90EOqkSJh27mTxpnnICJ84myL1CMveap5hRoXkbHjfAF0GEoydM8yUoYo+VbffqfDj1+DW1GsG 66wzq3MPEZIgDquW4bVo1kbu482kQ6ohq53BfH4hDSkXBMSfvSwiSXt/tvKEQ9IX9MY= X-Received: by 2002:a05:7023:e57:20b0:166:b307:5855 with SMTP id a92af1059eb24-1b5d6fd6306mr2661873c88.0.1796410291711; Fri, 04 Dec 2026 10:51:31 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d642f101sm9324498c88.5.2026.12.04.10.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:51:31 -0800 (PST) From: Praneeth Balasubramanian To: Greg Kroah-Hartman , Neill Kapron Cc: Daniel Mack , Haojian Zhuang , Robert Jarzmik , Petr Cvek , linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Praneeth Balasubramanian , stable@vger.kernel.org Subject: [PATCH] usb: gadget: pxa27x_udc: Keep ep->lock while queueing on ep0 Date: Fri, 4 Dec 2026 10:51:28 -0800 Message-Id: <20261204185128.1688263-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_105152_870958_E3EA26F2 X-CRM114-Status: GOOD ( 21.50 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 pxa_ep_queue() adds the request to ep->queue under ep->lock, drops the lock, and then runs the ep0 data stage: it writes or reads the ep0 FIFO, completes the request, or removes it again with ep_del_request() on an unexpected state. ep_del_request() is documented as "Context: ep->lock held". The ep0 interrupt path, handle_ep0(), works on the same queue and FIFO. When a gadget queues on ep0 from process context, as FunctionFS or a UVC gadget does after a delayed setup reply, interrupts are on and the UDC interrupt can run handle_ep0() in the middle of this sequence. The ep0 block ran under the lock until commit 5e23e90f3388 ("USB: pxa27x_udc: Fix deadlocks on request queueing"). That commit released the lock before it to avoid a deadlock when a completion handler queues a new request, and noted that ep0 still needed a proper fix. req_done() can already drop the lock around the completion when it gets the flags, as nuke() and handle_ep() use it. Keep ep->lock held for the ep0 block and pass &flags to the completion helpers, so the lock is still released while the gadget's completion runs. A 2017 RFC took the lock in the same way for the OUT data stage. The missing lock was found by a static check that turns the locking rule in a function's comment into a Clang context-analysis requirement on its callers. Link: https://lore.kernel.org/all/7670be97-1199-3c5c-8959-4b982d0fb9cf@tul.cz/ Fixes: 5e23e90f3388 ("USB: pxa27x_udc: Fix deadlocks on request queueing") Cc: stable@vger.kernel.org Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by a compiler-based check, part of research at UCSB SecLab. The locking rule stated in the kernel-doc comment of the called function was turned into a Clang context-analysis requirement (__must_hold) on that function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every caller. An LLM was used only to turn the comment into a machine-readable rule; the report itself comes from the compiler. The patch and changelog were drafted with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64, clang 23, allmodconfig). Not runtime-tested; I do not have this hardware, and I have not observed the race myself. drivers/usb/gadget/udc/pxa27x_udc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index df5cca43afbe..d20ccbe332d7 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.c +++ b/drivers/usb/gadget/udc/pxa27x_udc.c @@ -1102,13 +1102,12 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req, _req->actual = 0; ep_add_request(ep, req); - spin_unlock_irqrestore(&ep->lock, flags); if (is_ep0(ep)) { switch (dev->ep0state) { case WAIT_ACK_SET_CONF_INTERF: if (length == 0) { - ep_end_in_req(ep, req, NULL); + ep_end_in_req(ep, req, &flags); } else { ep_err(ep, "got a request of %d bytes while" "in state WAIT_ACK_SET_CONF_INTERF\n", @@ -1121,12 +1120,12 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req, case IN_DATA_STAGE: if (!ep_is_full(ep)) if (write_ep0_fifo(ep, req)) - ep0_end_in_req(ep, req, NULL); + ep0_end_in_req(ep, req, &flags); break; case OUT_DATA_STAGE: if ((length == 0) || !epout_has_pkt(ep)) if (read_ep0_fifo(ep, req)) - ep0_end_out_req(ep, req, NULL); + ep0_end_out_req(ep, req, &flags); break; default: ep_err(ep, "odd state %s to send me a request\n", @@ -1135,7 +1134,9 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req, rc = -EL2HLT; break; } + spin_unlock_irqrestore(&ep->lock, flags); } else { + spin_unlock_irqrestore(&ep->lock, flags); if (!recursion_detected) handle_ep(ep); } -- 2.25.1