mirror of
https://github.com/joel16/android_kernel_sony_msm8994_rework.git
synced 2024-12-28 06:54:55 +00:00
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>
This commit is contained in:
parent
2a65f1d9fe
commit
98a27ba485
@ -154,6 +154,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
|
||||
static int tty_fasync(int fd, struct file * filp, int on);
|
||||
static void release_tty(struct tty_struct *tty, int idx);
|
||||
static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
|
||||
static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
|
||||
|
||||
/**
|
||||
* alloc_tty_struct - allocate a tty object
|
||||
@ -1558,6 +1559,18 @@ void disassociate_ctty(int on_exit)
|
||||
unlock_kernel();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* no_tty - Ensure the current process does not have a controlling tty
|
||||
*/
|
||||
void no_tty(void)
|
||||
{
|
||||
struct task_struct *tsk = current;
|
||||
if (tsk->signal->leader)
|
||||
disassociate_ctty(0);
|
||||
proc_clear_tty(tsk);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* stop_tty - propogate flow control
|
||||
@ -3280,9 +3293,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
|
||||
case TIOCNOTTY:
|
||||
if (current->signal->tty != tty)
|
||||
return -ENOTTY;
|
||||
if (current->signal->leader)
|
||||
disassociate_ctty(0);
|
||||
proc_clear_tty(current);
|
||||
no_tty();
|
||||
return 0;
|
||||
case TIOCSCTTY:
|
||||
return tiocsctty(tty, arg);
|
||||
@ -3844,7 +3855,7 @@ static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
|
||||
tsk->signal->tty_old_pgrp = NULL;
|
||||
}
|
||||
|
||||
void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
|
||||
static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
|
||||
{
|
||||
spin_lock_irq(&tsk->sighand->siglock);
|
||||
__proc_set_tty(tsk, tty);
|
||||
|
@ -313,6 +313,7 @@ extern int tty_hung_up_p(struct file * filp);
|
||||
extern void do_SAK(struct tty_struct *tty);
|
||||
extern void __do_SAK(struct tty_struct *tty);
|
||||
extern void disassociate_ctty(int priv);
|
||||
extern void no_tty(void);
|
||||
extern void tty_flip_buffer_push(struct tty_struct *tty);
|
||||
extern speed_t tty_get_baud_rate(struct tty_struct *tty);
|
||||
extern 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,
|
||||
|
||||
extern dev_t tty_devnum(struct tty_struct *tty);
|
||||
extern void proc_clear_tty(struct task_struct *p);
|
||||
extern void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
|
||||
extern struct tty_struct *get_current_tty(void);
|
||||
|
||||
extern struct mutex tty_mutex;
|
||||
|
@ -1758,12 +1758,11 @@ static inline void flush_unauthorized_files(struct files_struct * files)
|
||||
}
|
||||
}
|
||||
file_list_unlock();
|
||||
|
||||
/* Reset controlling tty. */
|
||||
if (drop_tty)
|
||||
proc_set_tty(current, NULL);
|
||||
}
|
||||
mutex_unlock(&tty_mutex);
|
||||
/* Reset controlling tty. */
|
||||
if (drop_tty)
|
||||
no_tty();
|
||||
|
||||
/* Revalidate access to inherited open files. */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user