]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/commit
MFC 295418,295419:
authorjhb <jhb@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 17 Feb 2016 01:45:34 +0000 (01:45 +0000)
committerjhb <jhb@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 17 Feb 2016 01:45:34 +0000 (01:45 +0000)
commit9561cbad80d3084f178f87b955c8deb19d694ceb
treedef40838de7cca3646bf498c5c445f731dcfaaff
parenta18da6401fd8f2bbafdc7a719184ecf6aae70e6d
MFC 295418,295419:
Fix hangs or panics when misbehaved kernel threads return from their
main function.

295418:
Mark proc0 as a kernel process via the P_KTHREAD flag.

All other kernel processes have this flag set and all threads in proc0
(including thread0) have the similar TDP_KTHREAD flag set.

295419:
Call kthread_exit() rather than kproc_exit() for a premature kthread exit.

Kernel threads (and processes) are supposed to call kthread_exit() (or
kproc_exit()) to terminate.  However, the kernel includes a fallback in
fork_exit() to force a kthread exit if a kernel thread's "main" routine
returns.  This fallback was added back when the kernel only had processes
and was not updated to call kthread_exit() instead of kproc_exit() when
threads were added to the kernel.

This mistake was particularly exciting when the errant thread belonged to
proc0.  Due to the missing P_KTHREAD flag the fallback did not kick in
and instead tried to return to userland via whatever garbage was in the
trapframe.  With P_KTHREAD set it tried to terminate proc0 resulting in
other amusements.

PR: 204999

git-svn-id: svn://svn.freebsd.org/base/stable/8@295684 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
sys/kern/init_main.c
sys/kern/kern_fork.c