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=1796040379; b=V7gjCS1v8n0X3HjZjPFGAfCW2d+kGWLCvmttrV4Ke8GkRmPeCv93a7uFlU7wolH31Cw2 wWTgoQrd7gBtVL1ILORqx5VNEdt0NtBYRTao7i8kUUjWxrOnLBnTvhB6EIHaDXLv8rnwq IfPZwJynrktj02l90TkBFMa3bGuYBQkfbLZsf9GYkvuoZc6hCfB39MhgeM8/kw5HTOIaf 9bTjgHakXl2Orxf6IsccoKugFnlPeQI9A9xuG4lJzRgc1rOswe88nykozUvFUMpWq7lME DkipY6TlSozGl/+BxuQQNUlBDyUFonzVNQuYUHsD9eFG6Ac3+DjsF/b3Hj+iDWpf0zA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796040379; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ubcwx75T4fDUrQoAliV6/4rn2GZAoHJB5fV2WQpmdgI=; b=ZMFI9Z9USvTW7Vt6YjOZsJWT0GvmFWT99CcSicwOcDN0zyzx8zZa8cJkKhBS85JC3HLk Fl8cbo5He6hB/o9UZdlDpi9wbG345Q+X+id98435NDfWV/jKBlOXkhfHWCGteFKj3tMD6 jT9O69FmpHeqTRyZc5yw27weNpmBMK4vWMkhbGm6gbDgoHlnClNE9dzIJ4oWKGD/g+st+ 7CkGPbtNTSrPFFxrT+6y9Aj4HS6ME+Zt3pIdctPZgTYdJBPqoEVBgTkrUKs7Z/kEQBplm IsMmPaaK6k1M4YJTDqoIOs65EUnjVwMUzG2g94l4ke4zjKulfn+4iIMCEelOuzzFXKQ== 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=kKWAyVNs; 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 232F2606A31C for ; Mon, 30 Nov 2026 12:06:18 +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=kKWAyVNs Received: by smtp.kernel.org (Postfix) with ESMTPSA id A23D61F00899; Mon, 30 Nov 2026 12:06:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796040378; bh=ubcwx75T4fDUrQoAliV6/4rn2GZAoHJB5fV2WQpmdgI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=kKWAyVNsKhKpFjoeDDi1HVxSSoBm2GuPo1q3HpusJL6rE4YIaMjdjtbYmxVitGO5t ugodyIopXwIhGGcjAIpLXz9+7XgImkic5I5cuQhbGKDasDz0MEN8DpkBNdSMox8Iwr ERN23CdCQSSiI/KaXH66xioGbefCD/qiKAt+rTzQmHdMlcS3Sz7f1ZfZ1xma7DFDwL YdY2abeAJugJwfHkE3U3PJa1e/ECj8pTZK0VDT89ja9+wDe6HMj/3O3BYqaowG0ETz X9XA+Q4Ov5KJA+y+Xk7/R8nXJluKptSvPSXDD6jAiiPjX/thrDefYFXkzgWXsvPhRz m6/xiOiXsVuEQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] USB: serial: opticon: fix use-after-free in write completion Reply-To: sashiko-reviews@lists.linux.dev To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn> Cc: linux-usb@vger.kernel.org In-Reply-To: <20261130114616.31927-1-25031212351@stu.xidian.edu.cn> References: <20261130114616.31927-1-25031212351@stu.xidian.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 12:06:18 +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 1 potential issue to consider: - [High] usb: serial: opticon: use-after-free of port via work queued in port_remove() -- commit 4e868399fee2ff649a085893481b9d2e4c6c3450 Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn> USB: serial: opticon: fix use-after-free in write completion This commit kills anchored write URBs in opticon_port_remove() before freeing the port's private data to prevent a use-after-free on deferred URB giveback. > diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c > index 152dfc901cd8f..af53ed13577e9 100644 > --- a/drivers/usb/serial/opticon.c > +++ b/drivers/usb/serial/opticon.c > @@ -368,6 +368,7 @@ static void opticon_port_remove(struct usb_serial_por= t *port) > { > struct opticon_private *priv =3D usb_get_serial_port_data(port); > =20 > + usb_kill_anchored_urbs(&priv->anchor); > kfree(priv); > } [Severity: High] Can killing anchored write URBs in opticon_port_remove() cause a use-after-free of struct usb_serial_port via port->work? When usb_kill_anchored_urbs() kills an in-flight write URB here, it synchronously runs opticon_write_control_callback(), which unconditionally schedules port->work: drivers/usb/serial/opticon.c:opticon_write_control_callback() { ... spin_lock_irqsave(&priv->lock, flags); --priv->outstanding_urbs; priv->outstanding_bytes -=3D urb->transfer_buffer_length; spin_unlock_irqrestore(&priv->lock, flags); usb_serial_port_softint(port); } In usb_serial_disconnect(), cancel_work_sync(&port->work) runs in the first port loop before device_del(&port->dev) invokes opticon_port_remove(). Nothing cancels port->work after opticon_port_remove() returns, so when the tty has already been closed, usb_serial_put() immediately frees port in usb_serial_port_release() while port->work (usb_serial_port_work) is still queued: CPU0 CPU1 (system_wq) usb_serial_disconnect() cancel_work_sync(&port->work) device_del(&port->dev) ... opticon_port_remove() usb_kill_anchored_urbs() ... opticon_write_control_callback() usb_serial_port_softint(port) schedule_work(&port->work) usb_serial_put(serial) ... usb_serial_port_release() kfree(port) usb_serial_port_work() tty_port_tty_wakeup(&port->port) <-- use-after-free Cancelling port->work after usb_kill_anchored_urbs() (or not scheduling port->work when the URB fails with -ENOENT) would avoid this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130114616.3192= 7-1-25031212351@stu.xidian.edu.cn?part=3D1