NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/60924: invalid fd handling in linux inotify
>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:
Home |
Main Index |
Thread Index |
Old Index