From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410293; b=DnO6IJOEdABjB+MpslTtoyZXEXo/gLTytQvbNuUDPN0uS8szwQHGm9TSrrN0sf+jFLVS 42QHroIl+2FH3LVUqUMGYPAPfo9UHr1/GInZuGWwUeuKWcQP98dzOJxZprKZM2HBpAMKQ UvyF84lSObTbv1nMnSv5kf53QM45xeAEVI/VMt9T/+TOIcJKB3dfqW7cmSabpjj5t5YKE SlhO/N6ckl/krIhy3W4n/RpIO0hDF/tiZ8/BNIP87bAPpwMWXOHeT7Kf8m+lurbTuVzna XTTxevNPzEbgv34W2Fvaka+qOCebourIS9jxG7I0gCtc6NtAY8TyIC2l269A58GcZsw== 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=Fu1mz+QbnjuqtSf2SJgy8rM4bthnbJtBpr2Kk8o/yqU/lLixLLnzh0JrNfz2ND3/2Q7h zew8SY1DqA5XGlT+JiWgUJXGooyTI7taBf0E0hAEAwW3vICkuxVTj9I48+9XK6A6F8MD5 cRFDOOdrjFhRwmjdFn9tkwZ2S2dbDGGffoLIMJIDKo2/1K3g76ctBDzVQwxL0sEIx2FU0 BIgW/VY1V4+OOxdYsV14WuT3JqHfxpSkeoeNvDGaQfY9kMFvpvn5qF161fQpA07GhCcEt +tQDUOM6eZ5eckQRdpWEFX10x4eFrW/H1seRUPFSThlwmsGWmcuyZPWD3EIzfttG/PA== 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.43 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (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 BFAF3606A322 for ; Fri, 4 Dec 2026 18:51:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BFAF3606A322 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-f43.google.com with SMTP id a92af1059eb24-1a2af4c8d00so493212c88.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=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=r8diAUa3m4YrSMb3k9KH8evQW5+RfrsurjE1CqAvSIwatwwhTf9as4PGvWnJPFriDj So6B/DDLjQAXyiFH4rNQvxFBmqxqMKt6x62IOeHji7sIReKhY2KfNE/jID92meHYVcat l4G8JXL0wrRdW/J0nkaeSS4pkZTAiGeLMeEcVX8Z/09AH3cD9JwYydFGx2x5080CClbt PE7l7DtyA1GEGQueP8Tvzm0IcJkSiLCnlCN6yhg7APdIPCch1V8C8ZojULbKUFUs0lCb birjKX+4nVDESOl2AWdzW9o2XZzZpKZBD2wzWgEk7r4ilvgS1/bSD2dlM+yHUTqPlQ81 SGEg== X-Forwarded-Encrypted: i=1; AL+hErGUQiYZ/6QLWyCRWQHW3mGgq8x2SfQYZEPZNDTeMEw7NaJK/iVqYVWDytte6g2Oo2wjrf/qzGE=@vger.kernel.org X-Gm-Message-State: APuU4Z8mf1dJpm3kBgrJvP+od0wfRcRlABNfLdyiSUNpElCK3/uIrS5t ah9rROgNQ8aFCZbmau2rlR1tCr1YYzXxfY/cCaP7D8grS3IeG0pg2ooR X-Gm-Gg: AZFdTZdNsdnAnUhlzqBKAAKxUKN7aqlcc4zw9gS8HEUcKem7S/UAdrENtU9Yopnwf+p 00cpP8QrvrtSZY29VV9Fha8vKkhQniTug0N9RpKTwwN4hTg6zyuDEeADaqi5KVkhWzx0Wq5CiQh ln759TelNKJcwdegP5bCcfp+eWCSEJ3aECNCg7u25W31t/Oz+ryxF/YuVqlHQG6ex3q4MAVHxLB KxKv/UKL7ih3Mt+KuupHAyDrNR1TtRQLSOQqN9ueUb+YyCr8Yz6Yrc+KuKT/VEB8VsEffFeNteH r9gvmSsw6cmYtQKJR9p1qTbQfZtfxGOchzKDkGuECk/VSp+EFAvaCZgOX/0uEAFbuna/Z4cWX5x VRzcz0l/GYAcIuy5Rw1ygXOW1zJ/nesxrBStEkxLcog+hxvHlbz2kiPsHtPtLC1lDiqE/J/Z33e YSjhUkyLiunQLg0UKg/LNpT4U0V7qCzbNgq3v4wrAkxuCAL82/3cgpxdhZY//DvJnoYrbFyJyLD 2F5zP9ugdIcGPTs/LU1BrpRLI+P/IKNWYG2e1KS5bwRp0fqfUfZkeEPRgR6K1yeioMveokX2Fex g/XwHtNYXTZUvGiMySbHmkW1CPyW6YlPVHUjxXnbZmF9i0tbFYJ95cwj1kaIxnBKi7c= 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: stable@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