hso: fix crash when device disappears while serial port is open
authorOlivier Sobrie <olivier@sobrie.be>
Fri, 30 Jan 2015 12:21:54 +0000 (13:21 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sun, 1 Feb 2015 20:33:26 +0000 (12:33 -0800)
commit29bd3bc1194c624ce863cab2a7da9bc1f0c3b47b
tree4d766ae489b8f2812cce07ca73e9f5d450f989d7
parent3ac856c100f4eccdd8e4f56704f32ebdd5f4dd80
hso: fix crash when device disappears while serial port is open

When the device disappear, the function hso_disconnect() is called to
perform cleanup. In the cleanup function, hso_free_interface() calls
tty_port_tty_hangup() in view of scheduling a work to hang up the tty if
needed. If the port was not open then hso_serial_ref_free() is called
directly to cleanup everything. Otherwise, hso_serial_ref_free() is called
when the last fd associated to the port is closed.

For each open port, tty_release() will call the close method,
hso_serial_close(), which drops the last kref and call
hso_serial_ref_free() which unregisters, destroys the tty port
and finally frees the structure in which the tty_port structure
is included. Later, in tty_release(), more precisely when release_tty()
is called, the tty_port previously freed is accessed to cancel
the tty buf workqueue and it leads to a crash.

In view of avoiding this crash, we add a cleanup method that is called
at the end of the hangup process and we drop the last kref in this
function when all the ports have been closed, when tty_port is no
more needed and when it is safe to free the structure containing the
tty_port structure.

Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/usb/hso.c
This page took 0.02795 seconds and 5 git commands to generate.