public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Prarit Bhargava <prarit@redhat.com>
To: linux-kernel@vger.kernel.org, akpm@osdl.org
Cc: Prarit Bhargava <prarit@redhat.com>
Subject: [PATCH]: disassociate tty locking fixups
Date: Sat, 14 Oct 2006 07:22:18 -0400	[thread overview]
Message-ID: <20061014112218.30218.93267.sendpatchset@prarit.boston.redhat.com> (raw)

Additional tty_mutex locking in do_tty_hangup and disassociate_ctty.  It is
possible that do_tty_hangup sets current->signal->tty = NULL.  If that
happens then disassociate_ctty can corrupt memory.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>

--- linux-2.6.18.x86_64.orig/drivers/char/tty_io.c	2006-10-12 10:05:52.000000000 -0400
+++ linux-2.6.18.x86_64/drivers/char/tty_io.c	2006-10-13 11:19:30.000000000 -0400
@@ -1357,6 +1357,8 @@ static void do_tty_hangup(void *data)
 	  This should get done automatically when the port closes and
 	  tty_release is called */
 	
+	/* it is possible current->signal->tty is modified */
+	mutex_lock(&tty_mutex);
 	read_lock(&tasklist_lock);
 	if (tty->session > 0) {
 		do_each_task_pid(tty->session, PIDTYPE_SID, p) {
@@ -1364,14 +1366,16 @@ static void do_tty_hangup(void *data)
 				p->signal->tty = NULL;
 			if (!p->signal->leader)
 				continue;
+			mutex_unlock(&tty_mutex);
 			group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p);
 			group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
+			mutex_lock(&tty_mutex);
 			if (tty->pgrp > 0)
 				p->signal->tty_old_pgrp = tty->pgrp;
 		} while_each_task_pid(tty->session, PIDTYPE_SID, p);
 	}
 	read_unlock(&tasklist_lock);
-
+	mutex_unlock(&tty_mutex);
 	tty->flags = 0;
 	tty->session = 0;
 	tty->pgrp = -1;
@@ -1502,7 +1506,7 @@ void disassociate_ctty(int on_exit)
 			kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit);
 		}
 		mutex_unlock(&tty_mutex);
-		unlock_kernel();	
+		unlock_kernel();
 		return;
 	}
 	if (tty_pgrp > 0) {
@@ -1514,8 +1518,12 @@ void disassociate_ctty(int on_exit)
 	/* Must lock changes to tty_old_pgrp */
 	mutex_lock(&tty_mutex);
 	current->signal->tty_old_pgrp = 0;
-	tty->session = 0;
-	tty->pgrp = -1;
+
+	/* It is possible that do_tty_hangup has free'd this tty */
+	if (current->signal->tty) {
+		tty->session = 0;
+		tty->pgrp = -1;
+	}
 
 	/* Now clear signal->tty under the lock */
 	read_lock(&tasklist_lock);

             reply	other threads:[~2006-10-14 11:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-14 11:22 Prarit Bhargava [this message]
2006-10-14 12:20 ` [PATCH]: disassociate tty locking fixups Arjan van de Ven
2006-10-14 12:55 ` Alan Cox
2006-10-14 15:06   ` Prarit Bhargava
2006-10-14 16:29     ` 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=20061014112218.30218.93267.sendpatchset@prarit.boston.redhat.com \
    --to=prarit@redhat.com \
    --cc=akpm@osdl.org \
    --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