summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2008-09-06 14:43:32 +0000
committered <ed@FreeBSD.org>2008-09-06 14:43:32 +0000
commite4b90a03d05abcb1cb539ca3be7a7f39c6790f3b (patch)
treece8e7dfcdd24c64077d8e77b7359a4dab9e7b46c /sys/kern/tty.c
parent381ab7b037e665a260724873ebaf6f70e2822b51 (diff)
downloadFreeBSD-src-e4b90a03d05abcb1cb539ca3be7a7f39c6790f3b.zip
FreeBSD-src-e4b90a03d05abcb1cb539ca3be7a7f39c6790f3b.tar.gz
Make TIOCCONS use priv_check() instead of checking /dev/console permissions.
As discussed with Robert on IRC, checking the permissions on /dev/console to see if we can call TIOCCONS could be unreliable. When we run a chroot() without a devfs instance mounted inside, it won't actually check the permissions on the device node inside the devfs instance. Using the already existing PRIV_TTY_CONSOLE for this seems like a better idea. Approved by: rwatson
Diffstat (limited to 'sys/kern/tty.c')
-rw-r--r--sys/kern/tty.c43
1 files changed, 8 insertions, 35 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index c0a064a..bb0fb02 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$");
#include <sys/limits.h>
#include <sys/malloc.h>
#include <sys/mount.h>
-#include <sys/namei.h>
#include <sys/poll.h>
#include <sys/priv.h>
#include <sys/proc.h>
@@ -60,7 +59,6 @@ __FBSDID("$FreeBSD$");
#include <sys/ttydefaults.h>
#undef TTYDEFCHARS
#include <sys/ucred.h>
-#include <sys/vnode.h>
#include <machine/stdarg.h>
@@ -1513,46 +1511,21 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, struct thread *td)
case TIOCCONS:
/* Set terminal as console TTY. */
if (*(int *)data) {
- struct nameidata nd;
- int vfslocked;
+ error = priv_check(td, PRIV_TTY_CONSOLE);
+ if (error)
+ return (error);
/*
- * XXX: TTY won't slip away, but constty would
- * really need to be locked!
+ * XXX: constty should really need to be locked!
+ * XXX: allow disconnected constty's to be stolen!
*/
- tty_unlock(tp);
- if (constty == tp) {
- tty_lock(tp);
+ if (constty == tp)
return (0);
- }
- if (constty != NULL) {
- tty_lock(tp);
+ if (constty != NULL)
return (EBUSY);
- }
- /* XXX: allow disconnected constty's to be stolen! */
-
- /*
- * Only allow this to work when the user can
- * open /dev/console.
- */
- NDINIT(&nd, LOOKUP, FOLLOW|LOCKLEAF|MPSAFE,
- UIO_SYSSPACE, "/dev/console", td);
- if ((error = namei(&nd)) != 0) {
- tty_lock(tp);
- return (error);
- }
- vfslocked = NDHASGIANT(&nd);
- NDFREE(&nd, NDF_ONLY_PNBUF);
-
- error = VOP_ACCESS(nd.ni_vp, VREAD, td->td_ucred, td);
- vput(nd.ni_vp);
- VFS_UNLOCK_GIANT(vfslocked);
- if (error) {
- tty_lock(tp);
- return (error);
- }
+ tty_unlock(tp);
constty_set(tp);
tty_lock(tp);
} else if (constty == tp) {
OpenPOWER on IntegriCloud