From nobody Mon Sep 28 15:32:48 2026 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 968B935FF6E; Thu, 20 Aug 2026 14:55:43 +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=1787237744; cv=none; b=GoLdZZu0Eo4la1c665629/AXpZFWyGbJ/DaknvfKf5HTZWTNYBSIWWaMMdkD96sygqSlAplIMJH2pfubb+MOQ4yL2dc6kr2trDbcdkVWoocogbWIjxGXQsAgTATySh/hYoKKa9m5RdsbQ8s85Cv/PBpFwcOlBeZAQXj9kT9bV4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787237744; c=relaxed/simple; bh=PbU+elOpfjTkVbEZFnnE8odpHIA2v2q13MwBL5SBH2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tUqgfMwUWHVk7SE8tjogjG2vtEX79zvpPhZ2t0xTwdjBO9VlwOzr1rL6TReM2YOHiWJqM2oFAMUeKuH4EpK3w2Mvha8leGREXzihlGGEdPdNH2BQWuCdfZqNP8Z5QMaC4ZqSFNWgb+sOvGX/oGbshAk7TOrDuV6FrzacN3ziEWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xtj7Vao5; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xtj7Vao5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32F311F00A3A; Thu, 20 Aug 2026 14:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787237743; bh=KVZD0qsq1j+N11IUMNXG1IasgHvReK9xYRuzAdl7f04=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Xtj7Vao5P1a8UPr0yQxThoUVIpECNWoCkYvziUpZ7rW46LEkBQM72V8hCROYudQpL MBveC6NGb9g5eTsljjyh0hIxGXZzOHpOJCmsOzchDRMV6yjZchZGbWFmieKK05e23J Us6eyg4m4b1mrJujSisMV6CEWas+bRZpLHPOYdTa+ubCcaAdaQg7YS+K1bU0txZJi4 O2sgSJ4ATNv3WuLCnvRbJ+ManxL1lnHzY9PV5Lkes+Htwlyfo7nvD8ojlOcys/qxHc RnczEBa88sjddJRN9jFG2O+snvigVoliHRhKzwqb+qufOHK6zf2bTpwIApUtcF9r9m Age54yMx2uxmQ== Received: from johan by xi.lan with local (Exim 4.99.4) (envelope-from ) id 1wx4BA-00000001p31-48VO; Thu, 20 Aug 2026 16:55:40 +0200 From: Johan Hovold To: Johan Hovold Cc: Alan Stern , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+e5e28c3e953b2eebb16e@syzkaller.appspotmail.com, stable@vger.kernel.org Subject: [PATCH 1/2] USB: serial: fix port tear down use-after-free Date: Thu, 20 Aug 2026 16:54:01 +0200 Message-ID: <20260820145402.434447-2-johan@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260820145402.434447-1-johan@kernel.org> References: <20260820145402.434447-1-johan@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some drivers for multiport devices access port driver data from completion handlers of shared URBs submitted at attach() or first open() and stopped at last close() or disconnect(), respectively. A simple NULL check before accessing the driver data makes sure that a port state container has at least been allocated, but a completion handler can still race with port tear down. Reorder the disconnect handling so that ports are not deregistered (and their driver data freed) until after all ports have been hung up and the driver disconnect() callback has run so that all I/O has been stopped. Fixes: 2d93148ab698 ("USB: serial: fix lifetime and locking problems") Reported-by: syzbot+e5e28c3e953b2eebb16e@syzkaller.appspotmail.com Link: https://lore.kernel.org/all/6a7e6fb9.ec5dc6cc.21cb3f.00c0.GAE@google.= com/ Cc: stable@vger.kernel.org # 2.6.30 Cc: Alan Stern Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/usb-serial.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-seria= l.c index 17edc057a311..a4fbc849c0fa 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -1191,12 +1191,17 @@ static void usb_serial_disconnect(struct usb_interf= ace *interface) usb_serial_port_poison_urbs(port); wake_up_interruptible(&port->port.delta_msr_wait); cancel_work_sync(&port->work); - if (device_is_registered(&port->dev)) - device_del(&port->dev); } + if (serial->type->disconnect) serial->type->disconnect(serial); =20 + for (i =3D 0; i < serial->num_ports; ++i) { + port =3D serial->port[i]; + if (device_is_registered(&port->dev)) + device_del(&port->dev); + } + release_sibling(serial, interface); =20 /* let the last holder of this object cause it to be cleaned up */ --=20 2.54.0 From nobody Mon Sep 28 15:32:48 2026 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 4954C1A3160; Thu, 20 Aug 2026 14:55:43 +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=1787237744; cv=none; b=q2Z34fHAez+Vdy5gq6+WsG+Hj9h15XhOZOm7LJ70vFkU7jO/N+gNSoZhDcX7c1lDkcLSjouC2JhuWOF5sKygqeg07fEyVOxAeZcnARhyX1Hpco5fWOWqSsIUtVb4xSloEIl+iCi0Kf+iP6SgBp/kvd+nFP6AktwpwSWF8Ezny9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787237744; c=relaxed/simple; bh=SgFhHEDn+hyXiVIyNKDqOR5VodipRAz5cYCbN2CAwLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j1aTMzscRckVFunNBzjlOW1l/bLkY8hSFBx3Wv5qWmJPVVoEMmHEuDRvcpFhNX9eJZmbZ6T0XbR0WW40Buz0gerlqtJS6gGDOZpoBFkdi3ooI2enKKghoyoN0eh/dXP5X3q8Uoo1gxkDYkaTrjer9I7IZvwYKYlGq7s2sX00uoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IXE2E1FV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IXE2E1FV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30DE91F000E9; Thu, 20 Aug 2026 14:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787237743; bh=gpiz1AFuKOVRZzJUeStRF55Fo8fO48SSIgGLq/fRdGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IXE2E1FVTwxjxYgrUUztEM3wpRe3ZH5ZDOMLcp4csAiy4uAeWBmXgBgTSt4Wc20sA IMWYNFDTDay71Kf4Dj3LnWFEFHXNr0NBTBm7tVANw0AIimdPx9aGakwQinvPxoBr+1 3Kc/rNEJIP0K2EbkFaaITlW67tMoFzfhMor/vk4gCmtp4+Muqpf7vA8C7O2bFT+g7Y XjORFphBvkI8MyRe0dqSRuWtaVfbSu2y3is5M7s+nFzQD1u0/gt9E+9imWW71wg9LU giiTHnCYHlNRZ7gjrUQdq7O2W16Sj07EDT6vF5uvY4LXXFLAbnDyC1exxOSqtEUbjj oBaJwBHO7QYyQ== Received: from johan by xi.lan with local (Exim 4.99.4) (envelope-from ) id 1wx4BA-00000001p33-4B2h; Thu, 20 Aug 2026 16:55:40 +0200 From: Johan Hovold To: Johan Hovold Cc: Alan Stern , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/2] USB: serial: fix driver deregistration order Date: Thu, 20 Aug 2026 16:54:02 +0200 Message-ID: <20260820145402.434447-3-johan@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260820145402.434447-1-johan@kernel.org> References: <20260820145402.434447-1-johan@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" USB serial driver modules register one driver for the USB bus and one or more drivers for the ports on the USB serial bus. When unloading a driver module, the USB driver must be deregistered before the USB serial bus drivers so that I/O is stopped before unbinding the ports to avoid use-after-free in completion handlers accessing port data. Note that the order does not matter currently in the registration error path as the USB driver is not bound until after the USB serial drivers have been registered. Fixes: 765e0ba62613 ("usb-serial: new API for driver registration") Cc: stable@vger.kernel.org # 3.4 Cc: Alan Stern Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/usb-serial.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-seria= l.c index a4fbc849c0fa..08a9b6f8cf7d 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -1522,9 +1522,9 @@ int __usb_serial_register_drivers(struct usb_serial_d= river *const serial_drivers return 0; =20 err_deregister_drivers: + usb_deregister(udriver); while (sd-- > serial_drivers) usb_serial_deregister(*sd); - usb_deregister(udriver); err_free_driver: kfree(udriver); return rc; @@ -1543,9 +1543,15 @@ void usb_serial_deregister_drivers(struct usb_serial= _driver *const serial_driver { struct usb_driver *udriver =3D (*serial_drivers)->usb_driver; =20 + /* + * The USB driver must be deregistered before the USB serial drivers + * so that I/O is stopped before unbinding the ports. + */ + usb_deregister(udriver); + for (; *serial_drivers; ++serial_drivers) usb_serial_deregister(*serial_drivers); - usb_deregister(udriver); + kfree(udriver); } EXPORT_SYMBOL_GPL(usb_serial_deregister_drivers); --=20 2.54.0