aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-05-08 03:26:56 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:04 -0400
commit98a27ba485c7508ef9d9527fe06e4686f3a163dc (patch)
tree73d5dca7f1b5120ecf1bbcc664094044bc35dc56
parent2a65f1d9fe78475720bd8f0e0fbbf1973b1b5ac2 (diff)
tty: introduce no_tty and use it in selinux
While researching the tty layer pid leaks I found a weird case in selinux when we drop a controlling tty because of inadequate permissions we don't do the normal hangup processing. Which is a problem if it happens the session leader has exec'd something that can no longer access the tty. We already have code in the kernel to handle this case in the form of the TIOCNOTTY ioctl. So this patch factors out a helper function that is the essence of that ioctl and calls it from the selinux code. This removes the inconsistency in handling dropping of a controlling tty and who knows it might even make some part of user space happy because it received a SIGHUP it was expecting. In addition since this removes the last user of proc_set_tty outside of tty_io.c proc_set_tty is made static and removed from tty.h Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Acked-by: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: James Morris <jmorris@namei.org> Cc: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/char/tty_io.c19
-rw-r--r--include/linux/tty.h2
-rw-r--r--security/selinux/hooks.c7
3 files changed, 19 insertions, 9 deletions
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 39db186d5c5b..5d405a1bfbe3 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -154,6 +154,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
154static int tty_fasync(int fd, struct file * filp, int on); 154static int tty_fasync(int fd, struct file * filp, int on);
155static void release_tty(struct tty_struct *tty, int idx); 155static void release_tty(struct tty_struct *tty, int idx);
156static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); 156static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
157static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
157 158
158/** 159/**
159 * alloc_tty_struct - allocate a tty object 160 * alloc_tty_struct - allocate a tty object
@@ -1558,6 +1559,18 @@ void disassociate_ctty(int on_exit)
1558 unlock_kernel(); 1559 unlock_kernel();
1559} 1560}
1560 1561
1562/**
1563 *
1564 * no_tty - Ensure the current process does not have a controlling tty
1565 */
1566void no_tty(void)
1567{
1568 struct task_struct *tsk = current;
1569 if (tsk->signal->leader)
1570 disassociate_ctty(0);
1571 proc_clear_tty(tsk);
1572}
1573
1561 1574
1562/** 1575/**
1563 * stop_tty - propogate flow control 1576 * stop_tty - propogate flow control
@@ -3280,9 +3293,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
3280 case TIOCNOTTY: 3293 case TIOCNOTTY:
3281 if (current->signal->tty != tty) 3294 if (current->signal->tty != tty)
3282 return -ENOTTY; 3295 return -ENOTTY;
3283 if (current->signal->leader) 3296 no_tty();
3284 disassociate_ctty(0);
3285 proc_clear_tty(current);
3286 return 0; 3297 return 0;
3287 case TIOCSCTTY: 3298 case TIOCSCTTY:
3288 return tiocsctty(tty, arg); 3299 return tiocsctty(tty, arg);
@@ -3844,7 +3855,7 @@ static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3844 tsk->signal->tty_old_pgrp = NULL; 3855 tsk->signal->tty_old_pgrp = NULL;
3845} 3856}
3846 3857
3847void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 3858static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3848{ 3859{
3849 spin_lock_irq(&tsk->sighand->siglock); 3860 spin_lock_irq(&tsk->sighand->siglock);
3850 __proc_set_tty(tsk, tty); 3861 __proc_set_tty(tsk, tty);
diff --git a/include/linux/tty.h b/include/linux/tty.h
index dee72b9a20fb..bb4576085203 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -313,6 +313,7 @@ extern int tty_hung_up_p(struct file * filp);
313extern void do_SAK(struct tty_struct *tty); 313extern void do_SAK(struct tty_struct *tty);
314extern void __do_SAK(struct tty_struct *tty); 314extern void __do_SAK(struct tty_struct *tty);
315extern void disassociate_ctty(int priv); 315extern void disassociate_ctty(int priv);
316extern void no_tty(void);
316extern void tty_flip_buffer_push(struct tty_struct *tty); 317extern void tty_flip_buffer_push(struct tty_struct *tty);
317extern speed_t tty_get_baud_rate(struct tty_struct *tty); 318extern speed_t tty_get_baud_rate(struct tty_struct *tty);
318extern speed_t tty_termios_baud_rate(struct ktermios *termios); 319extern speed_t tty_termios_baud_rate(struct ktermios *termios);
@@ -333,7 +334,6 @@ extern int tty_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
333 334
334extern dev_t tty_devnum(struct tty_struct *tty); 335extern dev_t tty_devnum(struct tty_struct *tty);
335extern void proc_clear_tty(struct task_struct *p); 336extern void proc_clear_tty(struct task_struct *p);
336extern void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
337extern struct tty_struct *get_current_tty(void); 337extern struct tty_struct *get_current_tty(void);
338 338
339extern struct mutex tty_mutex; 339extern struct mutex tty_mutex;
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 885a9a958b8d..fa9dbb6b110d 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1758,12 +1758,11 @@ static inline void flush_unauthorized_files(struct files_struct * files)
1758 } 1758 }
1759 } 1759 }
1760 file_list_unlock(); 1760 file_list_unlock();
1761
1762 /* Reset controlling tty. */
1763 if (drop_tty)
1764 proc_set_tty(current, NULL);
1765 } 1761 }
1766 mutex_unlock(&tty_mutex); 1762 mutex_unlock(&tty_mutex);
1763 /* Reset controlling tty. */
1764 if (drop_tty)
1765 no_tty();
1767 1766
1768 /* Revalidate access to inherited open files. */ 1767 /* Revalidate access to inherited open files. */
1769 1768