linux-ppp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: linux-ppp@vger.kernel.org
Subject: 'devfd' fd leak in pppd
Date: Thu, 08 Dec 2005 14:52:34 +0000	[thread overview]
Message-ID: <439848B2.1050408@tls.msk.ru> (raw)

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

All recent versions of pppd have a filedescriptor leak -
pppd leaks a filedescriptor to the (serial/pty/whatever)
underlying device on each "redial".

The global `devfd' variable that holds this filedescriptor
is initialized to -1 at the start of the main loop, before
each redial.

The filedescriptor is opened in auth.c:link_required(),
calling the_channel->connect() routine.

Later, again in auth.c, in link_terminated() routine,
there's the following code:

    /*
     * Run disconnector script, if requested.
     * XXX we may not be able to do this if the line has hung up!
     */
    if (devfd >= 0 && the_channel->disconnect) {
        the_channel->disconnect();
        devfd = -1;
    }

For a tty device, there's a tty.c:disconnect_tty() used as
the_channel->disconnect; but it does not *close* any files.
For that, there's the_channel->close field.  Which is only
used in safe_fork() routine when running a child process...

Again, connect_tty() is used (from the_channel->connect())
to start new connection cycle, and that routine starts with

        pty_master = -1;
        pty_slave = -1;
        real_ttyfd = -1;

which, together with devfd = -1 assignment at the beginning
of the main loop effectively leaks the filedescriptor...

Should pppd call the_channel->close() routine in
auth.c:link_terminated(), at the same place where it calls
the_channel->disconnect() ?

Or should the_channel->disconnect() (disconnect_tty() etc)
call corresponding close() routine automagically?  (It seems
the former is better; but there are so many different small
functions out there...)

The attached patch goes the first route above, and it fixes
the problem for me.

Thanks.

/mjt

[-- Attachment #2: ppp-2.4.3-devfdleak.patch --]
[-- Type: text/x-patch, Size: 535 bytes --]

--- auth.c.orig	2004-11-12 13:30:51.000000000 +0300
+++ auth.c	2005-12-08 17:50:44.000000000 +0300
@@ -638,8 +638,13 @@ link_terminated(unit)
      * Run disconnector script, if requested.
      * XXX we may not be able to do this if the line has hung up!
      */
-    if (devfd >= 0 && the_channel->disconnect) {
-	the_channel->disconnect();
+    if (devfd >= 0) {
+	if (the_channel->disconnect)
+	    the_channel->disconnect();
+	if (the_channel->close)
+	    the_channel->close();
+	else
+	    close(devfd);
 	devfd = -1;
     }
 

                 reply	other threads:[~2005-12-08 14:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=439848B2.1050408@tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=linux-ppp@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).