diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 33e8759c97ff..d6937b7ca64e 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -716,7 +716,8 @@ kern___getcwd(struct thread *td, u_char *buf, enum uio_seg bufseg, u_int buflen) { char *bp, *tmpbuf; struct filedesc *fdp; - int error; + struct vnode *cdir, *rdir; + int error, vfslocked; if (disablecwd) return (ENODEV); @@ -728,9 +729,18 @@ kern___getcwd(struct thread *td, u_char *buf, enum uio_seg bufseg, u_int buflen) tmpbuf = malloc(buflen, M_TEMP, M_WAITOK); fdp = td->td_proc->p_fd; FILEDESC_SLOCK(fdp); - error = vn_fullpath1(td, fdp->fd_cdir, fdp->fd_rdir, tmpbuf, - &bp, buflen); + cdir = fdp->fd_cdir; + VREF(cdir); + rdir = fdp->fd_rdir; + VREF(rdir); FILEDESC_SUNLOCK(fdp); + error = vn_fullpath1(td, cdir, rdir, tmpbuf, &bp, buflen); + vfslocked = VFS_LOCK_GIANT(rdir->v_mount); + vrele(rdir); + VFS_UNLOCK_GIANT(vfslocked); + vfslocked = VFS_LOCK_GIANT(cdir->v_mount); + vrele(cdir); + VFS_UNLOCK_GIANT(vfslocked); if (!error) { if (bufseg == UIO_SYSSPACE) @@ -771,7 +781,8 @@ vn_fullpath(struct thread *td, struct vnode *vn, char **retbuf, char **freebuf) { char *buf; struct filedesc *fdp; - int error; + struct vnode *rdir; + int error, vfslocked; if (disablefullpath) return (ENODEV); @@ -781,8 +792,13 @@ vn_fullpath(struct thread *td, struct vnode *vn, char **retbuf, char **freebuf) buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); fdp = td->td_proc->p_fd; FILEDESC_SLOCK(fdp); - error = vn_fullpath1(td, vn, fdp->fd_rdir, buf, retbuf, MAXPATHLEN); + rdir = fdp->fd_rdir; + VREF(rdir); FILEDESC_SUNLOCK(fdp); + error = vn_fullpath1(td, vn, rdir, buf, retbuf, MAXPATHLEN); + vfslocked = VFS_LOCK_GIANT(rdir->v_mount); + vrele(rdir); + VFS_UNLOCK_GIANT(vfslocked); if (!error) *freebuf = buf;