From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410293; b=gwokbBV1hyiVgRQmlI5Hc5uA+6mIbCMkYCZRIl+7QcfsVD+iEc7hJ0lzDqSpQZ9+AFm3 IknQ2mgyLxYKe6MUoWseh1Y9LtJ73JGMjU4PlreH+B+cxKjZxG3WaRSqvfT2JT2w/+hM6 Dtg9+udvWzt/GgSUaeVRkwUi3fppM7TjSAY+ybdRGz5t13Cv4zDZAuVvpao3ffrawNUe9 qmxm5zVMzFCw9nII+Ct73jxmtDI86Phnxh1FDrAGe+Vwl/JpieuT1zwPFoS4lRZyhuo7V HmtMxd17NcVSbBbCn0gUIHB0qYJmYsOcjMvdYOnEJrzm6mU3DLJ1ujxCXYxqhT0q4MA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410293; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=2YkqTx+crth3Kbd83D+59ziru/VXkGwF3KvpHyENnQ0=; b=BMzEsl/uOPpogfc5/RRRTt33EqU71hmopOqb3ZKnStS0R1gyYXxCPEdNApfcu4+UjRFj sPbdjeIM78gPFUpVs491OLSsAyFMh8MacJUdfwqigB2+jc6U3EooC/h7pHanzhc/tiDDE 7wFFWUAYcKpV7vJxctyI6ghEY/wjBjTRVZ7kBEN9WEyVPIwA0/4D9hgTpCffZPfHeUjCH 6J9mNeodzakecpS7xM6E/ev5p/+6G6WqGrVHfzGNzssSqRyuHNRm9YmGb75BhP8VX27wk F9Fr9eOb3MqxTl6Bm/HmZ3QRqcqj2MKgYXGfATnLrQIoHwKw7PDNj6NcwwpscFegMvQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="GMLUi/K0"; arc=none smtp.remote-ip=74.125.82.41 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5485606A32D for ; Fri, 4 Dec 2026 18:51:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C5485606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=GMLUi/K0 Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-1b5adf7eacdso296549c88.1 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=vger.kernel.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=GMLUi/K023flpRwt2CEqI6YwEFLBmbSdOfzLd45a1cBUc9vmbFscPISnCT1KbhbgiY Md7T0paH6IGgooAfvew1NJ1g4sZQW+Kp6xSNcSpwF3g3rR75fD4l2dMKN7e+LXdW/ZW+ qRZf9PfjWAz2P0IDrGEiczhCHJqcuEZgiBiexHzFodvuvTxCgChHekatyexUhH6uJxUz 36xZPe5bkfcyKmGl6FDrOIIw9D6ehHnW2KktlzemRnqFafAiE8XBJk2HYA3XA7Bfmly9 q7XnrvuYvy9iNsRcMrPNBQfYiWJSie3HCc7z/jQjYtZnUrVogwKNv6YVYy+jr5fRNySl L2HQ== 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=eddnxIRRnPxhNE8MkfKhee36bHVzENrUb2CFn+3CN41KeN2w/GUi1qWyOacFa3Repl MKe/9TUv9qbw79kcKFw9l5k7kEhzgDfiMK/GJ7EezMRqR/AUmAy1Ux3Dq8e/pRZn0Bfh zQN2M5c7/Uy9hi/1GCKYwc5/v4b7nLp8LvrjF3fUPzssYivEhnNtbcuz8Mc80fWZ4Oeb MdOF9Da2MOfqlF5ArV/OlyP66eyHPc2H2VGrYKJi9QSBRI3PGUYjggADy8yt1dvYZnyD WF9OLngXciQYTRfXJcGHLXwbPC9IQIGxVGpxPgpL4S+riSlyeoc3t9BDOw0hDHgwBtWI akRg== X-Forwarded-Encrypted: i=1; AL+hErFll+/CQg8lGWbTNTb+68ok8k0V4szS3kGHBVuFxngCsWDpqVlbozZ0i+Ns0zayCFGYvc9DM0C62mk=@vger.kernel.org X-Gm-Message-State: APuU4Z/NFxAS2k3XogSVWGLupGCNvnZF+r5dExUAqJaDWnXwd2u+aGth tfDk34bB1MVNbgGf9ffoj1OrUtAqST7fGynMF0vzGnCyP0whBdnJqvag X-Gm-Gg: AZFdTZeWctNwKWS0MIu4gqy+IrC+NrnJGFNrfbfcoDoPX8u8ObkiuZ/D99fB11wws0V EuKb+doCYiGOIdbYQ5ao2Us3vx2xA16rV+jrpsMlxbecO+boonUmhprBdV/I/0lYmw7XdIr8iqh 2v+jFwvCuKz06s4WlVIbNEfUyo5WyiJcT2XZ6zUJwJojQjDm72ewYY3fHRgKRTZZBZdqETEr0A6 YvP8/G4MK5jzp7guoFKAUcIYBeInZPk3e4TvtIUYgfspuWpSS8lPi0f5EbS3Iy12SKXvgJMkBcx vt140aOZ5Gy8Jb/BJJRQ+pA63SDwcM7gCbDnDdzW3j3X9SbL8t7wG6I8p6O+kDDZqeiG8Gt4xG1 WdYjNj+Ft2BsFas43jeygsVEJfxvdbq34KE1x3wbsWOMokc/vpRENRVWd7K3NJQoy6bqhzNSAcn QfqXQh35X0e0l37phdcWZyLmBLr85WjSnUGv0vXSeN+mpP0NXG1+HnDmmeb1On//ml61zpCc3k9 X4Vc9VSDbITMoRA4yKLBcl944PbTqCjSmejeU4ZsrXxtNLpbW3NBpSOqDYEFXNslf9VZMzKk10X +TR55Ue9KlQMZPmqV4Ffq0yweercN/yndSO+KdV94//swmCWrh/GCYFuWLI84qcSolM= 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-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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