Skip to content

Commit 83efeee

Browse files
keesgregkh
authored andcommitted
tty: Allow TIOCSTI to be disabled
TIOCSTI continues its long history of being used in privilege escalation attacks[1]. Prior attempts to provide a mechanism to disable this have devolved into discussions around creating full-blown LSMs to provide arbitrary ioctl filtering, which is hugely over-engineered -- only TIOCSTI is being used this way. 3 years ago OpenBSD entirely removed TIOCSTI[2], Android has had it filtered for longer[3], and the tools that had historically used TIOCSTI either do not need it, are not commonly built with it, or have had its use removed. Provide a simple CONFIG and global sysctl to disable this for the system builders who have wanted this functionality for literally decades now, much like the ldisc_autoload CONFIG and sysctl. [1] https://lore.kernel.org/linux-hardening/Y0m9l52AKmw6Yxi1@hostpad [2] https://undeadly.org/cgi?action=article;sid=20170701132619 [3] https://lore.kernel.org/lkml/CAFJ0LnFGRuEEn1tCLhoki8ZyWrKfktbF+rwwN7WzyC_kBFoQVA@mail.gmail.com/ Cc: Greg Kroah-Hartman <[email protected]> Cc: Jiri Slaby <[email protected]> Cc: Simon Brand <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5fd8c2d commit 83efeee

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

drivers/tty/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ config LEGACY_PTY_COUNT
149149
When not in use, each legacy PTY occupies 12 bytes on 32-bit
150150
architectures and 24 bytes on 64-bit architectures.
151151

152+
config LEGACY_TIOCSTI
153+
bool "Allow legacy TIOCSTI usage"
154+
default y
155+
help
156+
Historically the kernel has allowed TIOCSTI, which will push
157+
characters into a controlling TTY. This continues to be used
158+
as a malicious privilege escalation mechanism, and provides no
159+
meaningful real-world utility any more. Its use is considered
160+
a dangerous legacy operation, and can be disabled on most
161+
systems.
162+
163+
Say 'Y here only if you have confirmed that your system's
164+
userspace depends on this functionality to continue operating
165+
normally.
166+
167+
This functionality can be changed at runtime with the
168+
dev.tty.legacy_tiocsti sysctl. This configuration option sets
169+
the default value of the sysctl.
170+
152171
config LDISC_AUTOLOAD
153172
bool "Automatically load TTY Line Disciplines"
154173
default y

drivers/tty/tty_io.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,11 +2268,15 @@ static int tty_fasync(int fd, struct file *filp, int on)
22682268
* * Called functions take tty_ldiscs_lock
22692269
* * current->signal->tty check is safe without locks
22702270
*/
2271+
static bool tty_legacy_tiocsti __read_mostly = IS_ENABLED(CONFIG_LEGACY_TIOCSTI);
22712272
static int tiocsti(struct tty_struct *tty, char __user *p)
22722273
{
22732274
char ch, mbz = 0;
22742275
struct tty_ldisc *ld;
22752276

2277+
if (!tty_legacy_tiocsti)
2278+
return -EIO;
2279+
22762280
if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
22772281
return -EPERM;
22782282
if (get_user(ch, p))
@@ -3573,6 +3577,13 @@ void console_sysfs_notify(void)
35733577
}
35743578

35753579
static struct ctl_table tty_table[] = {
3580+
{
3581+
.procname = "legacy_tiocsti",
3582+
.data = &tty_legacy_tiocsti,
3583+
.maxlen = sizeof(tty_legacy_tiocsti),
3584+
.mode = 0644,
3585+
.proc_handler = proc_dobool,
3586+
},
35763587
{
35773588
.procname = "ldisc_autoload",
35783589
.data = &tty_ldisc_autoload,

0 commit comments

Comments
 (0)