tty: Fix termios tty window resize race with pty/tty pair

Kanru Chen posted a patch versus the old code which deals with the case
where you resize the pty side of a pty/tty pair. In that situation the
termios data is updated for both pty and tty but the locks are not held
for the right side.

This implements the fix differently against the updated tty code. Patch
by self but the hard bit (noticing and fixing the bug) is thanks to Kanru
Chen.

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Alan Cox and committed by Linus Torvalds a152db71 f753f327

+4 -3
+4 -3
drivers/char/tty_io.c
··· 2498 2498 /** 2499 2499 * tty_do_resize - resize event 2500 2500 * @tty: tty being resized 2501 - * @real_tty: real tty (if using a pty/tty pair) 2501 + * @real_tty: real tty (not the same as tty if using a pty/tty pair) 2502 2502 * @rows: rows (character) 2503 2503 * @cols: cols (character) 2504 2504 * ··· 2512 2512 struct pid *pgrp, *rpgrp; 2513 2513 unsigned long flags; 2514 2514 2515 - mutex_lock(&tty->termios_mutex); 2515 + /* For a PTY we need to lock the tty side */ 2516 + mutex_lock(&real_tty->termios_mutex); 2516 2517 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) 2517 2518 goto done; 2518 2519 /* Get the PID values and reference them so we can ··· 2534 2533 tty->winsize = *ws; 2535 2534 real_tty->winsize = *ws; 2536 2535 done: 2537 - mutex_unlock(&tty->termios_mutex); 2536 + mutex_unlock(&real_tty->termios_mutex); 2538 2537 return 0; 2539 2538 } 2540 2539