diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/init_main.c | 2 | ||||
-rw-r--r-- | sys/kern/kern_fork.c | 16 | ||||
-rw-r--r-- | sys/kern/kern_prot.c | 16 | ||||
-rw-r--r-- | sys/kern/sched_4bsd.c | 2 | ||||
-rw-r--r-- | sys/sys/ucred.h | 1 |
5 files changed, 25 insertions, 12 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 03a3d9e..b8e3596 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -520,7 +520,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 diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index a5595c9..a84b619 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -412,9 +412,6 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2, p2->p_treeflag = 0; p2->p_filemon = NULL; - crhold(td->td_ucred); - proc_set_cred(p2, td->td_ucred); - /* Tell the prison that we exist. */ prison_proc_hold(p2->p_ucred->cr_prison); @@ -875,7 +872,7 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp, td2 = thread_alloc(pages); if (td2 == NULL) { error = ENOMEM; - goto fail1; + goto fail2; } proc_linkup(newproc, td2); } else { @@ -884,7 +881,7 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp, vm_thread_dispose(td2); if (!thread_alloc_stack(td2, pages)) { error = ENOMEM; - goto fail1; + goto fail2; } } } @@ -893,7 +890,7 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp, vm2 = vmspace_fork(p1->p_vmspace, &mem_charged); if (vm2 == NULL) { error = ENOMEM; - goto fail1; + goto fail2; } if (!swap_reserve(mem_charged)) { /* @@ -904,7 +901,7 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp, */ swap_reserve_force(mem_charged); error = ENOMEM; - goto fail1; + goto fail2; } } else vm2 = NULL; @@ -913,7 +910,7 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp, * XXX: This is ugly; when we copy resource usage, we need to bump * per-cred resource counters. */ - proc_set_cred(newproc, p1->p_ucred); + proc_set_cred_init(newproc, crhold(td->td_ucred)); /* * Initialize resource accounting for the child process. @@ -974,6 +971,9 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp, #endif racct_proc_exit(newproc); fail1: + crfree(newproc->p_ucred); + newproc->p_ucred = NULL; +fail2: if (vm2 != NULL) vmspace_free(vm2); uma_zfree(proc_zone, newproc); diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 8235a1a..6d6a92f 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1957,8 +1957,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 @@ -1971,9 +1982,10 @@ proc_set_cred(struct proc *p, struct ucred *newcred) { 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; diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c index 676bd35..28ca5e1 100644 --- a/sys/kern/sched_4bsd.c +++ b/sys/kern/sched_4bsd.c @@ -1235,7 +1235,7 @@ sched_pickcpu(struct thread *td) mtx_assert(&sched_lock, MA_OWNED); - if (THREAD_CAN_SCHED(td, td->td_lastcpu)) + if (td->td_lastcpu != NOCPU && THREAD_CAN_SCHED(td, td->td_lastcpu)) best = td->td_lastcpu; else best = NOCPU; diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h index b3d6f52..cbc87be 100644 --- a/sys/sys/ucred.h +++ b/sys/sys/ucred.h @@ -106,6 +106,7 @@ struct ucred *crcopysafe(struct proc *p, struct ucred *cr); struct ucred *crdup(struct ucred *cr); void crextend(struct ucred *cr, int n); 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); |