mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-08 02:49:48 +00:00
tty: Fix tty_send_xchar() lock order inversion
commitee0c1a65cfupstream. The correct lock order is atomic_write_lock => termios_rwsem, as established by tty_write() => n_tty_write(). Fixes:c274f6ef1c("tty: Hold termios_rwsem for tcflow(TCIxxx)") Reported-and-Tested-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
b7861b3137
commit
0163804569
@@ -1279,18 +1279,22 @@ int tty_send_xchar(struct tty_struct *tty, char ch)
|
||||
int was_stopped = tty->stopped;
|
||||
|
||||
if (tty->ops->send_xchar) {
|
||||
down_read(&tty->termios_rwsem);
|
||||
tty->ops->send_xchar(tty, ch);
|
||||
up_read(&tty->termios_rwsem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tty_write_lock(tty, 0) < 0)
|
||||
return -ERESTARTSYS;
|
||||
|
||||
down_read(&tty->termios_rwsem);
|
||||
if (was_stopped)
|
||||
start_tty(tty);
|
||||
tty->ops->write(tty, &ch, 1);
|
||||
if (was_stopped)
|
||||
stop_tty(tty);
|
||||
up_read(&tty->termios_rwsem);
|
||||
tty_write_unlock(tty);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1142,16 +1142,12 @@ int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
|
||||
spin_unlock_irq(&tty->flow_lock);
|
||||
break;
|
||||
case TCIOFF:
|
||||
down_read(&tty->termios_rwsem);
|
||||
if (STOP_CHAR(tty) != __DISABLED_CHAR)
|
||||
retval = tty_send_xchar(tty, STOP_CHAR(tty));
|
||||
up_read(&tty->termios_rwsem);
|
||||
break;
|
||||
case TCION:
|
||||
down_read(&tty->termios_rwsem);
|
||||
if (START_CHAR(tty) != __DISABLED_CHAR)
|
||||
retval = tty_send_xchar(tty, START_CHAR(tty));
|
||||
up_read(&tty->termios_rwsem);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
|
||||
Reference in New Issue
Block a user