From: Olivier Sobrie <olivier@sobrie.be>
To: Jan Dumon <j.dumon@option.com>, Dan Williams <dcbw@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
netdev@vger.kernel.org, Olivier Sobrie <olivier@sobrie.be>
Subject: [PATCH v2 02/11] hso: fix crash when device disappears while serial port is open
Date: Fri, 30 Jan 2015 13:21:54 +0100 [thread overview]
Message-ID: <1422620523-15021-3-git-send-email-olivier@sobrie.be> (raw)
In-Reply-To: <1422620523-15021-2-git-send-email-olivier@sobrie.be>
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>
---
drivers/net/usb/hso.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index cb0bcc1..3a6c630 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -1270,7 +1270,6 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
goto err_out;
D1("Opening %d", serial->minor);
- kref_get(&serial->parent->ref);
/* setup */
tty->driver_data = serial;
@@ -1289,7 +1288,8 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
if (result) {
hso_stop_serial_device(serial->parent);
serial->port.count--;
- kref_put(&serial->parent->ref, hso_serial_ref_free);
+ } else {
+ kref_get(&serial->parent->ref);
}
} else {
D1("Port was already open");
@@ -1339,8 +1339,6 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
usb_autopm_put_interface(serial->parent->interface);
mutex_unlock(&serial->parent->mutex);
-
- kref_put(&serial->parent->ref, hso_serial_ref_free);
}
/* close the requested serial port */
@@ -1391,6 +1389,16 @@ static int hso_serial_write_room(struct tty_struct *tty)
return room;
}
+static void hso_serial_cleanup(struct tty_struct *tty)
+{
+ struct hso_serial *serial = tty->driver_data;
+
+ if (!serial)
+ return;
+
+ kref_put(&serial->parent->ref, hso_serial_ref_free);
+}
+
/* setup the term */
static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
{
@@ -3215,6 +3223,7 @@ static const struct tty_operations hso_serial_ops = {
.close = hso_serial_close,
.write = hso_serial_write,
.write_room = hso_serial_write_room,
+ .cleanup = hso_serial_cleanup,
.ioctl = hso_serial_ioctl,
.set_termios = hso_serial_set_termios,
.chars_in_buffer = hso_serial_chars_in_buffer,
--
2.2.0
next prev parent reply other threads:[~2015-01-30 12:21 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-20 12:29 [PATCH 00/11] hso: fix some problems with reset/disconnect path Olivier Sobrie
2015-01-20 12:29 ` [PATCH 01/11] hso: remove useless header file timer.h Olivier Sobrie
2015-01-20 12:29 ` [PATCH 02/11] hso: fix crash when device disappears while serial port is open Olivier Sobrie
2015-01-20 12:29 ` [PATCH 03/11] hso: fix memory leak when device disconnects Olivier Sobrie
2015-01-20 12:29 ` [PATCH 04/11] hso: fix memory leak in hso_create_rfkill() Olivier Sobrie
2015-01-20 12:29 ` [PATCH 05/11] hso: fix small indentation error Olivier Sobrie
[not found] ` <1421756978-4093-6-git-send-email-olivier-Ui3EtX6WB9GzQB+pC5nmwQ@public.gmane.org>
2015-01-20 12:29 ` [PATCH 06/11] hso: rename hso_dev into serial in hso_free_interface() Olivier Sobrie
2015-01-20 12:29 ` [PATCH 07/11] hso: replace reset_device work by usb_queue_reset_device() Olivier Sobrie
2015-01-20 12:29 ` [PATCH 08/11] hso: move tty_unregister outside hso_serial_common_free() Olivier Sobrie
2015-01-20 12:29 ` [PATCH 09/11] hso: update serial_table in usb disconnect method Olivier Sobrie
2015-01-20 12:29 ` [PATCH 10/11] hso: add missing cancel_work_sync in disconnect() Olivier Sobrie
2015-01-20 12:29 ` [PATCH 11/11] usb: core: fix a race with usb_queue_reset_device() Olivier Sobrie
2015-01-20 13:48 ` Oliver Neukum
2015-01-20 15:10 ` Olivier Sobrie
2015-01-20 15:26 ` Alan Stern
2015-01-20 16:30 ` Olivier Sobrie
2015-01-21 13:55 ` Olivier Sobrie
2015-01-21 18:52 ` Alan Stern
2015-01-20 13:13 ` [PATCH 04/11] hso: fix memory leak in hso_create_rfkill() Oliver Neukum
2015-01-20 15:10 ` Olivier Sobrie
2015-01-20 18:41 ` Dan Williams
2015-01-30 12:21 ` [PATCH v2 00/11] hso: fix some problems in the disconnect path Olivier Sobrie
2015-01-30 12:21 ` [PATCH v2 01/11] hso: remove useless header file timer.h Olivier Sobrie
2015-01-30 12:21 ` Olivier Sobrie [this message]
2015-01-30 12:21 ` [PATCH v2 03/11] hso: fix memory leak when device disconnects Olivier Sobrie
2015-01-30 12:21 ` [PATCH v2 04/11] hso: fix memory leak in hso_create_rfkill() Olivier Sobrie
2015-01-30 12:21 ` [PATCH v2 05/11] hso: fix small indentation error Olivier Sobrie
2015-01-30 12:21 ` [PATCH v2 06/11] hso: rename hso_dev into serial in hso_free_interface() Olivier Sobrie
2015-01-30 12:21 ` [PATCH v2 07/11] hso: replace reset_device work by usb_queue_reset_device() Olivier Sobrie
2015-01-30 12:22 ` [PATCH v2 08/11] hso: move tty_unregister outside hso_serial_common_free() Olivier Sobrie
2015-01-30 12:22 ` [PATCH v2 09/11] hso: update serial_table in usb disconnect method Olivier Sobrie
2015-01-30 12:22 ` [PATCH v2 10/11] hso: add missing cancel_work_sync in disconnect() Olivier Sobrie
2015-01-30 12:22 ` [PATCH v2 11/11] hso: fix rfkill name conflicts Olivier Sobrie
2015-01-30 15:47 ` Dan Williams
2015-01-30 16:15 ` Olivier Sobrie
2015-01-30 16:59 ` Dan Williams
[not found] ` <1422620523-15021-1-git-send-email-olivier-Ui3EtX6WB9GzQB+pC5nmwQ@public.gmane.org>
2015-02-01 20:33 ` [PATCH v2 00/11] hso: fix some problems in the disconnect path David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1422620523-15021-3-git-send-email-olivier@sobrie.be \
--to=olivier@sobrie.be \
--cc=dcbw@redhat.com \
--cc=j.dumon@option.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).