USB: serial: ftdi_sio: simplify TIOCGSERIAL permission check
authorJohan Hovold <johan@kernel.org>
Wed, 7 Apr 2021 10:39:24 +0000 (12:39 +0200)
committerJohan Hovold <johan@kernel.org>
Thu, 8 Apr 2021 07:46:03 +0000 (09:46 +0200)
Changing the deprecated custom_divisor field is an unprivileged
operation so after verifying that flag field does not contain any
privileged changes both updates can be carried out by any user.

Combine the two branches and drop the erroneous comment.

Note that private flags field is only used for ASYNC flags so there's no
need to try to retain any other bits when updating the flags.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
drivers/usb/serial/ftdi_sio.c

index 3fd7875200b90186f288f1649f01d1405f1d5368..9228e56a91c0719fcde52b78a211d5009a1e45b9 100644 (file)
@@ -1496,27 +1496,16 @@ static int set_serial_info(struct tty_struct *tty,
        mutex_lock(&priv->cfg_lock);
        old_priv = *priv;
 
-       /* Do error checking and permission checking */
-
        if (!capable(CAP_SYS_ADMIN)) {
                if ((ss->flags ^ priv->flags) & ~ASYNC_USR_MASK) {
                        mutex_unlock(&priv->cfg_lock);
                        return -EPERM;
                }
-               priv->flags = ((priv->flags & ~ASYNC_USR_MASK) |
-                              (ss->flags & ASYNC_USR_MASK));
-               priv->custom_divisor = ss->custom_divisor;
-               goto check_and_exit;
        }
 
-
-       /* Make the changes - these are privileged changes! */
-
-       priv->flags = ((priv->flags & ~ASYNC_FLAGS) |
-                                       (ss->flags & ASYNC_FLAGS));
+       priv->flags = ss->flags & ASYNC_FLAGS;
        priv->custom_divisor = ss->custom_divisor;
 
-check_and_exit:
        write_latency_timer(port);
 
        if ((priv->flags ^ old_priv.flags) & ASYNC_SPD_MASK ||