Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jun 2018 09:18:38 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r335536 - stable/11/sys/kern
Message-ID:  <201806220918.w5M9Iclp028057@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Fri Jun 22 09:18:38 2018
New Revision: 335536
URL: https://svnweb.freebsd.org/changeset/base/335536

Log:
  MFC r332816: call racct_proc_ucred_changed() under the proc lock

Modified:
  stable/11/sys/kern/kern_jail.c
  stable/11/sys/kern/kern_loginclass.c
  stable/11/sys/kern/kern_prot.c
  stable/11/sys/kern/kern_racct.c
  stable/11/sys/kern/kern_rctl.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/kern_jail.c
==============================================================================
--- stable/11/sys/kern/kern_jail.c	Fri Jun 22 09:10:50 2018	(r335535)
+++ stable/11/sys/kern/kern_jail.c	Fri Jun 22 09:18:38 2018	(r335536)
@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/lock.h>
 #include <sys/mutex.h>
 #include <sys/racct.h>
+#include <sys/rctl.h>
 #include <sys/refcount.h>
 #include <sys/sx.h>
 #include <sys/sysent.h>
@@ -2409,10 +2410,15 @@ do_jail_attach(struct thread *td, struct prison *pr)
 	newcred->cr_prison = pr;
 	proc_set_cred(p, newcred);
 	setsugid(p);
-	PROC_UNLOCK(p);
 #ifdef RACCT
 	racct_proc_ucred_changed(p, oldcred, newcred);
+	crhold(newcred);
 #endif
+	PROC_UNLOCK(p);
+#ifdef RCTL
+	rctl_proc_ucred_changed(p, newcred);
+	crfree(newcred);
+#endif
 	prison_deref(oldcred->cr_prison, PD_DEREF | PD_DEUREF);
 	crfree(oldcred);
 	return (0);
@@ -3959,6 +3965,7 @@ prison_racct_modify(struct prison *pr)
 	 */
 	racct_move(pr->pr_prison_racct->prr_racct, oldprr->prr_racct);
 
+#ifdef RCTL
 	/*
 	 * Force rctl to reattach rules to processes.
 	 */
@@ -3966,9 +3973,10 @@ prison_racct_modify(struct prison *pr)
 		PROC_LOCK(p);
 		cred = crhold(p->p_ucred);
 		PROC_UNLOCK(p);
-		racct_proc_ucred_changed(p, cred, cred);
+		rctl_proc_ucred_changed(p, cred);
 		crfree(cred);
 	}
+#endif
 
 	sx_sunlock(&allproc_lock);
 	prison_racct_free_locked(oldprr);

Modified: stable/11/sys/kern/kern_loginclass.c
==============================================================================
--- stable/11/sys/kern/kern_loginclass.c	Fri Jun 22 09:10:50 2018	(r335535)
+++ stable/11/sys/kern/kern_loginclass.c	Fri Jun 22 09:18:38 2018	(r335536)
@@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/proc.h>
 #include <sys/queue.h>
 #include <sys/racct.h>
+#include <sys/rctl.h>
 #include <sys/refcount.h>
 #include <sys/rwlock.h>
 #include <sys/sysproto.h>
@@ -222,9 +223,14 @@ sys_setloginclass(struct thread *td, struct setlogincl
 	oldcred = crcopysafe(p, newcred);
 	newcred->cr_loginclass = newlc;
 	proc_set_cred(p, newcred);
-	PROC_UNLOCK(p);
 #ifdef RACCT
 	racct_proc_ucred_changed(p, oldcred, newcred);
+	crhold(newcred);
+#endif
+	PROC_UNLOCK(p);
+#ifdef RCTL
+	rctl_proc_ucred_changed(p, newcred);
+	crfree(newcred);
 #endif
 	loginclass_free(oldcred->cr_loginclass);
 	crfree(oldcred);

Modified: stable/11/sys/kern/kern_prot.c
==============================================================================
--- stable/11/sys/kern/kern_prot.c	Fri Jun 22 09:10:50 2018	(r335535)
+++ stable/11/sys/kern/kern_prot.c	Fri Jun 22 09:18:38 2018	(r335536)
@@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/jail.h>
 #include <sys/pioctl.h>
 #include <sys/racct.h>
+#include <sys/rctl.h>
 #include <sys/resourcevar.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
@@ -579,10 +580,15 @@ sys_setuid(struct thread *td, struct setuid_args *uap)
 		setsugid(p);
 	}
 	proc_set_cred(p, newcred);
-	PROC_UNLOCK(p);
 #ifdef RACCT
 	racct_proc_ucred_changed(p, oldcred, newcred);
+	crhold(newcred);
 #endif
+	PROC_UNLOCK(p);
+#ifdef RCTL
+	rctl_proc_ucred_changed(p, newcred);
+	crfree(newcred);
+#endif
 	uifree(uip);
 	crfree(oldcred);
 	return (0);
@@ -927,10 +933,15 @@ sys_setreuid(struct thread *td, struct setreuid_args *
 		setsugid(p);
 	}
 	proc_set_cred(p, newcred);
-	PROC_UNLOCK(p);
 #ifdef RACCT
 	racct_proc_ucred_changed(p, oldcred, newcred);
+	crhold(newcred);
 #endif
+	PROC_UNLOCK(p);
+#ifdef RCTL
+	rctl_proc_ucred_changed(p, newcred);
+	crfree(newcred);
+#endif
 	uifree(ruip);
 	uifree(euip);
 	crfree(oldcred);
@@ -1068,9 +1079,14 @@ sys_setresuid(struct thread *td, struct setresuid_args
 		setsugid(p);
 	}
 	proc_set_cred(p, newcred);
-	PROC_UNLOCK(p);
 #ifdef RACCT
 	racct_proc_ucred_changed(p, oldcred, newcred);
+	crhold(newcred);
+#endif
+	PROC_UNLOCK(p);
+#ifdef RCTL
+	rctl_proc_ucred_changed(p, newcred);
+	crfree(newcred);
 #endif
 	uifree(ruip);
 	uifree(euip);

Modified: stable/11/sys/kern/kern_racct.c
==============================================================================
--- stable/11/sys/kern/kern_racct.c	Fri Jun 22 09:10:50 2018	(r335535)
+++ stable/11/sys/kern/kern_racct.c	Fri Jun 22 09:18:38 2018	(r335536)
@@ -1048,7 +1048,7 @@ racct_proc_ucred_changed(struct proc *p, struct ucred 
 	if (!racct_enable)
 		return;
 
-	PROC_LOCK_ASSERT(p, MA_NOTOWNED);
+	PROC_LOCK_ASSERT(p, MA_OWNED);
 
 	newuip = newcred->cr_ruidinfo;
 	olduip = oldcred->cr_ruidinfo;
@@ -1075,10 +1075,6 @@ racct_proc_ucred_changed(struct proc *p, struct ucred 
 			    p->p_racct);
 	}
 	RACCT_UNLOCK();
-
-#ifdef RCTL
-	rctl_proc_ucred_changed(p, newcred);
-#endif
 }
 
 void

Modified: stable/11/sys/kern/kern_rctl.c
==============================================================================
--- stable/11/sys/kern/kern_rctl.c	Fri Jun 22 09:10:50 2018	(r335535)
+++ stable/11/sys/kern/kern_rctl.c	Fri Jun 22 09:18:38 2018	(r335536)
@@ -1954,12 +1954,15 @@ rctl_proc_ucred_changed(struct proc *p, struct ucred *
 	struct prison_racct *newprr;
 	int rulecnt, i;
 
-	ASSERT_RACCT_ENABLED();
+	if (!racct_enable)
+		return;
 
+	PROC_LOCK_ASSERT(p, MA_NOTOWNED);
+
 	newuip = newcred->cr_ruidinfo;
 	newlc = newcred->cr_loginclass;
 	newprr = newcred->cr_prison->pr_prison_racct;
-	
+
 	LIST_INIT(&newrules);
 
 again:



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