aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/tty_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/tty/tty_io.c')
-rw-r--r--drivers/tty/tty_io.c45
1 files changed, 16 insertions, 29 deletions
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 8a5a8b06461..2ea176b2280 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1166,10 +1166,8 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
1166 struct file *p = NULL; 1166 struct file *p = NULL;
1167 1167
1168 spin_lock(&redirect_lock); 1168 spin_lock(&redirect_lock);
1169 if (redirect) { 1169 if (redirect)
1170 get_file(redirect); 1170 p = get_file(redirect);
1171 p = redirect;
1172 }
1173 spin_unlock(&redirect_lock); 1171 spin_unlock(&redirect_lock);
1174 1172
1175 if (p) { 1173 if (p) {
@@ -2264,8 +2262,7 @@ static int tioccons(struct file *file)
2264 spin_unlock(&redirect_lock); 2262 spin_unlock(&redirect_lock);
2265 return -EBUSY; 2263 return -EBUSY;
2266 } 2264 }
2267 get_file(file); 2265 redirect = get_file(file);
2268 redirect = file;
2269 spin_unlock(&redirect_lock); 2266 spin_unlock(&redirect_lock);
2270 return 0; 2267 return 0;
2271} 2268}
@@ -2809,6 +2806,13 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
2809} 2806}
2810#endif 2807#endif
2811 2808
2809static int this_tty(const void *t, struct file *file, unsigned fd)
2810{
2811 if (likely(file->f_op->read != tty_read))
2812 return 0;
2813 return file_tty(file) != t ? 0 : fd + 1;
2814}
2815
2812/* 2816/*
2813 * This implements the "Secure Attention Key" --- the idea is to 2817 * This implements the "Secure Attention Key" --- the idea is to
2814 * prevent trojan horses by killing all processes associated with this 2818 * prevent trojan horses by killing all processes associated with this
@@ -2836,8 +2840,6 @@ void __do_SAK(struct tty_struct *tty)
2836 struct task_struct *g, *p; 2840 struct task_struct *g, *p;
2837 struct pid *session; 2841 struct pid *session;
2838 int i; 2842 int i;
2839 struct file *filp;
2840 struct fdtable *fdt;
2841 2843
2842 if (!tty) 2844 if (!tty)
2843 return; 2845 return;
@@ -2867,27 +2869,12 @@ void __do_SAK(struct tty_struct *tty)
2867 continue; 2869 continue;
2868 } 2870 }
2869 task_lock(p); 2871 task_lock(p);
2870 if (p->files) { 2872 i = iterate_fd(p->files, 0, this_tty, tty);
2871 /* 2873 if (i != 0) {
2872 * We don't take a ref to the file, so we must 2874 printk(KERN_NOTICE "SAK: killed process %d"
2873 * hold ->file_lock instead. 2875 " (%s): fd#%d opened to the tty\n",
2874 */ 2876 task_pid_nr(p), p->comm, i - 1);
2875 spin_lock(&p->files->file_lock); 2877 force_sig(SIGKILL, p);
2876 fdt = files_fdtable(p->files);
2877 for (i = 0; i < fdt->max_fds; i++) {
2878 filp = fcheck_files(p->files, i);
2879 if (!filp)
2880 continue;
2881 if (filp->f_op->read == tty_read &&
2882 file_tty(filp) == tty) {
2883 printk(KERN_NOTICE "SAK: killed process %d"
2884 " (%s): fd#%d opened to the tty\n",
2885 task_pid_nr(p), p->comm, i);
2886 force_sig(SIGKILL, p);
2887 break;
2888 }
2889 }
2890 spin_unlock(&p->files->file_lock);
2891 } 2878 }
2892 task_unlock(p); 2879 task_unlock(p);
2893 } while_each_thread(g, p); 2880 } while_each_thread(g, p);