Skip to content

Commit 2f83e38

Browse files
gnoackgregkh
authored andcommitted
tty: Permit some TIOCL_SETSEL modes without CAP_SYS_ADMIN
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Fixes: 8d1b43f ("tty: Restrict access to TIOCLINUX' copy-and-paste subcommands") Signed-off-by: Günther Noack <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b06f388 commit 2f83e38

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

drivers/tty/vt/selection.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,20 @@ int set_selection_user(const struct tiocl_selection __user *sel,
192192
if (copy_from_user(&v, sel, sizeof(*sel)))
193193
return -EFAULT;
194194

195+
/*
196+
* TIOCL_SELCLEAR, TIOCL_SELPOINTER and TIOCL_SELMOUSEREPORT are OK to
197+
* use without CAP_SYS_ADMIN as they do not modify the selection.
198+
*/
199+
switch (v.sel_mode) {
200+
case TIOCL_SELCLEAR:
201+
case TIOCL_SELPOINTER:
202+
case TIOCL_SELMOUSEREPORT:
203+
break;
204+
default:
205+
if (!capable(CAP_SYS_ADMIN))
206+
return -EPERM;
207+
}
208+
195209
return set_selection_kernel(&v, tty);
196210
}
197211

drivers/tty/vt/vt.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3345,8 +3345,6 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
33453345

33463346
switch (type) {
33473347
case TIOCL_SETSEL:
3348-
if (!capable(CAP_SYS_ADMIN))
3349-
return -EPERM;
33503348
return set_selection_user(param, tty);
33513349
case TIOCL_PASTESEL:
33523350
if (!capable(CAP_SYS_ADMIN))

0 commit comments

Comments
 (0)