Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Only allow root to use TIOCSTI. Don't eat the kauth...



details:   https://anonhg.NetBSD.org/src/rev/eb870f0d6e75
branches:  trunk
changeset: 348015:eb870f0d6e75
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Sep 29 21:46:32 2016 +0000

description:
Only allow root to use TIOCSTI. Don't eat the kauth error number.
It is unexpected for an unprivileged process to gain privs by
typing to root's tty:

$ cat installer
#!/bin/sh
whoami
/usr/sbin/sti /dev/tty whoami\\n

$ su unprivileged -c ./installer
unprivileged
$ whoami
root

diffstat:

 sys/kern/tty.c |  13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diffs (36 lines):

diff -r 7596236c3abc -r eb870f0d6e75 sys/kern/tty.c
--- a/sys/kern/tty.c    Thu Sep 29 20:47:18 2016 +0000
+++ b/sys/kern/tty.c    Thu Sep 29 21:46:32 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty.c,v 1.271 2016/07/07 06:55:43 msaitoh Exp $        */
+/*     $NetBSD: tty.c,v 1.272 2016/09/29 21:46:32 christos Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.271 2016/07/07 06:55:43 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.272 2016/09/29 21:46:32 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1240,12 +1240,13 @@
                mutex_spin_exit(&tty_lock);
                break;
        case TIOCSTI:                   /* simulate terminal input */
-               if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_STI,
-                   tp) != 0) {
+               if ((error = kauth_authorize_device_tty(l->l_cred,
+                   KAUTH_DEVICE_TTY_STI, tp)) != 0) {
                        if (!ISSET(flag, FREAD))
-                               return (EPERM);
+                               return EPERM;
                        if (!isctty(p, tp))
-                               return (EACCES);
+                               return EACCES;
+                       return error;
                }
                (*tp->t_linesw->l_rint)(*(u_char *)data, tp);
                break;



Home | Main Index | Thread Index | Old Index