From a25733769887116a0bfc2958ab8fe913784fa4cd Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Wed, 7 Feb 2007 10:30:49 +0000 Subject: [PATCH] Fix the race of dereferencing /proc//file with execve(2) by caching the value of p_textvp. This way, we always unlock the locked vnode. While there, vhold() the vnode around the vn_lock(). Reported and tested by: Guy Helmer (ghelmer palisadesys com) Approved by: des (procfs maintainer) MFC after: 1 week --- sys/fs/procfs/procfs.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sys/fs/procfs/procfs.c b/sys/fs/procfs/procfs.c index 90d8975a23b..d311a98a527 100644 --- a/sys/fs/procfs/procfs.c +++ b/sys/fs/procfs/procfs.c @@ -69,10 +69,18 @@ procfs_doprocfile(PFS_FILL_ARGS) { char *fullpath = "unknown"; char *freepath = NULL; + struct vnode *textvp; + int err; - vn_lock(p->p_textvp, LK_EXCLUSIVE | LK_RETRY, td); - vn_fullpath(td, p->p_textvp, &fullpath, &freepath); - VOP_UNLOCK(p->p_textvp, 0, td); + textvp = p->p_textvp; + VI_LOCK(textvp); + vholdl(textvp); + err = vn_lock(textvp, LK_EXCLUSIVE | LK_INTERLOCK, td); + vdrop(textvp); + if (err) + return (err); + vn_fullpath(td, textvp, &fullpath, &freepath); + VOP_UNLOCK(textvp, 0, td); sbuf_printf(sb, "%s", fullpath); if (freepath) free(freepath, M_TEMP);