Skip to content

fanotify: FAN_REPORT_MNT and the mount events of a mount namespace - #706

Merged
tamnd merged 1 commit into
mainfrom
fan-1
Nov 12, 2026
Merged

tamnd merged 1 commit into
mainfrom
fan-1

Conversation

@tamnd

@tamnd tamnd commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Part of #539: fanotify with pidfds and mount events. FAN_REPORT_PIDFD and FAN_REPORT_TID came in #643. This PR adds FAN_REPORT_MNT, as fs/notify/fanotify of Linux 7.3.

What changes

  • fanotify_init accepts FAN_REPORT_MNT. It gives EINVAL when the class is not FAN_CLASS_NOTIF, and when the flags also have a FID flag or FAN_REPORT_FD_ERROR. An unprivileged user can make such a group, as in Linux.
  • fanotify_mark accepts FAN_MARK_MNTNS. A group with FAN_REPORT_MNT marks only mount namespaces, with only FAN_MNT_ATTACH and FAN_MNT_DETACH. The other groups get EINVAL for these events and for this mark type. The path must be a mount namespace file of nsfs, such as /proc/self/ns/mnt, else the result is EINVAL. The mark needs CAP_SYS_ADMIN in the user namespace of the group and in the user namespace that owns the mount namespace, else the result is EPERM.
  • The mount namespace sends the events as mnt_notify of Linux: FAN_MNT_ATTACH when a mount is attached, FAN_MNT_DETACH on unmount, and both bits in one event on a move. For MOVE_MOUNT_BENEATH only the moved mount has an event. For pivot_root the old root moves first, then the new root.
  • A mount event does not merge with other events. Its fd is FAN_NOFD. After the pidfd record it has a 16 byte FAN_EVENT_INFO_TYPE_MNT record (type 7, len 16, 4 bytes of padding, then the unique mount ID of statx STATX_MNT_ID_UNIQUE).
  • The marks go away when the mount namespace goes away, as fsnotify_mntns_delete.
  • fdinfo of the group shows fanotify mnt_ns:INO mflags:X mask:X ignored_mask:X.

Tests

LTP 20260930 has no test for FAN_REPORT_MNT, so the init boot test has a new check (only fanotify). It checks the EINVAL cases of fanotify_init and fanotify_mark, the fdinfo line, the event of a tmpfs mount with the ID from statx, the event of MS_MOVE, the event of umount, and EAGAIN after the events. It also checks that a user without privilege gets EPERM on the mount namespace of the initial user namespace, and can mark the mount namespace of its own user namespace.

  • Unit tests of rk-vfs and rk-syscall: pass (one new test for the layout of the mount record).
  • init boot test with only fanotify: x86_64 pass (17 checks), arm64 pass (17 checks). Load average 18.9 to 22.3 on server2.
  • LTP fanotify18, fanotify19, fanotify20, fanotify21 with tools/ltp/run.py on server2:
    • x86_64: fanotify18 pass, fanotify19 pass, fanotify20 TCONF ("FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2", the same as Linux 7.3 and the reference in tools/ltp/syscalls.md). fanotify21 had a timeout at the default limit of 240 s at load 18.5 to 21 (14 TPASS and no TFAIL before the ext2 run). Run again with a limit of 1200 s: pass in 234 s, load 15.0 to 17.5.
    • arm64: fanotify18 pass, fanotify19 pass, fanotify20 TCONF (as above), fanotify21 pass. Load 18.5 to 19.0.
  • rustfmt --check: pass.

The full gate did not run.

@tamnd tamnd added kind/feature New behavior or a new part. area/fs The disk file systems: ext4, XFS, Btrfs and others. labels Nov 12, 2026
@tamnd
tamnd merged commit b86b867 into main Nov 12, 2026
6 of 7 checks passed
@tamnd
tamnd deleted the fan-1 branch November 12, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/fs The disk file systems: ext4, XFS, Btrfs and others. kind/feature New behavior or a new part.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant