From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795961308; b=zGaMuxvKwYuHBCD8ihl2j+NLDvHPT1B9HV88yrpjp1+suJhdDbpOtwnknVfBiHJq0GBI pxcvmI1e2CFjNF/cl3Eoeq98VxGtCxACdyxK6xGhm0TmFhXFJJ0IRnY+c3Z0J7iaDMTth Q5XVnEQBFLDTznOTa8CeEN/cjlGfhTZiRTTxFsOvIckAmsvIaGbKnyuVFqq3QfiRC2NcT VargYaP9iYPNXl6hB7vUDaR0xuFeyeDnTjojnawHQb0hORSjDnyDmLlr0+UCv5RrVjHO4 CVtqBFPtvAXx/UGM6VoUR7U1/QHCCiioWO3t0vNcHndA1/SoO4iHdmRTxJ96kD3iQNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795961308; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=wQO7UZhxsgKW/4thyun0PPC9pyykbBNUwbAW03Ueqcw=; b=gYuOE/p1b/m1hwh/8uqKL7bY1bW8HsZCLj3M+CqXxB0/E79xIaCTsekN0KwShYDkwSOe aZodrHgQNdf2Vtm57YgCC0Dkjy9fhbbF+4z0EIgnmz7gVRUL/PpJx5PNNHdrR4GoDogjI vBarAwOdEVaoH6F+Nd2RW58hIiZzxU4UFjcx9/qTslZB7Q3BB00g5A/fG59EXmW1zYjFW dNXVsrFGM+87k37L/f4e5uvhQAFJMokC+33A0/ynKSo24S1V+D9ghayzvjiYkQkJ0ZvNA uaVlzOCpmLBY0Mthlf1Q2hvZMNiFpCx8YCORkGMhL+XnX3ubWDabdFuTLHZEozM0M3Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=n6nqGd5o; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33BAC606A31C for ; Sun, 29 Nov 2026 14:08:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=n6nqGd5o Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF2631F00896; Sun, 29 Nov 2026 14:08:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795961308; bh=wQO7UZhxsgKW/4thyun0PPC9pyykbBNUwbAW03Ueqcw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=n6nqGd5oy97CPweNOtlIxkvGB5b06zl/Y9bJsczaItuRBjMQXsTtEsalsuPJO5Rfd 50LVeIppYgKRFhQ4r0BtVsoSu8b7Lx/yfVopjk/rwIxxQrK+JeDZnex/gltKQocapy PRZDdy2aCIQy00fHk7Oq0K+tJArK9o7XFdiWIZx5FediN0FynD4ReEwYIAur2mNWa6 GUCbchDqi00Gm8HEE6zt/4DkZA77diDF8aW/QhZrFJfn9c6aT7EzB1q+YLHeT4dI3p RsFhw1pb5vWC8hxfp4U5Oe/fFnNNpUUxupn5iRBCtczclQIVgAsYPlkggd19cDhFeg upEuCI+853Few== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] usb: gadget: f_printer: take dev->lock on copy_from_user() failure Reply-To: sashiko-reviews@lists.linux.dev To: "Jaegyun Lee" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261129135824.450263-1-dreams200260@gmail.com> References: <20261129135824.450263-1-dreams200260@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 14:08:27 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] usb: gadget: f_printer: interrupt re-entrancy deadlock in tx_complete() [1] -- commit 22f7b45ca310736e9c1b3990fe322c25d2ea2100 Author: Jaegyun Lee usb: gadget: f_printer: take dev->lock on copy_from_user() failure This commit takes dev->lock around list_add() when copy_from_user() fails in printer_write() to prevent list corruption against tx_complete(). Link: https://lore.kernel.org/all/sashiko-outbox-206117@kernel.org/ > diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget= /function/f_printer.c > index 29c8150a7d0ab..e817d8c854afa 100644 > --- a/drivers/usb/gadget/function/f_printer.c > +++ b/drivers/usb/gadget/function/f_printer.c > @@ -665,7 +665,9 @@ printer_write(struct file *fd, const char __user *buf= , size_t len, loff_t *ptr) > spin_unlock_irqrestore(&dev->lock, flags); > =20 > if (copy_from_user(req->buf, buf, size)) { > + spin_lock_irqsave(&dev->lock, flags); > list_add(&req->list, &dev->tx_reqs); > + spin_unlock_irqrestore(&dev->lock, flags); > mutex_unlock(&dev->lock_printer_io); > return bytes_copied; > } [Severity: High] This problem wasn't introduced by this patch, but can tx_complete() deadlock on dev->lock [1] when a UDC invokes completion callbacks with local interrupts enabled? drivers/usb/gadget/function/f_printer.c:tx_complete() { ... spin_lock(&dev->lock); /* Take the request struct off the active list and put it on the * free list. */ list_del_init(&req->list); list_add(&req->list, &dev->tx_reqs); ... spin_unlock(&dev->lock); } Because tx_complete() uses plain spin_lock(&dev->lock), a hardware interrupt on the same CPU can re-enter the driver and spin forever on dev->lock: tx_complete() spin_lock(&dev->lock) ... spin_lock_irqsave(&dev->lock, flags) <-- spins forever Using spin_lock_irqsave() and spin_unlock_irqrestore() in tx_complete() would avoid this lockup. [1] https://sashiko.dev/#/bug/linux-5e89bb2a-e067-4f0b-92c6-b7efb6d7b5ea --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129135824.4502= 63-1-dreams200260@gmail.com?part=3D1