NetBSD Problem Report #60924

From www@netbsd.org  Sun Oct 25 07:39:14 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 "YR1" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 1851A1A923B
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 25 Oct 2026 07:39:14 +0000 (UTC)
Message-Id: <20261025073912.6A2671A923C@mollari.NetBSD.org>
Date: Sun, 25 Oct 2026 07:39:12 +0000 (UTC)
From: noreply@noreply.com
Reply-To: noreply@noreply.com
To: gnats-bugs@NetBSD.org
Subject: invalid fd handling in linux inotify
X-Send-Pr-Version: www-1.0
X-From4GNATS: "noreply@noreply.com via gnats" <gnats-admin@NetBSD.org>

>Number:         60924
>Category:       kern
>Synopsis:       invalid fd handling in linux inotify
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 25 07:40:01 +0000 2026
>Originator:     your name
>Release:        netbsd-11
>Organization:
your organization
>Environment:
>Description:
salad of running vs target fds in inotify_filt_event leads to system panic 

inotify_filt_event() at inotify_filt_event+0x3a9
knote() at knote+0x2f
genfs_rename_knote() at genfs_rename_knote+0x199
genfs_sane_rename() at genfs_sane_rename+0x234
tmpfs_sane_rename() at tmpfs_sane_rename+0x3a
genfs_insane_rename() at genfs_insane_rename+0x80
VOP_RENAME() at VOP_RENAME+0x6c
do_sys_renameat.isra.0() at do_sys_renameat.isra.0+0x54d
linux_syscall() at linux_syscall+0x85
>How-To-Repeat:
compile this for linux and run. It should crash the kernel every time.

#include <sys/inotify.h>
#include <sys/wait.h>

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

#define CHECK_VALID(var_name, msg) if (var_name < 0) { perror(msg); return 1; }

int
main(void)
{
	int ifd, wd, tfd;
	pid_t pid;

	tfd = open("/tmp/file_a", O_RDWR | O_CREAT, 0644);
	CHECK_VALID(tfd, "open /tmp/file_a")
	close(tfd);

	tfd = open("/tmp/file_b", O_RDWR | O_CREAT, 0644);
	CHECK_VALID(tfd, "open /tmp/file_b")
	close(tfd);

	pid = fork();
	CHECK_VALID(pid, "fork")

	if (pid == 0) {
		sleep(1);
		int r = rename("/tmp/file_b", "/tmp/file_a");
		CHECK_VALID(r, "rename");
		sleep(1);
		return 0;
	}

	ifd = inotify_init();
	CHECK_VALID(ifd, "inotify_init");

	wd = inotify_add_watch(ifd, "/tmp/file_a",
	    IN_DELETE_SELF | IN_ATTRIB | IN_MOVE_SELF);
	CHECK_VALID(wd, "inotify_add_watch");

	(void)waitpid(pid, NULL, 0);
	/* currently unreachable */
	printf("I survived!\n");
	return 0;
}

>Fix:

NetBSD Home
NetBSD PR Database Search

(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.