Skip to content

Commit

Permalink
pty: Fix lock inversion
Browse files Browse the repository at this point in the history
The ptmx_open path takes the tty and devpts locks in the wrong order
because tty_init_dev locks and returns a locked tty.  As far as I can
tell this is actually safe anyway because the tty being returned is new
so nobody can get a reference to lock it at this point.

However we don't even need the devpts lock at this point, it's only held
as a byproduct of the way the locks were pushe down.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Alan Cox authored and Linus Torvalds committed May 29, 2012
1 parent a01ee16 commit d3ca8b6
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions drivers/tty/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ static int ptmx_open(struct inode *inode, struct file *filp)
mutex_unlock(&devpts_mutex);

mutex_lock(&tty_mutex);
mutex_lock(&devpts_mutex);
tty = tty_init_dev(ptm_driver, index);

if (IS_ERR(tty)) {
Expand All @@ -643,7 +642,6 @@ static int ptmx_open(struct inode *inode, struct file *filp)

/* The tty returned here is locked so we can safely
drop the mutex */
mutex_unlock(&devpts_mutex);
mutex_unlock(&tty_mutex);

set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
Expand Down

0 comments on commit d3ca8b6

Please sign in to comment.