]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
tty/n_gsm.c: fix a memory leak when gsmtty is removed
authorPan Xinhui <xinhuix.pan@intel.com>
Sat, 28 Mar 2015 02:42:56 +0000 (10:42 +0800)
committerSasha Levin <sasha.levin@oracle.com>
Wed, 10 Jun 2015 17:42:22 +0000 (13:42 -0400)
commit32c5ba5c6ec79e3196215ef849a3b2a6047c9cb5
treebfa0735f0a313ed416c3aac9f5995bf1f779b037
parent526639cb205517c4c83f7aef7884f00415990f3f
tty/n_gsm.c: fix a memory leak when gsmtty is removed

[ Upstream commit 8f9cfeed3eae86c70d3b04445a6f2036b27b6304 ]

when gsmtty_remove put dlci, it will cause memory leak if dlci->port's refcount is zero.
So we do the cleanup work in .cleanup callback instead.

dlci will be last put in two call chains.
1) gsmld_close -> gsm_cleanup_mux -> gsm_dlci_release -> dlci_put
2) gsmld_remove -> dlci_put
so there is a race. the memory leak depends on the race.

In call chain 2. we hit the memory leak. below comment tells.

release_tty -> tty_driver_remove_tty -> gsmtty_remove -> dlci_put -> tty_port_destructor (WARN_ON(port->itty) and return directly)
                         |
                tty->port->itty = NULL;
                         |
                tty_kref_put ---> release_one_tty -> gsmtty_cleanup (added by our patch)

So our patch fix the memory leak by doing the cleanup work after tty core did.

Signed-off-by: Pan Xinhui <xinhuix.pan@intel.com>
Fixes: dfabf7ffa30585
Cc: stable <stable@vger.kernel.org> # 3.14+
Acked-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
drivers/tty/n_gsm.c