tty: the vhangup syscall is racy
authorAlan Cox <alan@redhat.com>
Mon, 13 Oct 2008 09:40:30 +0000 (10:40 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 13 Oct 2008 16:51:41 +0000 (09:51 -0700)
We now have the infrastructure to sort this out but rather than teaching
the syscall tty lock rules we move the hard work into a tty helper

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/char/tty_io.c
fs/open.c
include/linux/tty.h

index 913b50258f903f74367f475cb69f1747492c0bfc..b5f57d0b30ee1bdb5e931825010c59ab0b2627a2 100644 (file)
@@ -729,6 +729,25 @@ void tty_vhangup(struct tty_struct *tty)
 
 EXPORT_SYMBOL(tty_vhangup);
 
+/**
+ *     tty_vhangup_self        -       process vhangup for own ctty
+ *
+ *     Perform a vhangup on the current controlling tty
+ */
+
+void tty_vhangup_self(void)
+{
+       struct tty_struct *tty;
+
+       mutex_lock(&tty_mutex);
+       tty = get_current_tty();
+       if (tty) {
+               tty_vhangup(tty);
+               tty_kref_put(tty);
+       }
+       mutex_unlock(&tty_mutex);
+}
+
 /**
  *     tty_hung_up_p           -       was tty hung up
  *     @filp: file pointer of tty
index 07da9359481c720c045e2a25e154df02ba02e9ff..5596049863bf742eadb115bafe0deef35b209421 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -1141,8 +1141,7 @@ EXPORT_SYMBOL(sys_close);
 asmlinkage long sys_vhangup(void)
 {
        if (capable(CAP_SYS_TTY_CONFIG)) {
-               /* XXX: this needs locking */
-               tty_vhangup(current->signal->tty);
+               tty_vhangup_self();
                return 0;
        }
        return -EPERM;
index c30ed8d3bcbdd1580aa598ea8d6e373167a11317..e00393a3d1c9376ca2ee9f607408fcf1700c7e99 100644 (file)
@@ -361,6 +361,7 @@ extern int is_ignored(int sig);
 extern int tty_signal(int sig, struct tty_struct *tty);
 extern void tty_hangup(struct tty_struct *tty);
 extern void tty_vhangup(struct tty_struct *tty);
+extern void tty_vhangup_self(void);
 extern void tty_unhangup(struct file *filp);
 extern int tty_hung_up_p(struct file *filp);
 extern void do_SAK(struct tty_struct *tty);