public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthias Urlichs <matthias@urlichs.de>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] ldisc switching on a HUPped pty hangs the caller
Date: Fri, 15 Jan 2010 06:07:52 +0100	[thread overview]
Message-ID: <1263532072.22171.24.camel@kiste> (raw)

Calling vhangup() and then switching line disciplines results in
incomplete clean-up and a wedged process if it then calls ioctl()
on the pty.

Signed-Off-By: Matthias Urlichs <matthias@urlichs.de>

---
I recently upgraded my gateway machine to 2.6.31. This caused
ppp-over-ssh to stop working. Indeed, the PPP process got wedged into
noninterruptible sleep, which this patch fixes.

(The comment, by the way, seems to be wrong. There was no race.) 

The underlying problem, however, turns out to be the vhangup() syscall
which the SSH server emits before exec'ing pppd. This causes the tty's
HUPPED bit to get set, which in turn causes the above error.

Browbeating sshd into not issuing vhangup() (why does it do that,
anyway? Presumably, using PTMX we can be sure that nobody is hogging the
pty in the first place, right?) means that I now have a working ssh
tunnel.

… until somebody forces me to switch to a 'real' VPN. :-P

---

diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index aafdbae..bb92f5e 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -621,9 +621,8 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
 		/* We were raced by the hangup method. It will have stomped
 		   the ldisc data and closed the ldisc down */
 		clear_bit(TTY_LDISC_CHANGING, &tty->flags);
-		mutex_unlock(&tty->ldisc_mutex);
-		tty_ldisc_put(new_ldisc);
-		return -EIO;
+		retval = -EIO;
+		goto out;
 	}
 
 	/* Shutdown the current discipline. */
@@ -652,7 +651,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
 	/*
 	 *	Allow ldisc referencing to occur again
 	 */
-
+out:
 	tty_ldisc_enable(tty);
 	if (o_tty)
 		tty_ldisc_enable(o_tty);




             reply	other threads:[~2010-01-15  5:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-15  5:07 Matthias Urlichs [this message]
2010-01-15 10:48 ` [PATCH] ldisc switching on a HUPped pty hangs the caller Alan Cox
2010-01-15 12:04   ` Matthias Urlichs
2010-01-15 11:16 ` Alan Cox

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=1263532072.22171.24.camel@kiste \
    --to=matthias@urlichs.de \
    --cc=linux-kernel@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