Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 May 2019 20:41:24 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r347579 - stable/12/sys/kern
Message-ID:  <201905142041.x4EKfO7v078703@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;
 



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