From 6370253bdc1d9199f89dc3a29376633daec69c12 Mon Sep 17 00:00:00 2001 From: jhb Date: Fri, 21 Jul 2006 20:28:56 +0000 Subject: Add conditional VFS Giant locking to svr4_sys_fchroot() and mark it MPSAFE. Also, call change_dir() instead of doing part of it inline (this now adds a mac_check_vnode_chdir() call) to match fchdir() and call mac_check_vnode_chroot() to match chroot(). Also, use the change_root() function to do the actual change root to match chroot(). Reviewed by: rwatson --- sys/compat/svr4/svr4_misc.c | 40 +++++++++++++++++++++------------------- sys/compat/svr4/syscalls.master | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) (limited to 'sys/compat') diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c index fea3608..6701cf8 100644 --- a/sys/compat/svr4/svr4_misc.c +++ b/sys/compat/svr4/svr4_misc.c @@ -606,34 +606,36 @@ svr4_sys_fchroot(td, uap) struct svr4_sys_fchroot_args *uap; { struct filedesc *fdp = td->td_proc->p_fd; - struct vnode *vp, *vpold; + struct vnode *vp; struct file *fp; - int error; + int error, vfslocked; if ((error = suser(td)) != 0) return error; if ((error = getvnode(fdp, uap->fd, &fp)) != 0) return error; vp = fp->f_vnode; - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); - if (vp->v_type != VDIR) - error = ENOTDIR; - else - error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td); - VOP_UNLOCK(vp, 0, td); - if (error) { - fdrop(fp, td); - return error; - } VREF(vp); - FILEDESC_LOCK_FAST(fdp); - vpold = fdp->fd_rdir; - fdp->fd_rdir = vp; - FILEDESC_UNLOCK_FAST(fdp); - if (vpold != NULL) - vrele(vpold); fdrop(fp, td); - return 0; + vfslocked = VFS_LOCK_GIANT(vp->v_mount); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); + error = change_dir(vp, td); + if (error) + goto fail; +#ifdef MAC + error = mac_check_vnode_chroot(td->td_ucred, vp); + if (error) + goto fail; +#endif + VOP_UNLOCK(vp, 0, td); + error = change_root(vp, td); + vrele(vp); + VFS_UNLOCK_GIANT(vfslocked); + return (error); +fail: + vput(vp); + VFS_UNLOCK_GIANT(vfslocked); + return (error); } diff --git a/sys/compat/svr4/syscalls.master b/sys/compat/svr4/syscalls.master index a5d6a94..b407c12 100644 --- a/sys/compat/svr4/syscalls.master +++ b/sys/compat/svr4/syscalls.master @@ -250,7 +250,7 @@ 150 AUE_NULL UNIMPL notused 151 AUE_NULL UNIMPL notused 152 AUE_NULL UNIMPL modctl -153 AUE_NULL STD { int svr4_sys_fchroot(int fd); } +153 AUE_NULL MSTD { int svr4_sys_fchroot(int fd); } 154 AUE_NULL MSTD { int svr4_sys_utimes(char *path, \ struct timeval *tptr); } 155 AUE_NULL MSTD { int svr4_sys_vhangup(void); } -- cgit v1.1