Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Sep 2019 14:06:44 -0000
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r346120 - head/sys/kern
Message-ID:  <201904111121.x3BBLj2K023087@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Thu Apr 11 11:21:45 2019
New Revision: 346120
URL: https://svnweb.freebsd.org/changeset/base/346120

Log:
  Use shared vnode locks for the ELF interpreter.
  
  Reviewed by:	kib
  MFC after:	2 weeks
  Sponsored by:	DARPA, AFRL
  Differential Revision:	https://reviews.freebsd.org/D19874

Modified:
  head/sys/kern/imgact_elf.c

Modified: head/sys/kern/imgact_elf.c
==============================================================================
--- head/sys/kern/imgact_elf.c	Thu Apr 11 08:06:45 2019	(r346119)
+++ head/sys/kern/imgact_elf.c	Thu Apr 11 11:21:45 2019	(r346120)
@@ -716,7 +716,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;
 
@@ -744,7 +744,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;
@@ -759,15 +762,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;
 





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904111121.x3BBLj2K023087>