]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tty: Permit some TIOCL_SETSEL modes without CAP_SYS_ADMIN
authorGünther Noack <gnoack@google.com>
Fri, 10 Jan 2025 14:21:22 +0000 (14:21 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 13 Jan 2025 05:46:50 +0000 (06:46 +0100)
With this, processes without CAP_SYS_ADMIN are able to use TIOCLINUX with
subcode TIOCL_SETSEL, in the selection modes TIOCL_SETPOINTER,
TIOCL_SELCLEAR and TIOCL_SELMOUSEREPORT.

TIOCL_SETSEL was previously changed to require CAP_SYS_ADMIN, as this IOCTL
let callers change the selection buffer and could be used to simulate
keypresses.  These three TIOCL_SETSEL selection modes, however, are safe to
use, as they do not modify the selection buffer.

This fixes a mouse support regression that affected Emacs (invisible mouse
cursor).

Cc: stable <stable@kernel.org>
Link: https://lore.kernel.org/r/ee3ec63269b43b34e1c90dd8c9743bf8@finder.org
Fixes: 8d1b43f6a6df ("tty: Restrict access to TIOCLINUX' copy-and-paste subcommands")
Signed-off-by: Günther Noack <gnoack@google.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://lore.kernel.org/r/20250110142122.1013222-1-gnoack@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/vt/selection.c
drivers/tty/vt/vt.c

index 564341f1a74f3f6b1b553bf8705fe34b62ed3b5a..0bd6544e30a6b3e38894bf1d36f88f44f1cc6ea6 100644 (file)
@@ -192,6 +192,20 @@ int set_selection_user(const struct tiocl_selection __user *sel,
        if (copy_from_user(&v, sel, sizeof(*sel)))
                return -EFAULT;
 
+       /*
+        * TIOCL_SELCLEAR, TIOCL_SELPOINTER and TIOCL_SELMOUSEREPORT are OK to
+        * use without CAP_SYS_ADMIN as they do not modify the selection.
+        */
+       switch (v.sel_mode) {
+       case TIOCL_SELCLEAR:
+       case TIOCL_SELPOINTER:
+       case TIOCL_SELMOUSEREPORT:
+               break;
+       default:
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+       }
+
        return set_selection_kernel(&v, tty);
 }
 
index 96842ce817af47905ba795b31ef45a27dec8eb66..be5564ed8c018a411acee0bcab1dceb9100d395a 100644 (file)
@@ -3345,8 +3345,6 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
 
        switch (type) {
        case TIOCL_SETSEL:
-               if (!capable(CAP_SYS_ADMIN))
-                       return -EPERM;
                return set_selection_user(param, tty);
        case TIOCL_PASTESEL:
                if (!capable(CAP_SYS_ADMIN))