Re: [PATCH 1/3] xhci: dbgtty: Fix unregister on tty_register_driver() failure

Mathias Nyman <[email protected]>
Newsgroups org.kernel.vger.linux-usb,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
On 7/20/26 23:27, Lucas De Marchi wrote:
> 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: [email protected] # v5.10
> Cc: Mathias Nyman <[email protected]>
> Cc: Greg Kroah-Hartman <[email protected]>
> Signed-off-by: Lucas De Marchi <[email protected]>
> ---

Thanks

Added series to queue

-Mathias
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.