Page MenuHomeFreeBSD

kthread: Set *tdptr earlier in kproc_kthread_add()
ClosedPublic

Authored by markj on Wed, Apr 24, 12:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, May 2, 7:37 PM
Unknown Object (File)
Mon, Apr 29, 6:08 PM
Unknown Object (File)
Mon, Apr 29, 11:13 AM
Unknown Object (File)
Fri, Apr 26, 5:52 PM
Unknown Object (File)
Fri, Apr 26, 8:04 AM
Unknown Object (File)
Fri, Apr 26, 8:04 AM
Unknown Object (File)
Fri, Apr 26, 8:04 AM
Unknown Object (File)
Fri, Apr 26, 12:39 AM
Subscribers

Details

Summary

See commit ae77041e0714 ("kthread: Set *newtdp earlier in
kthread_add1()") for details. That commit was incomplete since
g_init()'s first call to kproc_kthread_add() will cause
kproc_kthread_add() to take the *procptr == NULL branch, which avoids
kthread_create().

To ensure that the thread pointer is initialized before the thread
starts running, we have to start the kernel process with RFSTOPPED.
We could perhaps go further and use RFSTOPPED only when tdptr != NULL,
but it's probably better to have consistent behaviour.

Reported by: syzbot+e91e798f3c088215ace6@syzkaller.appspotmail.com

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Wed, Apr 24, 2:03 PM

I don't see any more path where the pointer to the new struct thread won't be initialized before the new thread is started, so I think this completely fixes the initial problem. Moreover, there most probably won't be any noticeable performance impact, since kproc_create() in the end calls fork1() with RFSTOPPED, so the only difference is now that the new process will be released only very slightly later.