From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410293; b=0ufrzTk2dmJIrM6HwtDfjm0qVFmeyLGY8UqkmxEjp3apuawHLFoIedeY3EsgxXIXx1HA 9cN5iNLHNbGd7QeRnE1maDmYAN0lB8vfshC2VFRsyIoybcNO+ElFuJdlrmuqEcd9BoLJt NZBzSRMtD4HDp/U8nF42RzbhTQwAA8AvQ6YyHQzrtKR/wtjCD0U4RWA6BIAmzEv2us5WN FEkIBl8bm0pHZuiiUeO+R9uFvKHVCDHz65Lb0F0oULLXpnufBSropuy1Udo7p4yb7QwHY FyRWumNFh66iOPDLgcPHT49C/GTIpe3NkEhfBMEAM8vLuOOBqeH6ZCfSACAE8VvOyPg== 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=J88oGIYYP/bhYWLR3AtZ8IXN6IK6WUDmDd2Sn50re+65PNPu47CT40C4MaoqXMtLZkvd PON39a4Od6JAd2go8mt2Iz+ztbXS+WbFjbA6FOfDUAdfkswCb6ThReYyN4B05/OqHfRSz cOcuEEV+vxuWt2Zg9r2zuxBe1xiqWuBm6c8gR8jhxvQsg6lKROyc/ZkQm3As+4q5piSlN CEsvFvwMTnnn7ksgVAciw6GqFiFSld9k+4xLuXN/lvR8mUwADdLTUiWmOBZAkHaeoe2ic Tn4/Q3pISv4vE05GYyNsE7yae4/iHPCvxX+Id/81DYVQ3oWl6zviXnAWDKtKhO/4jlw== 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.53 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (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 C813B606A680 for ; Fri, 4 Dec 2026 18:51:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C813B606A680 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-f53.google.com with SMTP id a92af1059eb24-1b5adf7eacdso296547c88.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=x0MVUJ2+X/AfP6l2g9la1X8O0ecf5YxXyGvu5n5cM17wMYAL2W1VVME6dfO8YXj5xD csEKePchs/tgQzrr4n2H0jPWwaQP26l/v7n+CgCe6ZAkCgZdPYNof6/hqolaTfMSvH5d cMr5+8/h/5NvH5nXecFezaQRr6zMvdNx7ohCc82aZfTCaNuuyFcvb20LYlezfuyDBs3f IDIcdiPwcTscRmazIC5dwhLgeocelO4KjuXjovtrZgDktvlHtdMwU2UzbWJ4qwc3cU5v 3Q3z+RZ5tOzrwKn/9ka3lkOdaFIomSSpPJ+4Ui8oTOrH8iaVhqGvTzYZtdx87/Y+cPIN ObMA== X-Forwarded-Encrypted: i=1; AL+hErH5h6tRzLb5m3qp0jwvaB8bp8XxL4EWkjnHLmFlulQlNuFv1sCoaF8wVeG8mD1Vliu4o9LgUU9MlUDqIYw=@vger.kernel.org X-Gm-Message-State: APuU4Z/iPLIEKLhl7Ajf9UzANXcAaIEUXnleMmkGOf1nhp/yzDsPXU7d b4zGdhM6aj7LPaPnbVapAy7jCY8ebeDFdUiuwV/0FlxhIFmyo+klS7fy X-Gm-Gg: AZFdTZf9MJ8grJZkUJO/h1rJn9YesnFSfR2zZchpDAGqAJG6UmC36Qtm8u7Kw+5TWqt Kk+maPACsAAm2XWrVsQtYoaOtoVutM/IslIDT2E1Fvafzv8BzIDScx6VWKo0Oj8jvHPmL3P0Fme 8pa5N42bNHkp3bg8LsumitanzNg8kd9htCbIo77EJy42o5cQagqM8UZsuAqd4rDAzQfoXCyqNfL Ks+ld6Ap9MfC5uCr2wMc4xerT20TaVuDf4tWSejv12IvSjMCuy6K9rj9RZQ2mUBVWtCTCpaw0Mr RGIGK8fZGR2cUn9lKhazcp1iHHSzLGYys3fNVfMJGiJ59tA12OrlxTit5oL6aKgPF2T/cDH0JNc 1Gdk5cOdJPgEIrXizi3gNGDHHShFJMZ71SQ9XzoCud5IgwogWAWWu6UjpCJC7zHZCjf9gMq6SkW RnI7wX/PwTyQbGe6tUrpQ3wcCYNRwhKAhOlG1CcLRJXrPMR9vkLdLhgFTZR5rLHlqf/t5LDmmyZ uvt3wwL/TlxYcy5rBAb+jvH4bAoFfOI+lb0ueSFhr7SxsBQlpLnmhHCvLOM9/7CEj9sDZLJVx1h u2Cvl7c8AInvr6aG5VpjFNkBjbfPptoeiPYzapyUyCGiFM4+kfKmtR6BmTeWT/ndSTY= 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-kernel@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