Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Jan 2012 23:03:32 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r230341 - head/sys/kern
Message-ID:  <201201192303.q0JN3W7o011525@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Thu Jan 19 23:03:31 2012
New Revision: 230341
URL: http://svn.freebsd.org/changeset/base/230341

Log:
  Use shared lock for the executable vnode in the exec path after the
  VV_TEXT changes are handled. Assert that vnode is exclusively locked at
  the places that modify VV_TEXT.
  
  Discussed with:	alc
  MFC after:	3 weeks

Modified:
  head/sys/kern/kern_exec.c

Modified: head/sys/kern/kern_exec.c
==============================================================================
--- head/sys/kern/kern_exec.c	Thu Jan 19 21:38:19 2012	(r230340)
+++ head/sys/kern/kern_exec.c	Thu Jan 19 23:03:31 2012	(r230341)
@@ -471,6 +471,7 @@ interpret:
 	 * actually an executable image.
 	 */
 	textset = imgp->vp->v_vflag & VV_TEXT;
+	ASSERT_VOP_ELOCKED(imgp->vp, "vv_text");
 	imgp->vp->v_vflag |= VV_TEXT;
 
 	error = exec_map_first_page(imgp);
@@ -502,8 +503,10 @@ interpret:
 
 	if (error) {
 		if (error == -1) {
-			if (textset == 0)
+			if (textset == 0) {
+				ASSERT_VOP_ELOCKED(imgp->vp, "vv_text");
 				imgp->vp->v_vflag &= ~VV_TEXT;
+			}
 			error = ENOEXEC;
 		}
 		goto exec_fail_dealloc;
@@ -596,7 +599,7 @@ interpret:
 
 	/* close files on exec */
 	fdcloseexec(td);
-	vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY);
+	vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
 
 	/* Get a reference to the vnode prior to locking the proc */
 	VREF(binvp);
@@ -701,7 +704,7 @@ interpret:
 		VOP_UNLOCK(imgp->vp, 0);
 		setugidsafety(td);
 		error = fdcheckstd(td);
-		vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY);
+		vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
 		if (error != 0)
 			goto done1;
 		PROC_LOCK(p);
@@ -805,7 +808,7 @@ interpret:
 		pe.pm_entryaddr = imgp->entry_addr;
 
 		PMC_CALL_HOOK_X(td, PMC_FN_PROCESS_EXEC, (void *) &pe);
-		vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY);
+		vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
 	} else
 		PROC_UNLOCK(p);
 #else  /* !HWPMC_HOOKS */
@@ -857,7 +860,7 @@ done1:
 	if (tracecred != NULL)
 		crfree(tracecred);
 #endif
-	vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY);
+	vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
 	pargs_drop(oldargs);
 	pargs_drop(newargs);
 	if (oldsigacts != NULL)



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