]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
ktrace: Fix a race with fork()
authorMark Johnston <markj@FreeBSD.org>
Thu, 27 May 2021 19:49:59 +0000 (15:49 -0400)
committerMark Johnston <markj@FreeBSD.org>
Thu, 27 May 2021 19:52:20 +0000 (15:52 -0400)
commitf3851b235b23d9220ace31bbc89b1fe0a78fc75c
tree86de2297d190bd474f3089c0da81ae7012f5c6cd
parente00bae5c181ac8282caf41cd33a076da03cf8ac9
ktrace: Fix a race with fork()

ktrace(2) may toggle trace points in any of
1. a single process
2. all members of a process group
3. all descendents of the processes in 1 or 2

In the first two cases, we do not permit the operation if the process is
being forked or not visible. However, in case 3 we did not enforce this
restriction for descendents. As a result, the assertions about the child
in ktrprocfork() may be violated.

Move these checks into ktrops() so that they are applied consistently.

Allow KTROP_CLEAR for nascent processes. Otherwise, there is a window
where we cannot clear trace points for a nascent child if they are
inherited from the parent.

Reported by: syzbot+d96676592978f137e05c@syzkaller.appspotmail.com
Reported by: syzbot+7c98fcf84a4439f2817f@syzkaller.appspotmail.com
Reviewed by: kib
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D30481
sys/kern/kern_ktrace.c