From 12244b4f2bc8fd7d89f24a93a0d301de33e659db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?=
Date: Fri, 23 Oct 2026 15:51:41 +0100
Subject: [PATCH] tail: fix handling of inotify event queue overflow
* src/tail.c (tail_forever_inotify): Fallback to polling upon overlow.
* tests/tail/inotify-overflow.sh: Add a new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.
Discovered by Anthropic's OSS Scanner, as bug ANT-2026-UUNT73BK.
---
NEWS | 6 +++
src/tail.c | 9 ++++
tests/local.mk | 1 +
tests/tail/inotify-overflow.sh | 75 ++++++++++++++++++++++++++++++++++
4 files changed, 91 insertions(+)
create mode 100755 tests/tail/inotify-overflow.sh
diff --git a/NEWS b/NEWS
index cacd907b0..76a809c7f 100644
--- a/NEWS
+++ b/NEWS
@@ -52,6 +52,12 @@ GNU coreutils NEWS -*- outline -*-
it would have failed if the control flag encoding was different.
[This bug was present in "the beginning".]
+ 'tail --follow' no longer ignores an overflow of the inotify event queue,
+ and now reverts to polling in that case. Previously tail could fail
+ to notice new data, or that a file followed by name was replaced,
+ if events arrived faster than tail could process them.
+ [bug introduced in coreutils-7.5]
+
'unexpand' no longer overflows a heap buffer on non-GLIBC platforms,
given whitespace characters whose display width is negative. E.g.,
this edge case can occur with \u0085 (next line) characters on musl.
diff --git a/src/tail.c b/src/tail.c
index 0778c9985..fd42fc34c 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1766,6 +1766,15 @@ tail_forever_inotify (int wd, struct File_spec *f, int n_files,
ev = void_ev;
evbuf_off += sizeof (*ev) + ev->len;
+ /* If the kernel discarded events for any of the watched files
+ or directories, so we can no longer depend on our view of them.
+ Revert to polling now. */
+ if (ev->mask & IN_Q_OVERFLOW)
+ {
+ error (0, 0, _("inotify event queue overflowed"));
+ return;
+ }
+
/* If a directory is deleted, IN_DELETE_SELF is emitted
with ev->name of length 0.
We need to catch it, otherwise it would wait forever,
diff --git a/tests/local.mk b/tests/local.mk
index 7d75b4b5a..bb6d90144 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -207,6 +207,7 @@ all_tests = \
tests/tail/inotify-rotate-resources.sh \
tests/tail/inotify-dir-recreate.sh \
tests/tail/inotify-only-regular.sh \
+ tests/tail/inotify-overflow.sh \
tests/tail/quote-headers.sh \
tests/chmod/no-x.sh \
tests/chgrp/basic.sh \
diff --git a/tests/tail/inotify-overflow.sh b/tests/tail/inotify-overflow.sh
new file mode 100755
index 000000000..c74bfa5e6
--- /dev/null
+++ b/tests/tail/inotify-overflow.sh
@@ -0,0 +1,75 @@
+#!/bin/sh
+# Ensure tail -F copes with the kernel discarding inotify events
+
+# Copyright (C) 2026 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see