From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE9D34E50D7; Fri, 9 Oct 2026 14:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791556113; cv=none; b=re7ocN2S6mQrWcAm2xAmD2xwjaeOff92whsXjSgxwD6sMlqiGgsr41fSxYcmp5z7Ai8WXOSgX80Qem9xSrrsVH7gjeO4HylFZIZGckoWEevti+u0VVPvM8EhB1A82XYr7L2svfdoNka2vmPKSNLCveuKAhSVaB7XqDKOrD8hzk0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791556113; c=relaxed/simple; bh=ZYJF+7G3EzTjpVw1Mu/GeA+7dLarW0zHh9fGfkSMMtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hhn0T8AkhQ6q4YGbVExFNfk9TifV63YV/QwKgPKxtVrBI3CfKMtkb49eRot2pd04o1N2Sg1ER47YXikjVkzdqvAP3l3bCQHk5UF8WuCkRMiHp9uf8+dd3CLLJ1Btef5WVv+IoDNMOVuga1+f1YpBU8SFeEE6IGrlkXDEyTMvGIQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=gC62fBiz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="gC62fBiz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A5B61F000FF; Fri, 9 Oct 2026 14:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791556112; bh=zbl+AusfATSqYDdCwngX+mGj2/wyr9Vxkujg0MmOF1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gC62fBizmQF7OFvxMsc5SaOYD4Xq1KdKx9HdsCFNMCybYFViFLdyIT3rdpZFbUDKz IDSBkB6YrLsQQdMAdvaXd0HHhSW3HSxMzZb7UgWpF1x0/lViDuJG4jjOrFE22HgL8J XbYyyEehYX7wrQCVZu5dKDA5yWpWf0Mrf+YBcy+Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Minseo Kim , Alan Stern , stable Subject: [PATCH 6.18 176/403] USB: gadget: dummy-hcd: Fix wait for outstanding request completions Date: Fri, 9 Oct 2026 16:08:57 +0200 Message-ID: <20261009140956.233076631@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261009140952.119038291@linuxfoundation.org> References: <20261009140952.119038291@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alan Stern commit b263ff9b0fc5c1f371d65c4eb196b31263d039ff upstream. The dummy-hcd driver emulates synchronize_irq() by waiting until its private callback_usage counter drops to 0 (with the private lock not held). This counter is incremented whenever a gadget driver callback occurs (which requires the private lock to be dropped), but not when a request completion handler is called. This is an oversight. Request completion is triggered by timer interrupts (emulating device IRQs in a real UDC), and the interrupt handlers are supposed to have completed when the synchronize_irq() emulation routine returns -- they aren't supposed to be in the middle of a completion callback. If this happens it can lead to a gadget driver's unbind routine running before all outstanding request completions have finished, maybe even allowing the gadget driver's module to be unloaded while a completion handler is still running. Fix the oversight by incrementing the callback_usage value across request completion callbacks. Link: https://lore.kernel.org/linux-usb/7a87e293-633c-4100-aa8d-91560ba5e5c5@rowland.harvard.edu/ Fixes: 7dbd8f4cabd9 ("USB: dummy-hcd: Fix erroneous synchronization change") Tested-by: Minseo Kim Signed-off-by: Alan Stern Cc: stable Link: https://patch.msgid.link/f23b9e1a-f110-441a-a1d8-95f442ec09d5@rowland.harvard.edu Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/udc/dummy_hcd.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/usb/gadget/udc/dummy_hcd.c +++ b/drivers/usb/gadget/udc/dummy_hcd.c @@ -343,9 +343,11 @@ static void dummy_giveback(struct dummy { bool fifo = req == &dum->fifo_req; + ++dum->callback_usage; spin_unlock(&dum->lock); usb_gadget_giveback_request(_ep, &req->req); spin_lock(&dum->lock); + --dum->callback_usage; if (fifo) dum->fifo_req_busy = 0; } @@ -759,11 +761,13 @@ static int dummy_queue(struct usb_ep *_e req->req.complete = fifo_complete; list_add_tail(&req->queue, &ep->queue); + ++dum->callback_usage; spin_unlock(&dum->lock); _req->actual = _req->length; _req->status = 0; usb_gadget_giveback_request(_ep, _req); spin_lock(&dum->lock); + --dum->callback_usage; } else list_add_tail(&req->queue, &ep->queue); spin_unlock_irqrestore(&dum->lock, flags);