public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix refcount leak in tty_port.c
@ 2013-07-09  8:35 Gianluca Anzolin
  2013-07-12 10:30 ` Gustavo Padovan
  0 siblings, 1 reply; 7+ messages in thread
From: Gianluca Anzolin @ 2013-07-09  8:35 UTC (permalink / raw)
  To: jslaby; +Cc: gregkh, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

Hello,

In linux 3.10 in the file drivers/tty/tty_port.c the function
tty_port_tty_hangup may leak a tty reference:

        struct tty_struct *tty = tty_port_tty_get(port);

        if (tty && (!check_clocal || !C_CLOCAL(tty))) {
                tty_hangup(tty);
                tty_kref_put(tty);
        }

If tty != NULL and the second condition is false we never call tty_kref_put and
the reference is leaked.

Fix by nesting two if statements.

Signed-off-by: Gianluca Anzolin <gianluca@sottospazio.it>

[-- Attachment #2: tty_port.patch --]
[-- Type: text/x-diff, Size: 465 bytes --]

diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 121aeb9..2198f7d 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -256,8 +256,9 @@ void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
 {
 	struct tty_struct *tty = tty_port_tty_get(port);
 
-	if (tty && (!check_clocal || !C_CLOCAL(tty))) {
-		tty_hangup(tty);
+	if (tty) {
+		if (!check_clocal || !C_CLOCAL(tty))
+			tty_hangup(tty);
 		tty_kref_put(tty);
 	}
 }

^ permalink raw reply related	[flat|nested] 7+ messages in thread
[parent not found: <20130709083535.GA30227>]

end of thread, other threads:[~2013-07-24 22:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-09  8:35 [PATCH] Fix refcount leak in tty_port.c Gianluca Anzolin
2013-07-12 10:30 ` Gustavo Padovan
2013-07-12 14:04   ` Peter Hurley
2013-07-24 14:11     ` Peter Hurley
2013-07-24 22:15       ` Greg KH
     [not found] <20130709083535.GA30227>
2013-07-12  9:47 ` Gianluca Anzolin
2013-07-12 15:12   ` Greg KH

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