Commit 8d075b19 authored by Alan Cox's avatar Alan Cox Committed by Greg Kroah-Hartman

tty: add a helper for setting termios data from kernel side

This basically encapsulates the small bit of locking knowledge needed. While
we are at it make sure we blow up on any more abusers and unsafe misuses of
ioctl for this kind of stuff.

We change the function to return an argument as at some point it needs to
honour the POSIX 'I asked for changes but got none of them' error reporting
corner case.
Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 94c2273d
...@@ -486,7 +486,7 @@ int tty_termios_hw_change(struct ktermios *a, struct ktermios *b) ...@@ -486,7 +486,7 @@ int tty_termios_hw_change(struct ktermios *a, struct ktermios *b)
EXPORT_SYMBOL(tty_termios_hw_change); EXPORT_SYMBOL(tty_termios_hw_change);
/** /**
* change_termios - update termios values * tty_set_termios - update termios values
* @tty: tty to update * @tty: tty to update
* @new_termios: desired new value * @new_termios: desired new value
* *
...@@ -497,7 +497,7 @@ EXPORT_SYMBOL(tty_termios_hw_change); ...@@ -497,7 +497,7 @@ EXPORT_SYMBOL(tty_termios_hw_change);
* Locking: termios_mutex * Locking: termios_mutex
*/ */
static void change_termios(struct tty_struct *tty, struct ktermios *new_termios) int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios)
{ {
struct ktermios old_termios; struct ktermios old_termios;
struct tty_ldisc *ld; struct tty_ldisc *ld;
...@@ -553,7 +553,9 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios) ...@@ -553,7 +553,9 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
tty_ldisc_deref(ld); tty_ldisc_deref(ld);
} }
mutex_unlock(&tty->termios_mutex); mutex_unlock(&tty->termios_mutex);
return 0;
} }
EXPORT_SYMBOL_GPL(tty_set_termios);
/** /**
* set_termios - set termios values for a tty * set_termios - set termios values for a tty
...@@ -562,7 +564,7 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios) ...@@ -562,7 +564,7 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
* @opt: option information * @opt: option information
* *
* Helper function to prepare termios data and run necessary other * Helper function to prepare termios data and run necessary other
* functions before using change_termios to do the actual changes. * functions before using tty_set_termios to do the actual changes.
* *
* Locking: * Locking:
* Called functions take ldisc and termios_mutex locks * Called functions take ldisc and termios_mutex locks
...@@ -620,7 +622,7 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt) ...@@ -620,7 +622,7 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
return -EINTR; return -EINTR;
} }
change_termios(tty, &tmp_termios); tty_set_termios(tty, &tmp_termios);
/* FIXME: Arguably if tmp_termios == tty->termios AND the /* FIXME: Arguably if tmp_termios == tty->termios AND the
actual requested termios was not tmp_termios then we may actual requested termios was not tmp_termios then we may
...@@ -797,7 +799,7 @@ static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) ...@@ -797,7 +799,7 @@ static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb)
termios.c_ospeed); termios.c_ospeed);
#endif #endif
mutex_unlock(&tty->termios_mutex); mutex_unlock(&tty->termios_mutex);
change_termios(tty, &termios); tty_set_termios(tty, &termios);
return 0; return 0;
} }
#endif #endif
...@@ -951,6 +953,8 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file, ...@@ -951,6 +953,8 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
int ret = 0; int ret = 0;
struct ktermios kterm; struct ktermios kterm;
BUG_ON(file == NULL);
if (tty->driver->type == TTY_DRIVER_TYPE_PTY && if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
tty->driver->subtype == PTY_TYPE_MASTER) tty->driver->subtype == PTY_TYPE_MASTER)
real_tty = tty->link; real_tty = tty->link;
......
...@@ -448,6 +448,7 @@ extern void tty_encode_baud_rate(struct tty_struct *tty, ...@@ -448,6 +448,7 @@ extern void tty_encode_baud_rate(struct tty_struct *tty,
speed_t ibaud, speed_t obaud); speed_t ibaud, speed_t obaud);
extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old); extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old);
extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b); extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b);
extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *);
extern void tty_ldisc_deref(struct tty_ldisc *); extern void tty_ldisc_deref(struct tty_ldisc *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment