diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -241,9 +241,9 @@ #ifndef _SYS_SYSPROTO_H_ struct execve_args { - char *fname; + char *fname; char **argv; - char **envv; + char **envv; }; #endif @@ -432,6 +432,7 @@ int error, i, orig_osrel; uint32_t orig_fctl0; Elf_Brandinfo *orig_brandinfo; + size_t freepath_size; static const char fexecv_proc_title[] = "(fexecv)"; imgp = &image_params; @@ -479,7 +480,8 @@ */ if (args->fname != NULL) { NDINIT(&nd, LOOKUP, ISOPEN | LOCKLEAF | LOCKSHARED | FOLLOW | - SAVENAME | AUDITVNODE1, UIO_SYSSPACE, args->fname, td); + WANTPARENT | SAVENAME | AUDITVNODE1, UIO_SYSSPACE, + args->fname, td); } SDT_PROBE1(proc, , , exec, args->fname); @@ -509,7 +511,8 @@ /* * Descriptors opened only with O_EXEC or O_RDONLY are allowed. */ - error = fgetvp_exec(td, args->fd, &cap_fexecve_rights, &newtextvp); + error = fgetvp_exec(td, args->fd, &cap_fexecve_rights, + &newtextvp); if (error) goto exec_fail; vn_lock(newtextvp, LK_SHARED | LK_RETRY); @@ -624,11 +627,21 @@ /* * Do the best to calculate the full path to the image file. */ - if (args->fname != NULL && args->fname[0] == '/') - imgp->execpath = args->fname; - else { + if (args->fname != NULL) { + if (args->fname[0] == '/') + imgp->execpath = args->fname; + else { + VOP_UNLOCK(imgp->vp); + freepath_size = MAXPATHLEN; + if (vn_fullpath_hardlink(&nd, &imgp->execpath, + &imgp->freepath, &freepath_size) != 0) + imgp->execpath = args->fname; + vn_lock(imgp->vp, LK_SHARED | LK_RETRY); + } + } else { VOP_UNLOCK(imgp->vp); - if (vn_fullpath(imgp->vp, &imgp->execpath, &imgp->freepath) != 0) + if (vn_fullpath(imgp->vp, &imgp->execpath, + &imgp->freepath) != 0) imgp->execpath = args->fname; vn_lock(imgp->vp, LK_SHARED | LK_RETRY); } @@ -678,8 +691,6 @@ VOP_UNSET_TEXT_CHECKED(newtextvp); imgp->textset = false; /* free name buffer and old vnode */ - if (args->fname != NULL) - NDFREE(&nd, NDF_ONLY_PNBUF); #ifdef MAC mac_execve_interpreter_enter(newtextvp, &interpvplabel); #endif @@ -688,6 +699,11 @@ imgp->opened = 0; } vput(newtextvp); + if (args->fname != NULL) { + if (nd.ni_dvp != NULL) + vrele(nd.ni_dvp); + NDFREE(&nd, NDF_ONLY_PNBUF); + } vm_object_deallocate(imgp->object); imgp->object = NULL; execve_nosetid(imgp); @@ -696,7 +712,8 @@ imgp->freepath = NULL; /* set new name to that of the interpreter */ NDINIT(&nd, LOOKUP, ISOPEN | LOCKLEAF | LOCKSHARED | FOLLOW | - SAVENAME, UIO_SYSSPACE, imgp->interpreter_name, td); + SAVENAME | WANTPARENT, UIO_SYSSPACE, + imgp->interpreter_name, td); args->fname = imgp->interpreter_name; goto interpret; } @@ -928,8 +945,6 @@ exec_unmap_first_page(imgp); if (imgp->vp != NULL) { - if (args->fname) - NDFREE(&nd, NDF_ONLY_PNBUF); if (imgp->opened) VOP_CLOSE(imgp->vp, FREAD, td->td_ucred, td); if (imgp->textset) @@ -938,6 +953,11 @@ vput(imgp->vp); else VOP_UNLOCK(imgp->vp); + if (args->fname != NULL) { + if (nd.ni_dvp != NULL) + vrele(nd.ni_dvp); + NDFREE(&nd, NDF_ONLY_PNBUF); + } } if (imgp->object != NULL) @@ -1040,7 +1060,7 @@ #endif error = vm_page_grab_valid_unlocked(&m, object, 0, VM_ALLOC_COUNT(VM_INITIAL_PAGEIN) | - VM_ALLOC_NORMAL | VM_ALLOC_NOBUSY | VM_ALLOC_WIRED); + VM_ALLOC_NORMAL | VM_ALLOC_NOBUSY | VM_ALLOC_WIRED); if (error != VM_PAGER_OK) return (EIO); @@ -1985,7 +2005,8 @@ if (locked) PROC_UNLOCK(p); if (cp->comp != NULL) - error = compressor_write(cp->comp, __DECONST(char *, data), len); + error = compressor_write(cp->comp, __DECONST(char *, data), + len); else error = core_write(cp, __DECONST(void *, data), len, cp->offset, UIO_SYSSPACE, NULL); diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -579,8 +579,6 @@ "Number of times 3-way vnode locking failed"); static void cache_zap_locked(struct namecache *ncp); -static int vn_fullpath_hardlink(struct nameidata *ndp, char **retbuf, - char **freebuf, size_t *buflen); static int vn_fullpath_any_smr(struct vnode *vp, struct vnode *rdir, char *buf, char **retbuf, size_t *buflen, size_t addend); static int vn_fullpath_any(struct vnode *vp, struct vnode *rdir, char *buf, @@ -3602,7 +3600,7 @@ * - otherwise we populate the buffer with the saved name and start resolving * from the parent */ -static int +int vn_fullpath_hardlink(struct nameidata *ndp, char **retbuf, char **freebuf, size_t *buflen) { diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -697,6 +697,8 @@ int vn_getcwd(char *buf, char **retbuf, size_t *buflen); int vn_fullpath(struct vnode *vp, char **retbuf, char **freebuf); int vn_fullpath_global(struct vnode *vp, char **retbuf, char **freebuf); +int vn_fullpath_hardlink(struct nameidata *ndp, char **retbuf, + char **freebuf, size_t *buflen); struct vnode * vn_dir_dd_ino(struct vnode *vp); int vn_commname(struct vnode *vn, char *buf, u_int buflen);