svn commit: r347579 - stable/12/sys/kern
Edward Tomasz Napierala
trasz at FreeBSD.org
Tue May 14 20:41:25 UTC 2019
Author: trasz
Date: Tue May 14 20:41:24 2019
New Revision: 347579
URL: https://svnweb.freebsd.org/changeset/base/347579
Log:
MFC r346120:
Use shared vnode locks for the ELF interpreter.
Sponsored by: DARPA, AFRL
Modified:
stable/12/sys/kern/imgact_elf.c
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/sys/kern/imgact_elf.c
==============================================================================
--- stable/12/sys/kern/imgact_elf.c Tue May 14 20:32:29 2019 (r347578)
+++ stable/12/sys/kern/imgact_elf.c Tue May 14 20:41:24 2019 (r347579)
@@ -717,7 +717,7 @@ __elfN(load_file)(struct proc *p, const char *file, u_
struct nameidata *nd;
struct vattr *attr;
struct image_params *imgp;
- u_long rbase;
+ u_long flags, rbase;
u_long base_addr = 0;
int error;
@@ -745,7 +745,10 @@ __elfN(load_file)(struct proc *p, const char *file, u_
imgp->object = NULL;
imgp->execlabel = NULL;
- NDINIT(nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_SYSSPACE, file, curthread);
+ flags = FOLLOW | LOCKSHARED | LOCKLEAF;
+
+again:
+ NDINIT(nd, LOOKUP, flags, UIO_SYSSPACE, file, curthread);
if ((error = namei(nd)) != 0) {
nd->ni_vp = NULL;
goto fail;
@@ -760,15 +763,30 @@ __elfN(load_file)(struct proc *p, const char *file, u_
if (error)
goto fail;
+ /*
+ * Also make certain that the interpreter stays the same,
+ * so set its VV_TEXT flag, too. Since this function is only
+ * used to load the interpreter, the VV_TEXT is almost always
+ * already set.
+ */
+ if (VOP_IS_TEXT(nd->ni_vp) == 0) {
+ if (VOP_ISLOCKED(nd->ni_vp) != LK_EXCLUSIVE) {
+ /*
+ * LK_UPGRADE could have resulted in dropping
+ * the lock. Just try again from the start,
+ * this time with exclusive vnode lock.
+ */
+ vput(nd->ni_vp);
+ flags &= ~LOCKSHARED;
+ goto again;
+ }
+
+ VOP_SET_TEXT(nd->ni_vp);
+ }
+
error = exec_map_first_page(imgp);
if (error)
goto fail;
-
- /*
- * Also make certain that the interpreter stays the same, so set
- * its VV_TEXT flag, too.
- */
- VOP_SET_TEXT(nd->ni_vp);
imgp->object = nd->ni_vp->v_object;
More information about the svn-src-all
mailing list