[PATCH] inotify: do not coalesce events with different rename cookies
From: Hungyu Lin
Date: Sun Oct 25 2026 - 19:23:24 EST
inotify compares the mask, watch descriptor and name when coalescing
adjacent unread events, but ignores their rename cookies. Distinct
renames can therefore lose an event even with IN_ALL_EVENTS.
For example, prepare two files in an unwatched staging directory and
rename each onto the same pathname in a watched destination directory
before reading the events. Only the first IN_MOVED_TO event is retained,
although the two renames have different cookies. Similarly, coalescing
distinct IN_MOVED_FROM events can discard the cookie needed to match a
subsequent IN_MOVED_TO event.
The original inotify implementation compared cookies before coalescing.
The fsnotify conversion lost this comparison. Compare sync_cookie as well
to preserve distinct rename events, while retaining coalescing for
ordinary events with zero cookies.
Fixes: 63c882a05416 ("inotify: reimplement inotify using fsnotify")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
fs/notify/inotify/inotify_fsnotify.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index 7c326ec2e8a8..6456d9c0e408 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -40,6 +40,7 @@ static bool event_compare(struct fsnotify_event *old_fsn,
return false;
if ((old->mask == new->mask) &&
(old->wd == new->wd) &&
+ (old->sync_cookie == new->sync_cookie) &&
(old->name_len == new->name_len) &&
(!old->name_len || !strcmp(old->name, new->name)))
return true;
--
2.43.0