Skip to content

Commit

Permalink
saner tty_mode_ioctl() prototype
Browse files Browse the repository at this point in the history
Pass arg as void __user * and don't bother with file at all.
Callers adjusted.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Sep 2, 2022
1 parent cdc4463 commit 6890ade
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion drivers/net/can/can327.c
Expand Up @@ -1101,7 +1101,7 @@ static int can327_ldisc_ioctl(struct tty_struct *tty, unsigned int cmd,
return -EINVAL;

default:
return tty_mode_ioctl(tty, cmd, arg);
return tty_mode_ioctl(tty, cmd, (void __user *)arg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/can/slcan/slcan-core.c
Expand Up @@ -898,7 +898,7 @@ static int slcan_ioctl(struct tty_struct *tty, unsigned int cmd,
return -EINVAL;

default:
return tty_mode_ioctl(tty, cmd, arg);
return tty_mode_ioctl(tty, cmd, (void __user *)arg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/hamradio/6pack.c
Expand Up @@ -735,7 +735,7 @@ static int sixpack_ioctl(struct tty_struct *tty, unsigned int cmd,
break;
}
default:
err = tty_mode_ioctl(tty, cmd, arg);
err = tty_mode_ioctl(tty, cmd, (void __user *)arg);
}

sp_put(sp);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ppp/ppp_async.c
Expand Up @@ -321,7 +321,7 @@ ppp_asynctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)

default:
/* Try the various mode ioctls */
err = tty_mode_ioctl(tty, cmd, arg);
err = tty_mode_ioctl(tty, cmd, (void __user *)arg);
}

ap_put(ap);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ppp/ppp_synctty.c
Expand Up @@ -313,7 +313,7 @@ ppp_synctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
break;

default:
err = tty_mode_ioctl(tty, cmd, arg);
err = tty_mode_ioctl(tty, cmd, (void __user *)arg);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/slip/slip.c
Expand Up @@ -1173,7 +1173,7 @@ static int slip_ioctl(struct tty_struct *tty, unsigned int cmd,
/* VSV changes end */
#endif
default:
return tty_mode_ioctl(tty, cmd, arg);
return tty_mode_ioctl(tty, cmd, (void __user *)arg);
}
}

Expand Down
53 changes: 25 additions & 28 deletions drivers/tty/tty_ioctl.c
Expand Up @@ -760,10 +760,9 @@ static int tty_change_softcar(struct tty_struct *tty, int arg)
* consistent mode setting.
*/

int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, void __user *arg)
{
struct tty_struct *real_tty;
void __user *p = (void __user *)arg;
int ret = 0;
struct ktermios kterm;

Expand All @@ -776,73 +775,72 @@ int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
switch (cmd) {
#ifdef TIOCGETP
case TIOCGETP:
return get_sgttyb(real_tty, (struct sgttyb __user *) arg);
return get_sgttyb(real_tty, arg);
case TIOCSETP:
case TIOCSETN:
return set_sgttyb(real_tty, (struct sgttyb __user *) arg);
return set_sgttyb(real_tty, arg);
#endif
#ifdef TIOCGETC
case TIOCGETC:
return get_tchars(real_tty, p);
return get_tchars(real_tty, arg);
case TIOCSETC:
return set_tchars(real_tty, p);
return set_tchars(real_tty, arg);
#endif
#ifdef TIOCGLTC
case TIOCGLTC:
return get_ltchars(real_tty, p);
return get_ltchars(real_tty, arg);
case TIOCSLTC:
return set_ltchars(real_tty, p);
return set_ltchars(real_tty, arg);
#endif
case TCSETSF:
return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_OLD);
return set_termios(real_tty, arg, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_OLD);
case TCSETSW:
return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_OLD);
return set_termios(real_tty, arg, TERMIOS_WAIT | TERMIOS_OLD);
case TCSETS:
return set_termios(real_tty, p, TERMIOS_OLD);
return set_termios(real_tty, arg, TERMIOS_OLD);
#ifndef TCGETS2
case TCGETS:
copy_termios(real_tty, &kterm);
if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm))
if (kernel_termios_to_user_termios(arg, &kterm))
ret = -EFAULT;
return ret;
#else
case TCGETS:
copy_termios(real_tty, &kterm);
if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm))
if (kernel_termios_to_user_termios_1(arg, &kterm))
ret = -EFAULT;
return ret;
case TCGETS2:
copy_termios(real_tty, &kterm);
if (kernel_termios_to_user_termios((struct termios2 __user *)arg, &kterm))
if (kernel_termios_to_user_termios(arg, &kterm))
ret = -EFAULT;
return ret;
case TCSETSF2:
return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT);
return set_termios(real_tty, arg, TERMIOS_FLUSH | TERMIOS_WAIT);
case TCSETSW2:
return set_termios(real_tty, p, TERMIOS_WAIT);
return set_termios(real_tty, arg, TERMIOS_WAIT);
case TCSETS2:
return set_termios(real_tty, p, 0);
return set_termios(real_tty, arg, 0);
#endif
case TCGETA:
return get_termio(real_tty, p);
return get_termio(real_tty, arg);
case TCSETAF:
return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_TERMIO);
return set_termios(real_tty, arg, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_TERMIO);
case TCSETAW:
return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_TERMIO);
return set_termios(real_tty, arg, TERMIOS_WAIT | TERMIOS_TERMIO);
case TCSETA:
return set_termios(real_tty, p, TERMIOS_TERMIO);
return set_termios(real_tty, arg, TERMIOS_TERMIO);
#ifndef TCGETS2
case TIOCGLCKTRMIOS:
copy_termios_locked(real_tty, &kterm);
if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm))
if (kernel_termios_to_user_termios(arg, &kterm))
ret = -EFAULT;
return ret;
case TIOCSLCKTRMIOS:
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
copy_termios_locked(real_tty, &kterm);
if (user_termios_to_kernel_termios(&kterm,
(struct termios __user *) arg))
if (user_termios_to_kernel_termios(&kterm, arg))
return -EFAULT;
down_write(&real_tty->termios_rwsem);
real_tty->termios_locked = kterm;
Expand All @@ -851,15 +849,14 @@ int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
#else
case TIOCGLCKTRMIOS:
copy_termios_locked(real_tty, &kterm);
if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm))
if (kernel_termios_to_user_termios_1(arg, &kterm))
ret = -EFAULT;
return ret;
case TIOCSLCKTRMIOS:
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
copy_termios_locked(real_tty, &kterm);
if (user_termios_to_kernel_termios_1(&kterm,
(struct termios __user *) arg))
if (user_termios_to_kernel_termios_1(&kterm, arg))
return -EFAULT;
down_write(&real_tty->termios_rwsem);
real_tty->termios_locked = kterm;
Expand Down Expand Up @@ -977,7 +974,7 @@ int n_tty_ioctl_helper(struct tty_struct *tty, unsigned int cmd,
return __tty_perform_flush(tty, arg);
default:
/* Try the mode commands */
return tty_mode_ioctl(tty, cmd, arg);
return tty_mode_ioctl(tty, cmd, (void __user *)arg);
}
}
EXPORT_SYMBOL(n_tty_ioctl_helper);
2 changes: 1 addition & 1 deletion include/linux/tty.h
Expand Up @@ -464,7 +464,7 @@ int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);

void tty_wakeup(struct tty_struct *tty);

int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, void __user *arg);
int tty_perform_flush(struct tty_struct *tty, unsigned long arg);
struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
void tty_release_struct(struct tty_struct *tty, int idx);
Expand Down

0 comments on commit 6890ade

Please sign in to comment.