summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/init_main.c1
-rw-r--r--sys/kern/kern_exit.c10
-rw-r--r--sys/kern/kern_fork.c5
-rw-r--r--sys/kern/subr_trap.c14
4 files changed, 27 insertions, 3 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 5491cef..438f2f9 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -347,6 +347,7 @@ proc0_init(void *dummy __unused)
p->p_ucred->cr_uidinfo = uifind(0);
p->p_ucred->cr_ruidinfo = uifind(0);
p->p_ucred->cr_prison = NULL; /* Don't jail it. */
+ td->td_ucred = crhold(p->p_ucred);
/* Create procsig. */
p->p_procsig = &procsig0;
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 0793503..20a862f 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -388,6 +388,16 @@ exit1(td, rv)
}
/*
+ * Release this thread's reference to the ucred. The actual proc
+ * reference will stay around until the proc is harvested by
+ * wait(). At this point the ucred is immutable (no other threads
+ * from this proc are around that can change it) so we leave the
+ * per-thread ucred pointer intact in case it is needed although
+ * in theory nothing should be using it at this point.
+ */
+ crfree(td->td_ucred);
+
+ /*
* Finally, call machine-dependent code to release the remaining
* resources including address space, the kernel stack and pcb.
* The address space is released by "vmspace_free(p->p_vmspace)"
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 2d1ce60..28f0970 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -472,6 +472,7 @@ again:
*/
PROC_LOCK(p1);
p2->p_ucred = crhold(p1->p_ucred);
+ p2->p_thread.td_ucred = crhold(p2->p_ucred); /* XXXKSE */
if (p2->p_args)
p2->p_args->ar_ref++;
@@ -797,6 +798,10 @@ fork_exit(callout, arg, frame)
kthread_exit(0);
}
PROC_UNLOCK(p);
+ mtx_lock(&Giant);
+ crfree(td->td_ucred);
+ mtx_unlock(&Giant);
+ td->td_ucred = NULL;
mtx_assert(&Giant, MA_NOTOWNED);
}
diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c
index 908e8f1..a899576 100644
--- a/sys/kern/subr_trap.c
+++ b/sys/kern/subr_trap.c
@@ -135,6 +135,7 @@ ast(framep)
#endif
KASSERT(TRAPF_USERMODE(framep), ("ast in kernel mode"));
+ KASSERT(td->td_ucred == NULL, ("leaked ucred"));
#ifdef WITNESS
if (witness_list(td))
panic("Returning to user mode with mutex(s) held");
@@ -161,10 +162,13 @@ ast(framep)
if (flags & KEF_OWEUPC) {
prticks = p->p_stats->p_prof.pr_ticks;
p->p_stats->p_prof.pr_ticks = 0;
- mtx_unlock_spin(&sched_lock);
+ }
+ mtx_unlock_spin(&sched_lock);
+ PROC_LOCK(p);
+ td->td_ucred = crhold(p->p_ucred);
+ PROC_UNLOCK(p);
+ if (flags & KEF_OWEUPC)
addupc_task(ke, p->p_stats->p_prof.pr_addr, prticks);
- } else
- mtx_unlock_spin(&sched_lock);
if (sflag & PS_ALRMPEND) {
PROC_LOCK(p);
psignal(p, SIGVTALRM);
@@ -187,6 +191,10 @@ ast(framep)
}
userret(td, framep, sticks);
+ mtx_lock(&Giant);
+ crfree(td->td_ucred);
+ mtx_unlock(&Giant);
+ td->td_ucred = NULL;
s = critical_enter();
}
mtx_assert(&Giant, MA_NOTOWNED);
OpenPOWER on IntegriCloud