Author: mjg
Date: Sat Mar 21 20:24:54 2015
New Revision: 280331
URL: https://svnweb.freebsd.org/changeset/base/280331

Log:
  cred: add proc_set_cred_init helper
  
  proc_set_cred_init can be used to set first credentials of a new
  process.
  
  Update proc_set_cred assertions so that it only expects already used
  processes.
  
  This fixes panics where p_ucred of a new process happens to be non-NULL.
  
  Reviewed by:  kib

Modified:
  head/sys/kern/init_main.c
  head/sys/kern/kern_fork.c
  head/sys/kern/kern_prot.c
  head/sys/sys/ucred.h

Modified: head/sys/kern/init_main.c
==============================================================================
--- head/sys/kern/init_main.c   Sat Mar 21 20:24:03 2015        (r280330)
+++ head/sys/kern/init_main.c   Sat Mar 21 20:24:54 2015        (r280331)
@@ -515,7 +515,7 @@ proc0_init(void *dummy __unused)
        newcred->cr_ruidinfo = uifind(0);
        newcred->cr_prison = &prison0;
        newcred->cr_loginclass = loginclass_find("default");
-       proc_set_cred(p, newcred);
+       proc_set_cred_init(p, newcred);
 #ifdef AUDIT
        audit_cred_kproc0(newcred);
 #endif

Modified: head/sys/kern/kern_fork.c
==============================================================================
--- head/sys/kern/kern_fork.c   Sat Mar 21 20:24:03 2015        (r280330)
+++ head/sys/kern/kern_fork.c   Sat Mar 21 20:24:54 2015        (r280331)
@@ -867,7 +867,7 @@ fork1(struct thread *td, int flags, int 
         * XXX: This is ugly; when we copy resource usage, we need to bump
         *      per-cred resource counters.
         */
-       proc_set_cred(newproc, crhold(td->td_ucred));
+       proc_set_cred_init(newproc, crhold(td->td_ucred));
 
        /*
         * Initialize resource accounting for the child process.

Modified: head/sys/kern/kern_prot.c
==============================================================================
--- head/sys/kern/kern_prot.c   Sat Mar 21 20:24:03 2015        (r280330)
+++ head/sys/kern/kern_prot.c   Sat Mar 21 20:24:54 2015        (r280331)
@@ -1954,8 +1954,19 @@ cred_update_thread(struct thread *td)
 }
 
 /*
+ * Set initial process credentials.
+ * Callers are responsible for providing the reference for provided 
credentials.
+ */
+void
+proc_set_cred_init(struct proc *p, struct ucred *newcred)
+{
+
+       p->p_ucred = newcred;
+}
+
+/*
  * Change process credentials.
- * Callers are responsible for providing the reference for current credentials
+ * Callers are responsible for providing the reference for passed credentials
  * and for freeing old ones.
  *
  * Process has to be locked except when it does not have credentials (as it
@@ -1968,9 +1979,10 @@ proc_set_cred(struct proc *p, struct ucr
 {
        struct ucred *oldcred;
 
+       MPASS(p->p_ucred != NULL);
        if (newcred == NULL)
                MPASS(p->p_state == PRS_ZOMBIE);
-       else if (p->p_ucred != NULL)
+       else
                PROC_LOCK_ASSERT(p, MA_OWNED);
 
        oldcred = p->p_ucred;

Modified: head/sys/sys/ucred.h
==============================================================================
--- head/sys/sys/ucred.h        Sat Mar 21 20:24:03 2015        (r280330)
+++ head/sys/sys/ucred.h        Sat Mar 21 20:24:54 2015        (r280331)
@@ -106,6 +106,7 @@ void        crcopy(struct ucred *dest, struct u
 struct ucred   *crcopysafe(struct proc *p, struct ucred *cr);
 struct ucred   *crdup(struct ucred *cr);
 void   cred_update_thread(struct thread *td);
+void   proc_set_cred_init(struct proc *p, struct ucred *cr);
 struct ucred   *proc_set_cred(struct proc *p, struct ucred *cr);
 void   crfree(struct ucred *cr);
 struct ucred   *crget(void);
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to