Date: Tue, 20 Aug 2013 19:13:14 +0000 (UTC) From: Bryan Venteicher <bryanv@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r254578 - stable/9/sys/kern Message-ID: <201308201913.r7KJDENI066628@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bryanv Date: Tue Aug 20 19:13:13 2013 New Revision: 254578 URL: http://svnweb.freebsd.org/changeset/base/254578 Log: MFC r254457 Do not use potentially stale thread in kthread_add() When an existing process is provided, the thread selected to use to initialize the new thread could have exited and be reaped. Acquire the proc lock earlier to ensure the thread remains valid. Modified: stable/9/sys/kern/kern_kthread.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/kern_kthread.c ============================================================================== --- stable/9/sys/kern/kern_kthread.c Tue Aug 20 18:22:04 2013 (r254577) +++ stable/9/sys/kern/kern_kthread.c Tue Aug 20 19:13:13 2013 (r254578) @@ -257,18 +257,17 @@ kthread_add(void (*func)(void *), void * panic("kthread_add called too soon"); /* If no process supplied, put it on proc0 */ - if (p == NULL) { + if (p == NULL) p = &proc0; - oldtd = &thread0; - } else { - oldtd = FIRST_THREAD_IN_PROC(p); - } /* Initialize our new td */ newtd = thread_alloc(pages); if (newtd == NULL) return (ENOMEM); + PROC_LOCK(p); + oldtd = FIRST_THREAD_IN_PROC(p); + bzero(&newtd->td_startzero, __rangeof(struct thread, td_startzero, td_endzero)); /* XXX check if we should zero. */ @@ -293,7 +292,6 @@ kthread_add(void (*func)(void *), void * newtd->td_ucred = crhold(p->p_ucred); /* this code almost the same as create_thread() in kern_thr.c */ - PROC_LOCK(p); p->p_flag |= P_HADTHREADS; newtd->td_sigmask = oldtd->td_sigmask; /* XXX dubious */ thread_link(newtd, p);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308201913.r7KJDENI066628>