[PATCH] selinux: fix tty locking
authorStephen Smalley <sds@tycho.nsa.gov>
Tue, 26 Sep 2006 06:32:03 +0000 (23:32 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Tue, 26 Sep 2006 15:48:53 +0000 (08:48 -0700)
Take tty_mutex when accessing ->signal->tty in selinux code.  Noted by Alan
Cox.  Longer term, we are looking at refactoring the code to provide better
encapsulation of the tty layer, but this is a simple fix that addresses the
immediate bug.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Acked-by: Alan Cox <alan@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
security/selinux/hooks.c

index 55cec4d6f11749ed0f197d535db9e42cc9bb100a..e4d81a42fca4205f9faa8962caca88af01d9245d 100644 (file)
@@ -1689,10 +1689,12 @@ static inline void flush_unauthorized_files(struct files_struct * files)
 {
        struct avc_audit_data ad;
        struct file *file, *devnull = NULL;
-       struct tty_struct *tty = current->signal->tty;
+       struct tty_struct *tty;
        struct fdtable *fdt;
        long j = -1;
 
+       mutex_lock(&tty_mutex);
+       tty = current->signal->tty;
        if (tty) {
                file_list_lock();
                file = list_entry(tty->tty_files.next, typeof(*file), f_u.fu_list);
@@ -1712,6 +1714,7 @@ static inline void flush_unauthorized_files(struct files_struct * files)
                }
                file_list_unlock();
        }
+       mutex_unlock(&tty_mutex);
 
        /* Revalidate access to inherited open files. */