NetBSD Problem Report #60358
From www@netbsd.org Tue Jun 23 17:34:06 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.netbsd.org", Issuer "R13" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 88E581A923A
for <gnats-bugs@gnats.NetBSD.org>; Tue, 23 Jun 2026 17:34:06 +0000 (UTC)
Message-Id: <20260623173405.4165E1A923B@mollari.NetBSD.org>
Date: Tue, 23 Jun 2026 17:34:05 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: kevent EVFILT_PROC races with process exit
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>
>Number: 60358
>Category: kern
>Synopsis: kevent EVFILT_PROC races with process exit
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: thorpej
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jun 23 17:35:00 +0000 2026
>Last-Modified: Tue Jun 23 18:00:02 +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.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: kern-bug-people->thorpej
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Tue, 23 Jun 2026 17:38:15 +0000
Responsible-Changed-Why:
You made the latest change to kern_event.c replacing proc_find_raw
(which can return zombies) by proc_find, can you take a look?
https://mail-index.netbsd.org/source-changes/2021/10/10/msg132905.html
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/60358 CVS commit: src/usr.bin
Date: Tue, 23 Jun 2026 17:57:14 +0000
Module Name: src
Committed By: riastradh
Date: Tue Jun 23 17:57:14 UTC 2026
Modified Files:
src/usr.bin/diff: pr.c pr.h
src/usr.bin/diff3: diff3.c
Log Message:
diff3(1): Just use waitpid(2), no need for kevent(2).
Sidesteps
PR kern/60358: kevent EVFILT_PROC races with process exit
in order to fix
PR bin/60357: diff3(1): tests are failing since BSD diff import
The FreeBSD version used kevent(2) until February of this year:
https://cgit.freebsd.org/src/commit/?id=404753664a5e145d98f1749d1c7bc046c8aa32c3
So this reduces diff from FreeBSD somewhat, except FreeBSD uses
capsicum and process fds rather than pids.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/diff/pr.c src/usr.bin/diff/pr.h
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/diff3/diff3.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.