Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 May 2002 14:54:02 -0700 (PDT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 11490 for review
Message-ID:  <200205182154.g4ILs2046258@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=11490

Change 11490 by rwatson@rwatson_curry on 2002/05/18 14:53:42

	Re-structure __mac_set_proc() so that it does process locking,
	and grabs Giant a little later.  This actually appears to simplify
	things a bit, interestingly.

Affected files ...

... //depot/projects/trustedbsd/mac/sys/kern/kern_mac.c#145 edit

Differences ...

==== //depot/projects/trustedbsd/mac/sys/kern/kern_mac.c#145 (text+ko) ====

@@ -1641,7 +1641,6 @@
 
 /*
  * MPSAFE
- * XXX Proc Locking
  */
 int
 __mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
@@ -1650,35 +1649,34 @@
 	struct mac newlabel;
 	int error;
 
-	mtx_lock(&Giant);
-	oldcred = td->td_proc->p_ucred;
-	newcred = crdup(td->td_proc->p_ucred);
-	if (newcred == NULL) {
-		error = ENOMEM;
-		goto out;
-	}
-
+	newcred = crget();
 	error = copyin(SCARG(uap, mac_p), &newlabel, sizeof(newlabel));
-	if (error) {
+	if (error) {   
 		crfree(newcred);
-		goto out;
+		return (error);
 	}
 
+	mtx_lock(&Giant);
+	PROC_LOCK(td->td_proc);
+	oldcred = td->td_proc->p_ucred;
+
 	error = mac_cred_check_relabel_subject(oldcred, &newlabel);
 	if (error) {
+		PROC_UNLOCK(td->td_proc);
 		crfree(newcred);
-		goto out;
+		mtx_unlock(&Giant);
+		return (error);
 	}
 
 	setsugid(td->td_proc);
 	mac_relabel_subject(newcred, &newlabel);
 
 	td->td_proc->p_ucred = newcred;
+
+	PROC_UNLOCK(td->td_proc);
 	crfree(oldcred);
-
-out:
 	mtx_unlock(&Giant);
-	return (error);
+	return (0);
 }
 
 /*

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




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