summaryrefslogtreecommitdiffstats
path: root/sys/fs/devfs/devfs_vnops.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2003-01-13 22:20:36 +0000
committerphk <phk@FreeBSD.org>2003-01-13 22:20:36 +0000
commit7558240f5690462141d1e37d1edf444520a3afc8 (patch)
tree951fa9709e9d03b4e78204be6055e8e1d8fdb8a2 /sys/fs/devfs/devfs_vnops.c
parent26e1430b79f110018841137c1850f907738f4080 (diff)
downloadFreeBSD-src-7558240f5690462141d1e37d1edf444520a3afc8.zip
FreeBSD-src-7558240f5690462141d1e37d1edf444520a3afc8.tar.gz
Even if the permissions deny it, a process should be allowed to
access its controlling terminal. In essense, history dictates that any process is allowed to open /dev/tty for RW, irrespective of credential, because by definition it is it's own controlling terminal. Before DEVFS we relied on a hacky half-device thing (kern/tty_tty.c) which did the magic deep down at device level, which at best was disgusting from an architectural point of view. My first shot at this was to use the cloning mechanism to simply give people the right tty when they ask for /dev/tty, that's why you get this, slightly counter intuitive result: syv# ls -l /dev/tty `tty` crw--w---- 1 u1 tty 5, 0 Jan 13 22:14 /dev/tty crw--w---- 1 u1 tty 5, 0 Jan 13 22:14 /dev/ttyp0 Trouble is, when user u1 su(1)'s to user u2, he cannot open /dev/ttyp0 anymore because he doesn't have permission to do so. The above fix allows him to do that. The interesting side effect is that one was previously only able to access the controlling tty by indirection: date > /dev/tty but not by name: date > `tty` This is now possible, and that feels a lot more like DTRT. PR: 46635 MFC candidate: could be.
Diffstat (limited to 'sys/fs/devfs/devfs_vnops.c')
-rw-r--r--sys/fs/devfs/devfs_vnops.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c
index 3f28566..6f466ad 100644
--- a/sys/fs/devfs/devfs_vnops.c
+++ b/sys/fs/devfs/devfs_vnops.c
@@ -181,13 +181,24 @@ devfs_access(ap)
{
struct vnode *vp = ap->a_vp;
struct devfs_dirent *de;
+ int error;
de = vp->v_data;
if (vp->v_type == VDIR)
de = de->de_dir;
- return (vaccess(vp->v_type, de->de_mode, de->de_uid, de->de_gid,
- ap->a_mode, ap->a_cred, NULL));
+ error = vaccess(vp->v_type, de->de_mode, de->de_uid, de->de_gid,
+ ap->a_mode, ap->a_cred, NULL);
+ if (!error)
+ return (error);
+ if (error != EACCES)
+ return (error);
+ /* We do, however, allow access to the controlling terminal */
+ if (!(ap->a_td->td_proc->p_flag & P_CONTROLT))
+ return (error);
+ if (ap->a_td->td_proc->p_session->s_ttyvp == de->de_vnode)
+ return (0);
+ return (error);
}
static int
OpenPOWER on IntegriCloud