Pārlūkot izejas kodu

tty: Hold termios_rwsem for tcflow(TCIxxx)

While transmitting a START/STOP char for tcflow(TCION/TCIOFF), prevent
a termios change. Otherwise, a garbage in-band flow control char
may be sent, if the termios change overlaps the transmission setup.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Peter Hurley 11 gadi atpakaļ
vecāks
revīzija
c274f6ef1c
1 mainītis faili ar 7 papildinājumiem un 3 dzēšanām
  1. 7 3
      drivers/tty/tty_ioctl.c

+ 7 - 3
drivers/tty/tty_ioctl.c

@@ -1164,17 +1164,21 @@ int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
 			spin_unlock_irq(&tty->flow_lock);
 			spin_unlock_irq(&tty->flow_lock);
 			break;
 			break;
 		case TCIOFF:
 		case TCIOFF:
+			down_read(&tty->termios_rwsem);
 			if (STOP_CHAR(tty) != __DISABLED_CHAR)
 			if (STOP_CHAR(tty) != __DISABLED_CHAR)
-				return tty_send_xchar(tty, STOP_CHAR(tty));
+				retval = tty_send_xchar(tty, STOP_CHAR(tty));
+			up_read(&tty->termios_rwsem);
 			break;
 			break;
 		case TCION:
 		case TCION:
+			down_read(&tty->termios_rwsem);
 			if (START_CHAR(tty) != __DISABLED_CHAR)
 			if (START_CHAR(tty) != __DISABLED_CHAR)
-				return tty_send_xchar(tty, START_CHAR(tty));
+				retval = tty_send_xchar(tty, START_CHAR(tty));
+			up_read(&tty->termios_rwsem);
 			break;
 			break;
 		default:
 		default:
 			return -EINVAL;
 			return -EINVAL;
 		}
 		}
-		return 0;
+		return retval;
 	case TCFLSH:
 	case TCFLSH:
 		retval = tty_check_change(tty);
 		retval = tty_check_change(tty);
 		if (retval)
 		if (retval)