NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/60358: kevent EVFILT_PROC races with process exit



>Number:         60358
>Category:       kern
>Synopsis:       kevent EVFILT_PROC races with process exit
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 23 17:35:00 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current, 11/10/9/...(?)
>Organization:
The WaitBSD Foundevent, Inc.
>Environment:
>Description:

	kevent EVFILT_PROC (with NOTE_EXIT) fails if the process has
	already exited, even if it is guaranteed to exist and to be
	usable with wait() because it is a zombie child of the current
	process.

	This is the root cause of mysterious diff3(1) test failures:

	https://gnats.NetBSD.org/60357
	bin/60357: diff3(1): tests are failing since BSD diff import

>How-To-Repeat:
#include <sys/event.h>
#include <sys/wait.h>

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main(void)
{
	struct kevent ev;
	int kq;
	pid_t child;
	int nev;

	if ((kq = kqueue()) == -1)
		err(EXIT_FAILURE, "kqueue");

	if ((child = fork()) == -1)
		err(EXIT_FAILURE, "fork");
	if (child == 0)
		_exit(1);
	sleep(1);
	EV_SET(&ev, child, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
	if (kevent(kq, &ev, 1, NULL, 0, NULL) == -1)
		err(EXIT_FAILURE, "kevent add");
	nev = kevent(kq, NULL, 0, &ev, 1, NULL);
	if (nev == -1)
		err(EXIT_FAILURE, "kevent wait");
	if (nev == 0)
		errx(EXIT_FAILURE, "kevent failed to wait");
}

>Fix:

	Allow EVFILT_PROC to be registered on zombie children of the
	current process, in which case NOTE_EXIT should fire
	immediately.




Home | Main Index | Thread Index | Old Index