linux/fs/notify
Kyle Zeng 36ebddca56
fsnotify: prevent mark additions during connector teardown
fsnotify_destroy_marks() keeps a reference to its current mark while it
drops conn->lock to destroy the mark. This stabilizes the forward-walk
cursor, but does not prevent a new mark from being inserted before it.
For example, an inotify watch re-added after IN_IGNORED sorts before the
old, detached mark for the same group. The walk can miss the replacement
and then detach the entire connector from the object.

The replacement is still on its group's marks_list and, for inotify, in
the watch IDR. The group mutex no longer protects the connector's object
from disappearing. An unprivileged fdinfo read racing the final detach
can consequently call igrab(NULL):

  BUG: KASAN: null-ptr-deref in igrab+0x24/0x100
  Write of size 4 at addr 0000000000000148
  Call Trace:
   igrab+0x24/0x100
   inotify_show_fdinfo+0x1dc/0x5e0
   seq_show+0x397/0x690

Set a DESTROYING flag under conn->lock before starting the walk, and
reject new marks on that connector with -ENOENT. The existing add-mark
error paths undo the temporary group-list entry and the backend's watch
allocation. Do not wait for teardown while holding the group mutex,
which the destroyer needs. Once the old connector is detached, an add
can install a fresh connector as before.

This closes the insertion race for all object types using the common
connector teardown, without changing the mark reference or SRCU lifetime
rules.

Fixes: 6b3f05d24d ("fsnotify: Detach mark from object list when last reference is dropped")
Cc: stable@vger.kernel.org
Signed-off-by: Kyle Zeng <kylebot@openai.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-10-14 22:08:05 +02:00
..
dnotify fix a leak in fcntl_dirnotify() 2025-07-14 10:13:31 +02:00
fanotify fsnotify: Fix stale object mask after concurrent mark updates 2026-08-05 11:50:45 +02:00
inotify fsnotify: Fix stale object mask after concurrent mark updates 2026-08-05 11:50:45 +02:00
fdinfo.c treewide: change inode->i_ino from unsigned long to u64 2026-03-06 14:31:28 +01:00
fdinfo.h
fsnotify.c vfs-7.2-rc1.directory.delegations 2026-06-15 02:50:44 +05:30
fsnotify.h fsnotify: Use connector list for destroying inode marks 2026-01-23 13:26:37 +01:00
group.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
Kconfig fs/notify: Remove "select SRCU" 2023-02-02 16:26:06 -08:00
Makefile
mark.c fsnotify: prevent mark additions during connector teardown 2026-10-14 22:08:05 +02:00
notification.c fsnotify: Pass group argument to free_event 2021-10-27 12:34:18 +02:00