Linux USB
 help / color / mirror / Atom feed
* [PATCH 1/3] xhci: dbgtty: Fix unregister on tty_register_driver() failure
@ 2026-07-20 20:27 Lucas De Marchi
  2026-07-20 20:27 ` [PATCH 2/3] xhci: dbgtty: Fix unregister on tty_alloc_driver() failure Lucas De Marchi
  2026-07-20 20:27 ` [PATCH 3/3] xhci: dbgtty: Drop extra call to idr_destroy() Lucas De Marchi
  0 siblings, 2 replies; 3+ messages in thread
From: Lucas De Marchi @ 2026-07-20 20:27 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, demarchi, Lucas De Marchi, stable,
	Mathias Nyman

If tty_register_driver() fails, it drops the reference, but fails to set
the global dbc_tty_driver to NULL, causing the unregister to be called
again when module exits.

On module unload dbc_tty_exit() only gates its cleanup on the driver
pointer being non-NULL, so it operates on the already-freed driver:

    module_init(xhci_hcd_init)
      xhci_hcd_init()
        xhci_dbc_init()                       [return value ignored]
          dbc_tty_init()
            tty_register_driver() fails
              tty_driver_kref_put()           -> driver freed
              (dbc_tty_driver left dangling)
    ...
    module_exit(xhci_hcd_fini)
      xhci_hcd_fini()
        xhci_dbc_exit()
          dbc_tty_exit()
            if (dbc_tty_driver)               -> true (dangling)
              tty_unregister_driver()         -> use-after-free

Fixes: 4521f1613940 ("xhci: dbctty: split dbc tty driver registration and unregistration functions.")
Cc: stable@vger.kernel.org # v5.10
Cc: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Lucas De Marchi <ldemarchi@nvidia.com>
---
 drivers/usb/host/xhci-dbgtty.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 2e7384c6b6ec..01decd46f313 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -651,6 +651,7 @@ int dbc_tty_init(void)
 		pr_err("Can't register dbc tty driver\n");
 		tty_driver_kref_put(dbc_tty_driver);
 		idr_destroy(&dbc_tty_minors);
+		dbc_tty_driver = NULL;
 	}
 
 	return ret;
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-20 20:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 20:27 [PATCH 1/3] xhci: dbgtty: Fix unregister on tty_register_driver() failure Lucas De Marchi
2026-07-20 20:27 ` [PATCH 2/3] xhci: dbgtty: Fix unregister on tty_alloc_driver() failure Lucas De Marchi
2026-07-20 20:27 ` [PATCH 3/3] xhci: dbgtty: Drop extra call to idr_destroy() Lucas De Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox