diff options
author | bdrewery <bdrewery@FreeBSD.org> | 2016-08-08 18:10:59 +0000 |
---|---|---|
committer | bdrewery <bdrewery@FreeBSD.org> | 2016-08-08 18:10:59 +0000 |
commit | 367e6d5ac9d44619a8c1cfe96d3e87f7bd2cf26e (patch) | |
tree | 07575c68a9d5c96b9356e16602c78ca490484e4c | |
parent | 89512a096a7717f8c3f2ca6889e0c6b1a1d50b32 (diff) | |
download | FreeBSD-src-367e6d5ac9d44619a8c1cfe96d3e87f7bd2cf26e.zip FreeBSD-src-367e6d5ac9d44619a8c1cfe96d3e87f7bd2cf26e.tar.gz |
MFC r280330,r282567:
r280330:
fork: assign refed credentials earlier
r282567:
Fix up panics when fork fails due to hitting proc limit
PR: D7431
-rw-r--r-- | sys/kern/kern_fork.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index a5595c9..6173a89 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(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); |