kthread_add(): do not allow to attach the thread to a dead or dying process

Reported by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2023-09-05 13:54:36 +03:00
parent ba675bb948
commit 9636299233

View file

@ -281,6 +281,10 @@ kthread_add1(void (*func)(void *), void *arg, struct proc *p,
return (ENOMEM);
PROC_LOCK(p);
if (p->p_state == PRS_ZOMBIE || (p->p_flag2 & P2_WEXIT) != 0) {
PROC_UNLOCK(p);
return (ESRCH);
}
oldtd = FIRST_THREAD_IN_PROC(p);
bzero(&newtd->td_startzero,