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=1796403756; b=xyEgJuvfjZJ/D2CMm6dctjz0jsascUfb27idFktC6UBzEY2jSKG7GXk+6d+u+cutF05K IKbQOWl6JVGcj2sPweJcTA0yAtYpp8oox/mfdBNn9bhNkwzzmNvNT6AiRelKqM/W8lt4D rOXbdZehxJ/gn4g3dS/O+S81TfIbL7e1oFeyFQyrPbxz8NVP5O6+tGKpuZyrSIAlqb0AK K41sTVZSSFAGoMrxUNaVlFQn58wJE2PVNTRTPWyxMpPeq2G4RWtty1s15a45KlFAcsCf5 Nr4yWYYDGgdp3C0BqZGE5HB9013ZcqFaPm9uhcDY2Uj7988r2YCzneDNVf5jzwrw6tw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796403756; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=RsNjjZF7qDET+rUgU/Y+ZS6//wtG+/Jzg2hVfmpI8zs=; b=ECc1uuA4vcg2zu4n1m5wnh4VyQApFze2WEgYzJStXKvFI4ugpTjSDjTO6Sdy2bag/mpr 2FL9MX03RhovvJbEdodpY1XquTOMl4NQ1qFMk5Tz+qWYufKP3D7+1VVLiLKdA4MWWBpf1 XKVrC6z6j1bb72TE2Y1lNWhNEen8coe+Wtiu7keYue/pBadD9Po6lin7Lk8FyH3Sa+5oD UINmHUFZnNaAcIb1n7TS1+WSalkw+Slt981oiUbliPPQBpdj8qOwdTYGftTTE8vMF3Frl h0+XX19gaUbGwx44TifNBx/zdN1npo0HOVOwjJAThlwQNtfm/BBtJa89KqfVHnH8xGQ== 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=ltK8tAU5; 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 4D90E606A32C for ; Fri, 4 Dec 2026 17:02:36 +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=ltK8tAU5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C679E1F00ACB; Fri, 4 Dec 2026 17:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796403755; bh=RsNjjZF7qDET+rUgU/Y+ZS6//wtG+/Jzg2hVfmpI8zs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ltK8tAU5ovwQVwJkne1zia8r4SOWPVZeCc2vu6X4zgu/LpbISFvhwRf3uF35c82f9 WtIZbhmtrY1AG8sber3d1rHszRTfeAc5IZ/IOypaXzhJ8qB3KZJ819Z8Av00OXax35 OLAdkuk1Z3Z4cccKuujZ1ym1t9Dk3d46J+F9cEvGNeeTY2jq4xK2nHOLMUkh21bNEa CFvPDSTZEFnUG4YA0CXAoXtDV6iD6UXHTyC/JWmXWjK+iSl+BAaYJHGtD1vfk7f9Xx KGhfN987ljlwnFb+cBWYayKRh6FJgdTpMk83z2S1XfXHPpvUaP2QYZLiYnIV2cNxps jRgJcSSxtueJA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] USB: serial: mos7840: fix use-after-free in write path Reply-To: sashiko-reviews@lists.linux.dev To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn> Cc: linux-usb@vger.kernel.org In-Reply-To: <20261204162226.17678-1-25031212351@stu.xidian.edu.cn> References: <20261204162226.17678-1-25031212351@stu.xidian.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:02:35 +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 3 potential issues to consider: - [Medium] USB: serial: mos7840: uninitialized status return in mos7840_port_probe() - [Medium] usb: serial: mos7840: mos7840_close() leaves post-close writes unblocked - [Low] USB: serial: mos7840: inaccurate Fixes tag and URB lifetime claim in commit log -- commit c490b6baa39966d1389b0f8fab083c3a14fe5814 Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn> > USB: serial: mos7840: fix use-after-free in write path > > The write URB pool is allocated at open() and freed at close(), but the > TTY line discipline can still invoke the driver write() callback after > close() has returned. tty_release() calls the driver close() before it > cancels the flip-buffer work, so a port that is still processing > received data can flush pending echo characters to the driver and > dereference the freed URBs. > > A KASAN slab-use-after-free was observed in mos7840_write() while > reading the transfer buffer of a freed urb, followed by an "urb > submitted while active" warning when the same freed urb was resubmitted. > > Give the write URB pool the same lifetime as the port instead: allocate > it at port probe and free it at port removal, after the URBs have been > killed. This matches how usb-serial core manages its own read and write > URBs and makes the write callback safe against a racing close(). > > The issue was found by exercising the driver with a virtual USB device > during automated testing. The change has only been compile tested; no > physical device was available for runtime testing. > > Fixes: 0de9a7024e7a ("USB: overhaul of mos7840 driver") > Cc: stable@vger.kernel.org > Co-developed-by: Bin Yu > Signed-off-by: Bin Yu > Co-developed-by: Cheng Wen > Signed-off-by: Cheng Wen > Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> [Severity: Low] Should the Fixes tag point to 3f5429746d91 ("USB: Moschip 7840 USB-Serial Driver") instead of 0de9a7024e7a ("USB: overhaul of mos7840 driver")? The initial driver commit already allocated write_urb_pool[] in mos7840_open() and freed it in mos7840_close() without clearing the pointers. Also, usb-serial core poisons its read and write URBs in usb_serial_disconnect() and frees them in usb_serial_port_release(), not during port_remove(). > diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c > index ef803e74ab4bc..f4eda9bc7b236 100644 > --- a/drivers/usb/serial/mos7840.c > +++ b/drivers/usb/serial/mos7840.c [ ... ] > @@ -751,14 +726,6 @@ static void mos7840_close(struct usb_serial_port *po= rt) > for (j =3D 0; j < NUM_URBS; ++j) > usb_kill_urb(mos7840_port->write_urb_pool[j]); > =20 > - /* Freeing Write URBs */ > - for (j =3D 0; j < NUM_URBS; ++j) { > - if (mos7840_port->write_urb_pool[j]) { > - kfree(mos7840_port->write_urb_pool[j]->transfer_buffer); > - usb_free_urb(mos7840_port->write_urb_pool[j]); > - } > - } > - > usb_kill_urb(mos7840_port->read_urb); > mos7840_port->read_urb_busy =3D false; > =20 [Severity: Medium] Can a racing post-close mos7840_write() still submit write URBs and trigger LED activity after mos7840_close() returns? CPU0 CPU1 tty_port_close_start() ... mos7840_bulk_in_callback() tty_flip_buffer_push() mos7840_close() usb_kill_urb(write_urb_pool[]) usb_kill_urb(read_urb) serial_port_shutdown() usb_autopm_put_interface() flush_to_ldisc() ... mos7840_write() usb_submit_urb(urb) <-- post-close Because mos7840_close() kills write_urb_pool[] before read_urb and does not poison the pool, a queued ldisc write can still submit a bulk-out URB and arm led_urb/led_timer1 after the runtime PM reference is dropped. If the port is reopened while that write URB is still queued, mos7840_open() calls usb_clear_halt() on the busy bulk-out endpoint, triggering an EHCI warning or xHCI reset refusal and leaving host and device data toggles out of sync. On suspend, mos7840_suspend() skips closed ports and never poisons write_urb_pool[] or stops the LED timers and URB, leaving them active on a suspended device. Killing read_urb first and poisoning write_urb_pool[] in mos7840_close() (unpoisoning it in mos7840_open()) would prevent post-close submissions. [ ... ] > @@ -1521,7 +1488,9 @@ static int mos7840_port_probe(struct usb_serial_por= t *port) > struct usb_serial *serial =3D port->serial; > unsigned long device_flags =3D (unsigned long)usb_get_serial_data(seria= l); > struct moschip_port *mos7840_port; > + struct urb *urb; > int status; > + int j; > int pnum; > __u16 Data; > =20 > @@ -1542,6 +1511,19 @@ static int mos7840_port_probe(struct usb_serial_po= rt *port) > mos7840_port->port =3D port; > spin_lock_init(&mos7840_port->pool_lock); > =20 > + /* Initializing the write urb pool */ > + for (j =3D 0; j < NUM_URBS; ++j) { > + urb =3D usb_alloc_urb(0, GFP_KERNEL); > + if (!urb) > + goto error; > + mos7840_port->write_urb_pool[j] =3D urb; > + > + urb->transfer_buffer =3D kmalloc(URB_TRANSFER_BUFFER_SIZE, > + GFP_KERNEL); > + if (!urb->transfer_buffer) > + goto error; > + } > + > /* minor is not initialised until later by > * usb-serial.c:get_free_serial() and cannot therefore be used > * to index device instances */ [Severity: Medium] Does mos7840_port_probe() return an uninitialized status if usb_alloc_urb() or kmalloc() fails here? Both error branches jump to error before status is assigned, so the function frees mos7840_port and returns uninitialized status. If status happens to be zero (for example under CONFIG_INIT_STACK_ALL_ZERO=3Dy), usb_serial_device_probe() proceeds to register the tty device with NULL port driver data, causing a NULL pointer dereference on subsequent open or removal. Setting status =3D -ENOMEM before jumping to error would fix this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204162226.1767= 8-1-25031212351@stu.xidian.edu.cn?part=3D1