| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/03 03:34 | flow | patch-triage |
2mArgs:null Results: {
"EnableConfigs": [
"DEBUG_VFS",
"FHANDLE",
"FSNOTIFY",
"USER_NS"
],
"FocusSymbols": [
"fcntl_set_rw_hint",
"subtree_unobstructed",
"handle_to_path",
"step_into_slowpath",
"unlink_may_reveal",
"__detach_mounts",
"has_locked_children",
"attach_recursive_mnt",
"mark_mounts_for_expiry",
"shrink_submount",
"nullfs_dir_readdir",
"nullfs_nolock",
"fsnotify_add_mark_locked",
"fsnotify_add_mark_list"
],
"KMSANReasoning": "The patch series modifies VFS mount handling, mount propagation locking (MNT_LOCKED), directory iteration locking for immutable filesystems (FOP_IMMUTABLE in nullfs and iterate_dir), fcntl rw-hint checks for immutable inodes, path lookup unlinked-dentry checks (unlink_may_reveal), and fsnotify mark restrictions (FS_DISALLOW_NOTIFY), along with corresponding selftests.\n\nNone of the changes introduce or modify kernel-to-user copy paths with uninitialized padding/fields, nor do they introduce allocations of uninitialized memory, branch on uninitialized variables, or alter buffer bounds. Potential risks introduced by these changes primarily concern reference counting (dentry/mount ref handling), concurrency, locking (inode rwsem, mount_lock), and access control/logic bugs. These categories are caught by standard KASAN, LOCKDEP, and functional fuzzing/testing. Spawning a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch series modifies core VFS logic across mount namespace locking and propagation (attach_recursive_mnt, has_locked_children), mount detach and expiry handling (__detach_mounts, shrink_submount, and adding a VFS_WARN_ON_ONCE assertion in mark_mounts_for_expiry), refwalk lookup revealing unlinked dentries (unlink_may_reveal in step_into_slowpath), lockless readdir execution for immutable filesystems (iterate_dir with FOP_IMMUTABLE), nullfs directory and file operations, file handle subtree decode checks (subtree_unobstructed in fhandle), fcntl rw_hint checks on immutable inodes, and fsnotify mark validation. All modified paths are reachable via standard system calls and virtualized environments, making this change an ideal candidate for fuzzing.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/03 03:34 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit f2c7e28a87ef20978c41877ec1ef9d1356a8d6a0\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sat Oct 3 03:34:56 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/fs/fcntl.c b/fs/fcntl.c\nindex c158f082f1da4..9b71bc9d71d15 100644\n--- a/fs/fcntl.c\n+++ b/fs/fcntl.c\n@@ -372,6 +372,9 @@ static long fcntl_set_rw_hint(struct file *file, unsigned long arg)\n \tu64 __user *argp = (u64 __user *)arg;\n \tu64 hint;\n \n+\t/* nothing is ever written to it */\n+\tif (IS_IMMUTABLE(inode))\n+\t\treturn -EPERM;\n \tif (!inode_owner_or_capable(file_mnt_idmap(file), inode))\n \t\treturn -EPERM;\n \ndiff --git a/fs/fhandle.c b/fs/fhandle.c\nindex f8829231e3d75..d22f2e065677a 100644\n--- a/fs/fhandle.c\n+++ b/fs/fhandle.c\n@@ -298,6 +298,22 @@ static bool capable_wrt_mount(struct mount *mount)\n \treturn mnt_ns \u0026\u0026 ns_capable(mnt_ns-\u003euser_ns, CAP_SYS_ADMIN);\n }\n \n+/*\n+ * Does the caller have an unobstructed way to everything below @root? Only\n+ * if the mount is mounted, the caller is privileged over its mount namespace\n+ * and no locked child covers something below @root-\u003edentry. One answer from\n+ * under mount_lock: an umount in between clears -\u003emnt_ns and takes the\n+ * children off the mount, the locked ones too.\n+ */\n+static bool subtree_unobstructed(const struct path *root)\n+{\n+\tstruct mount *mnt = real_mount(root-\u003emnt);\n+\n+\tguard(mount_locked_reader)();\n+\treturn is_mounted(root-\u003emnt) \u0026\u0026 capable_wrt_mount(mnt) \u0026\u0026\n+\t !has_locked_children(mnt, root-\u003edentry);\n+}\n+\n static inline int may_decode_fh(struct handle_to_path_ctx *ctx,\n \t\t\t\tunsigned int o_flags)\n {\n@@ -332,9 +348,7 @@ static inline int may_decode_fh(struct handle_to_path_ctx *ctx,\n \n \tif (ns_capable(root-\u003emnt-\u003emnt_sb-\u003es_user_ns, CAP_SYS_ADMIN))\n \t\tctx-\u003eflags = HANDLE_CHECK_PERMS;\n-\telse if (is_mounted(root-\u003emnt) \u0026\u0026\n-\t\t capable_wrt_mount(real_mount(root-\u003emnt)) \u0026\u0026\n-\t\t !has_locked_children(real_mount(root-\u003emnt), root-\u003edentry))\n+\telse if (subtree_unobstructed(root))\n \t\tctx-\u003eflags = HANDLE_CHECK_PERMS | HANDLE_CHECK_SUBTREE;\n \telse\n \t\treturn -EPERM;\ndiff --git a/fs/mount.h b/fs/mount.h\nindex 2223fb141499f..4e68e5cbc2549 100644\n--- a/fs/mount.h\n+++ b/fs/mount.h\n@@ -6,6 +6,7 @@\n #include \u003clinux/fs_pin.h\u003e\n \n extern struct file_system_type nullfs_fs_type;\n+extern struct vfsmount *knullfs;\n extern struct list_head notify_list;\n \n struct mnt_namespace {\ndiff --git a/fs/namei.c b/fs/namei.c\nindex 20a6534ea3eff..c87c14ee1a252 100644\n--- a/fs/namei.c\n+++ b/fs/namei.c\n@@ -2086,6 +2086,33 @@ static noinline const char *pick_link(struct nameidata *nd, struct path *link,\n \treturn NULL;\n }\n \n+/*\n+ * Be careful in case the dentry is unlinked or renamed. Any mounts\n+ * stacked on top of it are going away. We need to make sure that we\n+ * don't reveal the underyling dentry during refwalk. In rcuwalk we\n+ * catch this via d_seq and another lookup for the name. Give the same\n+ * guarantee in refwalk.\n+ */\n+static bool unlink_may_reveal(struct nameidata *nd, int flags,\n+\t\t\t struct path *path, struct dentry *dentry)\n+{\n+\t/* \"..\" and LOOKUP_DOWN may land on an unhashed directory */\n+\tif (flags \u0026 WALK_NOFOLLOW)\n+\t\treturn false;\n+\tif (nd-\u003eflags \u0026 LOOKUP_REVAL)\n+\t\treturn false;\n+\t/* We crossed onto a mount and the name led us here while it still existed */\n+\tif (path-\u003emnt != nd-\u003epath.mnt)\n+\t\treturn false;\n+\t/* only a name on its way out is flagged */\n+\tif (likely(!cant_mount(dentry)))\n+\t\treturn false;\n+\tif (!d_unlinked(dentry))\n+\t\treturn false;\n+\tdput(no_free_ptr(path-\u003edentry));\n+\treturn true;\n+}\n+\n /*\n * Do we need to follow links? We _really_ want to be able\n * to do this check without having to look at inode-\u003ei_op,\n@@ -2115,6 +2142,8 @@ static noinline const char *step_into_slowpath(struct nameidata *nd, int flags,\n \t\t\tif (unlikely(!inode))\n \t\t\t\treturn ERR_PTR(-ENOENT);\n \t\t} else {\n+\t\t\tif (unlikely(unlink_may_reveal(nd, flags, \u0026path, dentry)))\n+\t\t\t\treturn ERR_PTR(-ESTALE);\n \t\t\tdput(nd-\u003epath.dentry);\n \t\t\tif (nd-\u003epath.mnt != path.mnt)\n \t\t\t\tmntput(nd-\u003epath.mnt);\ndiff --git a/fs/namespace.c b/fs/namespace.c\nindex fcf42f192aae9..e1b0ade95b0d8 100644\n--- a/fs/namespace.c\n+++ b/fs/namespace.c\n@@ -80,6 +80,7 @@ static u64 mnt_id_ctr = MNT_UNIQUE_ID_OFFSET;\n static struct hlist_head *mount_hashtable __ro_after_init;\n static struct hlist_head *mountpoint_hashtable __ro_after_init;\n static struct kmem_cache *mnt_cache __ro_after_init;\n+struct vfsmount *knullfs __ro_after_init;\t/* private nullfs instance */\n static DECLARE_RWSEM(namespace_sem);\n static HLIST_HEAD(unmounted);\t/* protected by namespace_sem */\n static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */\n@@ -1996,6 +1997,9 @@ static int do_umount(struct mount *mnt, int flags)\n * detach_mounts allows lazily unmounting those mounts instead of\n * leaking them.\n *\n+ * The dentry is unhashed before the mounts go so that no lookup finds\n+ * what they covered. The caller removes it for good afterwards.\n+ *\n * The caller may hold dentry-\u003ed_inode-\u003ei_rwsem.\n */\n void __detach_mounts(struct dentry *dentry)\n@@ -2009,6 +2013,8 @@ void __detach_mounts(struct dentry *dentry)\n \tif (!lookup_mountpoint(dentry, \u0026mp))\n \t\treturn;\n \n+\t/* the name goes first, what covered it goes second */\n+\td_drop(dentry);\n \tevent++;\n \twhile (mp.node.next) {\n \t\tmnt = hlist_entry(mp.node.next, struct mount, mnt_mp_list);\n@@ -2348,7 +2354,7 @@ void dissolve_on_fput(struct vfsmount *mnt)\n }\n \n /* locks: namespace_shared \u0026\u0026 pinned(mnt) || mount_locked_reader */\n-static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)\n+bool has_locked_children(struct mount *mnt, struct dentry *dentry)\n {\n \tstruct mount *child;\n \n@@ -2362,12 +2368,6 @@ static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)\n \treturn false;\n }\n \n-bool has_locked_children(struct mount *mnt, struct dentry *dentry)\n-{\n-\tguard(mount_locked_reader)();\n-\treturn __has_locked_children(mnt, dentry);\n-}\n-\n /* locks: namespace_shared \u0026\u0026 pinned(mnt) || mount_locked_reader */\n static bool __has_children(struct mount *mnt, struct dentry *dentry)\n {\n@@ -2436,7 +2436,7 @@ struct vfsmount *clone_private_mount(const struct path *path)\n \tif (!ns_capable(old_mnt-\u003emnt_ns-\u003euser_ns, CAP_SYS_ADMIN))\n \t\treturn ERR_PTR(-EPERM);\n \n-\tif (__has_locked_children(old_mnt, path-\u003edentry))\n+\tif (has_locked_children(old_mnt, path-\u003edentry))\n \t\treturn ERR_PTR(-EINVAL);\n \n \tnew_mnt = clone_mnt(old_mnt, path-\u003edentry, CL_PRIVATE);\n@@ -2599,11 +2599,11 @@ enum mnt_tree_flags_t {\n static int attach_recursive_mnt(struct mount *source_mnt,\n \t\t\t\tconst struct pinned_mountpoint *dest)\n {\n-\tstruct user_namespace *user_ns = current-\u003ensproxy-\u003emnt_ns-\u003euser_ns;\n \tstruct mount *dest_mnt = dest-\u003eparent;\n \tstruct mountpoint *dest_mp = dest-\u003emp;\n \tHLIST_HEAD(tree_list);\n \tstruct mnt_namespace *ns = dest_mnt-\u003emnt_ns;\n+\tstruct user_namespace *user_ns = ns-\u003euser_ns;\n \tstruct pinned_mountpoint root = {};\n \tstruct mountpoint *shorter = NULL;\n \tstruct mount *child, *p;\n@@ -2612,6 +2612,22 @@ static int attach_recursive_mnt(struct mount *source_mnt,\n \tint err = 0;\n \tbool moving = mnt_has_parent(source_mnt);\n \n+\t/*\n+\t * A caller in an unprivileged mount namespaces may trigger an\n+\t * automount and propagate locked mounts into privileged mount\n+\t * namespaces. Take ownership from the target mount namespace.\n+\t * It's equivalent for everything but the automount case.\n+\t *\n+\t * Detached trees in anonymous mount namespaces by be handed\n+\t * over via SCM_RIGHTS or inherited in other ways on purpose\n+\t * the attaching task's mount namespace is authoritative, not\n+\t * the creator of the detached tree.\n+\t */\n+\tif (is_anon_ns(ns))\n+\t\tuser_ns = current-\u003ensproxy-\u003emnt_ns-\u003euser_ns;\n+\telse\n+\t\tuser_ns = ns-\u003euser_ns;\n+\n \t/*\n \t * Preallocate a mountpoint in case the new mounts need to be\n \t * mounted beneath mounts on the same mountpoint.\n@@ -2691,15 +2707,17 @@ static int attach_recursive_mnt(struct mount *source_mnt,\n \t\t\t/*\n \t\t\t * If @q was locked it was meant to hide\n \t\t\t * whatever was under it. Let @child take over\n-\t\t\t * that job and lock it, then we can unlock @q.\n-\t\t\t * That'll allow another namespace to shed @q\n-\t\t\t * and reveal @child. Clearly, that mounter\n-\t\t\t * consented to this by not severing the mount\n-\t\t\t * relationship. Otherwise, what's the point.\n+\t\t\t * that job and lock it. If @child is the mount\n+\t\t\t * the caller placed we can then unlock @q:\n+\t\t\t * nothing another namespace does removes it\n+\t\t\t * again. A propagated copy goes away when the\n+\t\t\t * mounter of the original unmounts it, so @q\n+\t\t\t * keeps its lock.\n \t\t\t */\n \t\t\tif (IS_MNT_LOCKED(q)) {\n \t\t\t\tchild-\u003emnt.mnt_flags |= MNT_LOCKED;\n-\t\t\t\tq-\u003emnt.mnt_flags \u0026= ~MNT_LOCKED;\n+\t\t\t\tif (child == source_mnt)\n+\t\t\t\t\tq-\u003emnt.mnt_flags \u0026= ~MNT_LOCKED;\n \t\t\t}\n \t\t\tmnt_change_mountpoint(r, mp, q);\n \t\t}\n@@ -2796,6 +2814,11 @@ static void do_lock_mount(const struct path *path,\n \n \t\tscoped_guard(mount_locked_reader) {\n \t\t\tm = where_to_mount(path, \u0026dentry, beneath);\n+\t\t\t/* sticky, so it takes no locks to refuse it */\n+\t\t\tif (unlikely(cant_mount(dentry))) {\n+\t\t\t\tres-\u003eparent = ERR_PTR(-ENOENT);\n+\t\t\t\treturn;\n+\t\t\t}\n \t\t\tif (\u0026m-\u003emnt != path-\u003emnt) {\n \t\t\t\tmntget(\u0026m-\u003emnt);\n \t\t\t\tdget(dentry);\n@@ -3033,7 +3056,7 @@ static struct mount *__do_loopback(const struct path *old_path,\n \tif (recurse \u0026\u0026 !old-\u003emnt_ns)\n \t\treturn ERR_PTR(-EINVAL);\n \n-\tif (!recurse \u0026\u0026 __has_locked_children(old, old_path-\u003edentry))\n+\tif (!recurse \u0026\u0026 has_locked_children(old, old_path-\u003edentry))\n \t\treturn ERR_PTR(-EINVAL);\n \n \tif (recurse)\n@@ -3521,7 +3544,7 @@ static int do_set_group(const struct path *from_path, const struct path *to_path\n \t\treturn -EINVAL;\n \n \t/* From mount should not have locked children in place of To's root */\n-\tif (__has_locked_children(from, to-\u003emnt.mnt_root))\n+\tif (has_locked_children(from, to-\u003emnt.mnt_root))\n \t\treturn -EINVAL;\n \n \t/* Setting sharing groups is only allowed on private mounts */\n@@ -3801,7 +3824,7 @@ static int do_add_mount(struct mount *newmnt, const struct pinned_mountpoint *mp\n \t\tif (!(mnt_flags \u0026 MNT_SHRINKABLE))\n \t\t\treturn -EINVAL;\n \t\t/* ... and for those we'd better have mountpoint still alive */\n-\t\tif (!parent-\u003emnt_ns)\n+\t\tif (!is_mounted(\u0026parent-\u003emnt))\n \t\t\treturn -EINVAL;\n \t}\n \n@@ -4011,6 +4034,8 @@ void mark_mounts_for_expiry(struct list_head *mounts)\n \tlist_for_each_entry_safe(mnt, next, mounts, mnt_expire) {\n \t\tif (!is_mounted(\u0026mnt-\u003emnt))\n \t\t\tcontinue;\n+\t\t/* lock_mnt_tree() leaves expirable mounts alone */\n+\t\tVFS_WARN_ON_ONCE(IS_MNT_LOCKED(mnt));\n \t\tif (!xchg(\u0026mnt-\u003emnt_expiry_mark, 1) ||\n \t\t\tpropagate_mount_busy(mnt, 1))\n \t\t\tcontinue;\n@@ -4037,7 +4062,8 @@ EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);\n */\n static bool shrink_submount(struct mount *mnt)\n {\n-\tif (propagate_mount_busy(mnt, 1))\n+\t/* not the kernel's to remove either */\n+\tif (IS_MNT_LOCKED(mnt) || propagate_mount_busy(mnt, 1))\n \t\treturn false;\n \ttouch_mnt_namespace(mnt-\u003emnt_ns);\n \tumount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);\n@@ -6315,7 +6341,7 @@ static void __init init_mount_tree(void)\n \t *\n \t * (1) nullfs with mount id 1\n \t * (2) mutable rootfs with mount id 2\n-\t * (3) private nullfs for kthreads (SB_KERNMOUNT)\n+\t * (3) private nullfs for kthreads (SB_KERNMOUNT), kept in knullfs\n \t *\n \t * with (2) mounted on top of (1). The init_task's root and pwd\n \t * are pointed at (3) so all kthreads start isolated in nullfs.\n@@ -6350,11 +6376,15 @@ static void __init init_mount_tree(void)\n \t\tinit_mnt_ns.nr_mounts++;\n \t}\n \n-\tnullfs_mnt = kern_mount(\u0026nullfs_fs_type);\n-\tif (IS_ERR(nullfs_mnt))\n+\tknullfs = kern_mount(\u0026nullfs_fs_type);\n+\tif (IS_ERR(knullfs))\n \t\tpanic(\"VFS: Failed to create private nullfs instance\");\n-\troot.mnt\t= nullfs_mnt;\n-\troot.dentry\t= nullfs_mnt-\u003emnt_root;\n+\t/* nothing is ever mounted on the root of a kernel thread */\n+\tdont_mount(knullfs-\u003emnt_root);\n+\t/* and nothing is ever written through it */\n+\tknullfs-\u003emnt_flags |= MNT_READONLY;\n+\troot.mnt\t= knullfs;\n+\troot.dentry\t= knullfs-\u003emnt_root;\n \n \tinit_task.nsproxy-\u003emnt_ns = \u0026init_mnt_ns;\n \tget_mnt_ns(\u0026init_mnt_ns);\ndiff --git a/fs/notify/mark.c b/fs/notify/mark.c\nindex b2640d836a712..d17628580a570 100644\n--- a/fs/notify/mark.c\n+++ b/fs/notify/mark.c\n@@ -903,6 +903,10 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, void *obj,\n \tif (WARN_ON(!fsnotify_valid_obj_type(obj_type)))\n \t\treturn -EINVAL;\n \n+\t/* the filesystem doesn't want its objects watched */\n+\tif (sb \u0026\u0026 (sb-\u003es_type-\u003efs_flags \u0026 FS_DISALLOW_NOTIFY))\n+\t\treturn -EINVAL;\n+\n \t/*\n \t * Attach the sb info before attaching a connector to any object on sb.\n \t * The sb info will remain attached as long as sb lives.\ndiff --git a/fs/nullfs.c b/fs/nullfs.c\nindex e06352c7b2ccf..bfc04bca39407 100644\n--- a/fs/nullfs.c\n+++ b/fs/nullfs.c\n@@ -10,6 +10,43 @@ static const struct super_operations nullfs_super_operations = {\n \t.statfs\t= simple_statfs,\n };\n \n+static loff_t nullfs_dir_llseek(struct file *file, loff_t offset, int whence)\n+{\n+\t/* an empty directory has two entries . and .. at offsets 0 and 1 */\n+\treturn generic_file_llseek_size(file, offset, whence, 2, 2);\n+}\n+\n+static int nullfs_dir_readdir(struct file *file, struct dir_context *ctx)\n+{\n+\tdir_emit_dots(file, ctx);\n+\treturn 0;\n+}\n+\n+/* the one inode of nullfs is shared by every holder, so no locks on it */\n+static int nullfs_nolock(struct file *file, int cmd, struct file_lock *fl)\n+{\n+\treturn -ENOLCK;\n+}\n+\n+/* and no leases or delegations */\n+static int nullfs_nolease(struct file *file, int arg, struct file_lease **flp,\n+\t\t\t void **priv)\n+{\n+\treturn -EINVAL;\n+}\n+\n+/* what libfs gives an empty directory, plus the refusal of file locks */\n+static const struct file_operations nullfs_dir_operations = {\n+\t.llseek\t\t= nullfs_dir_llseek,\n+\t.read\t\t= generic_read_dir,\n+\t.iterate_shared\t= nullfs_dir_readdir,\n+\t.fsync\t\t= noop_fsync,\n+\t.lock\t\t= nullfs_nolock,\n+\t.flock\t\t= nullfs_nolock,\n+\t.setlease\t= nullfs_nolease,\n+\t.fop_flags\t= FOP_IMMUTABLE,\n+};\n+\n static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)\n {\n \tstruct inode *inode;\n@@ -30,10 +67,11 @@ static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)\n \n \t/* nullfs is permanently empty... */\n \tmake_empty_dir_inode(inode);\n+\tinode-\u003ei_fop = \u0026nullfs_dir_operations;\n \tsimple_inode_init_ts(inode);\n \tinode-\u003ei_ino\t= 1;\n-\t/* ... and immutable. */\n-\tinode-\u003ei_flags |= S_IMMUTABLE;\n+\t/* ... and immutable, reading it leaves no trace either. */\n+\tinode-\u003ei_flags |= S_IMMUTABLE | S_NOATIME;\n \n \ts-\u003es_root = d_make_root(inode);\n \tif (!s-\u003es_root)\n@@ -61,6 +99,7 @@ static int nullfs_init_fs_context(struct fs_context *fc)\n \n struct file_system_type nullfs_fs_type = {\n \t.name\t\t\t= \"nullfs\",\n+\t.fs_flags\t\t= FS_DISALLOW_NOTIFY,\n \t.init_fs_context\t= nullfs_init_fs_context,\n \t.kill_sb\t\t= kill_anon_super,\n };\ndiff --git a/fs/readdir.c b/fs/readdir.c\nindex 76bb1ae3a4504..f2288841337ad 100644\n--- a/fs/readdir.c\n+++ b/fs/readdir.c\n@@ -87,6 +87,8 @@ EXPORT_SYMBOL(wrap_directory_iterator);\n int iterate_dir(struct file *file, struct dir_context *ctx)\n {\n \tstruct inode *inode = file_inode(file);\n+\t/* never an entry, never removed: nothing for the lock to keep still */\n+\tbool locked = !(file-\u003ef_op-\u003efop_flags \u0026 FOP_IMMUTABLE);\n \tint res = -ENOTDIR;\n \n \tif (!file-\u003ef_op-\u003eiterate_shared)\n@@ -100,9 +102,11 @@ int iterate_dir(struct file *file, struct dir_context *ctx)\n \tif (res)\n \t\tgoto out;\n \n-\tres = down_read_killable(\u0026inode-\u003ei_rwsem);\n-\tif (res)\n-\t\tgoto out;\n+\tif (locked) {\n+\t\tres = down_read_killable(\u0026inode-\u003ei_rwsem);\n+\t\tif (res)\n+\t\t\tgoto out;\n+\t}\n \n \tres = -ENOENT;\n \tif (!IS_DEADDIR(inode)) {\n@@ -112,7 +116,8 @@ int iterate_dir(struct file *file, struct dir_context *ctx)\n \t\tfsnotify_access(file);\n \t\tfile_accessed(file);\n \t}\n-\tinode_unlock_shared(inode);\n+\tif (locked)\n+\t\tinode_unlock_shared(inode);\n out:\n \treturn res;\n }\ndiff --git a/include/linux/fs.h b/include/linux/fs.h\nindex f9d1e05e8ae68..deb411e866617 100644\n--- a/include/linux/fs.h\n+++ b/include/linux/fs.h\n@@ -1978,6 +1978,8 @@ struct file_operations {\n #define FOP_ASYNC_LOCK\t\t((__force fop_flags_t)(1 \u003c\u003c 6))\n /* File system supports uncached read/write buffered IO */\n #define FOP_DONTCACHE\t\t((__force fop_flags_t)(1 \u003c\u003c 7))\n+/* Never changes and is never removed, readdir of a directory takes no lock */\n+#define FOP_IMMUTABLE\t\t((__force fop_flags_t)(1 \u003c\u003c 8))\n \n /* Wrap a directory iterator that needs exclusive inode access */\n int wrap_directory_iterator(struct file *, struct dir_context *,\n@@ -2296,6 +2298,7 @@ struct file_system_type {\n #define FS_POWER_FREEZE\t\t256\t/* Always freeze on suspend/hibernate */\n #define FS_USERNS_MOUNT_RESTRICTED 512\t/* Restrict mount in userns if not already visible */\n #define FS_USERNS_DELEGATABLE\t1024\t/* Can be mounted inside userns from outside */\n+#define FS_DISALLOW_NOTIFY\t2048\t/* No fsnotify marks on its objects */\n #define FS_RENAME_DOES_D_MOVE\t32768\t/* FS will handle d_move() during rename() internally. */\n \tint (*init_fs_context)(struct fs_context *);\n \tconst struct fs_parameter_spec *parameters;\ndiff --git a/tools/testing/selftests/filesystems/.gitignore b/tools/testing/selftests/filesystems/.gitignore\nindex 9eb185fb2f9dd..62f7b1c466497 100644\n--- a/tools/testing/selftests/filesystems/.gitignore\n+++ b/tools/testing/selftests/filesystems/.gitignore\n@@ -7,3 +7,4 @@ anon_inode_test\n kernfs_test\n idmapped_tmpfile\n ustat_test\n+rw_hint_test\ndiff --git a/tools/testing/selftests/filesystems/Makefile b/tools/testing/selftests/filesystems/Makefile\nindex 03be337c1f351..93e2cc9123b04 100644\n--- a/tools/testing/selftests/filesystems/Makefile\n+++ b/tools/testing/selftests/filesystems/Makefile\n@@ -1,7 +1,7 @@\n # SPDX-License-Identifier: GPL-2.0\n \n CFLAGS += $(KHDR_INCLUDES)\n-TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test\n+TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test rw_hint_test\n TEST_GEN_PROGS += idmapped_tmpfile\n TEST_GEN_PROGS_EXTENDED := dnotify_test\n \ndiff --git a/tools/testing/selftests/filesystems/empty_mntns/.gitignore b/tools/testing/selftests/filesystems/empty_mntns/.gitignore\nindex 32125b3eaa801..27bcbcaeb1d19 100644\n--- a/tools/testing/selftests/filesystems/empty_mntns/.gitignore\n+++ b/tools/testing/selftests/filesystems/empty_mntns/.gitignore\n@@ -3,3 +3,5 @@ clone3_empty_mntns_test\n empty_mntns_test\n overmount_chroot_test\n internal_sb_reconfigure_test\n+nullfs_atime_test\n+root_readdir_test\ndiff --git a/tools/testing/selftests/filesystems/empty_mntns/Makefile b/tools/testing/selftests/filesystems/empty_mntns/Makefile\nindex b64818b962ca5..22af2164c54e9 100644\n--- a/tools/testing/selftests/filesystems/empty_mntns/Makefile\n+++ b/tools/testing/selftests/filesystems/empty_mntns/Makefile\n@@ -4,7 +4,9 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES)\n LDLIBS += -lcap\n \n TEST_GEN_PROGS := empty_mntns_test overmount_chroot_test clone3_empty_mntns_test\n-TEST_GEN_PROGS += internal_sb_reconfigure_test\n+TEST_GEN_PROGS += internal_sb_reconfigure_test nullfs_atime_test root_readdir_test\n+\n+LOCAL_HDRS += ../readdir_hold.h\n \n include ../../lib.mk\n \n@@ -12,3 +14,4 @@ $(OUTPUT)/empty_mntns_test: ../utils.c\n $(OUTPUT)/overmount_chroot_test: ../utils.c\n $(OUTPUT)/clone3_empty_mntns_test: ../utils.c\n $(OUTPUT)/internal_sb_reconfigure_test: ../utils.c\n+$(OUTPUT)/root_readdir_test: LDLIBS += -pthread\ndiff --git a/tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c b/tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c\nnew file mode 100644\nindex 0000000000000..51e34f3c4f541\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c\n@@ -0,0 +1,129 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * The root of every empty mount namespace is the same nullfs inode. A read\n+ * of it by one user must not change the access time another user sees.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cdirent.h\u003e\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003cunistd.h\u003e\n+#include \u003csys/stat.h\u003e\n+#include \u003csys/wait.h\u003e\n+\n+#include \"../../kselftest_harness.h\"\n+\n+#ifndef UNSHARE_EMPTY_MNTNS\n+#define UNSHARE_EMPTY_MNTNS\t0x00100000\n+#endif\n+\n+enum {\n+\tCHILD_OK,\n+\tCHILD_UNSUPPORTED,\n+\tCHILD_SETUP,\n+\tCHILD_CHANGED,\n+};\n+\n+static int wait_byte(int fd)\n+{\n+\tchar c;\n+\n+\treturn read(fd, \u0026c, 1) == 1 ? 0 : -1;\n+}\n+\n+static int send_byte(int fd)\n+{\n+\treturn write(fd, \"x\", 1) == 1 ? 0 : -1;\n+}\n+\n+static int empty_mntns(void)\n+{\n+\tif (!unshare(UNSHARE_EMPTY_MNTNS))\n+\t\treturn 0;\n+\treturn errno == EINVAL ? CHILD_UNSUPPORTED : CHILD_SETUP;\n+}\n+\n+/* the watcher: stats its root before and after the reader read its own */\n+static int watcher(int to_reader, int from_reader)\n+{\n+\tstruct stat before, after;\n+\tint ret;\n+\n+\tret = empty_mntns();\n+\tif (ret)\n+\t\treturn ret;\n+\tif (stat(\"/\", \u0026before))\n+\t\treturn CHILD_SETUP;\n+\tif (send_byte(to_reader) || wait_byte(from_reader))\n+\t\treturn CHILD_SETUP;\n+\tif (stat(\"/\", \u0026after))\n+\t\treturn CHILD_SETUP;\n+\tif (before.st_atim.tv_sec != after.st_atim.tv_sec ||\n+\t before.st_atim.tv_nsec != after.st_atim.tv_nsec)\n+\t\treturn CHILD_CHANGED;\n+\treturn CHILD_OK;\n+}\n+\n+/* the reader: lists its own root, which is the same inode */\n+static int reader(int to_watcher, int from_watcher)\n+{\n+\tstruct dirent *de;\n+\tDIR *d;\n+\tint ret;\n+\n+\tret = empty_mntns();\n+\tif (ret)\n+\t\treturn ret;\n+\tif (wait_byte(from_watcher))\n+\t\treturn CHILD_SETUP;\n+\td = opendir(\"/\");\n+\tif (!d)\n+\t\treturn CHILD_SETUP;\n+\twhile ((de = readdir(d)))\n+\t\t;\n+\tclosedir(d);\n+\treturn send_byte(to_watcher) ? CHILD_SETUP : CHILD_OK;\n+}\n+\n+static int wait_child(pid_t pid)\n+{\n+\tint status;\n+\n+\tif (waitpid(pid, \u0026status, 0) != pid || !WIFEXITED(status))\n+\t\treturn -1;\n+\treturn WEXITSTATUS(status);\n+}\n+\n+TEST(empty_mntns_root_atime)\n+{\n+\tint to_reader[2], to_watcher[2], w, r;\n+\tpid_t watcher_pid, reader_pid;\n+\n+\tif (geteuid())\n+\t\tSKIP(return, \"test requires root\");\n+\tASSERT_EQ(pipe(to_reader), 0);\n+\tASSERT_EQ(pipe(to_watcher), 0);\n+\n+\twatcher_pid = fork();\n+\tASSERT_GE(watcher_pid, 0);\n+\tif (watcher_pid == 0)\n+\t\t_exit(watcher(to_reader[1], to_watcher[0]));\n+\treader_pid = fork();\n+\tASSERT_GE(reader_pid, 0);\n+\tif (reader_pid == 0)\n+\t\t_exit(reader(to_watcher[1], to_reader[0]));\n+\n+\tr = wait_child(reader_pid);\n+\tw = wait_child(watcher_pid);\n+\tif (r == CHILD_UNSUPPORTED || w == CHILD_UNSUPPORTED)\n+\t\tSKIP(return, \"UNSHARE_EMPTY_MNTNS not supported\");\n+\tEXPECT_EQ(r, CHILD_OK);\n+\tEXPECT_EQ(w, CHILD_OK)\n+\t\tTH_LOG(\"the access time of the root changed while this namespace did nothing\");\n+}\n+\n+TEST_HARNESS_MAIN\ndiff --git a/tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c b/tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c\nnew file mode 100644\nindex 0000000000000..0ff5442470270\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c\n@@ -0,0 +1,45 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Reading the root of an empty mount namespace holds nothing that anybody\n+ * else waits for: the directory never has an entry, so a readdir stuck in\n+ * the page fault of its buffer stalls neither a create nor a lookup in it.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cunistd.h\u003e\n+\n+#include \"../../kselftest_harness.h\"\n+#include \"../readdir_hold.h\"\n+#include \"empty_mntns.h\"\n+\n+TEST(readdir_blocks_nobody)\n+{\n+\tstruct readdir_hold hold;\n+\tbool stalled;\n+\tint dfd;\n+\n+\tif (geteuid())\n+\t\tSKIP(return, \"test requires root\");\n+\tif (readdir_hold_init(\u0026hold))\n+\t\tSKIP(return, \"test requires userfaultfd\");\n+\tif (unshare(UNSHARE_EMPTY_MNTNS)) {\n+\t\treaddir_hold_destroy(\u0026hold);\n+\t\tif (errno == EINVAL)\n+\t\t\tSKIP(return, \"UNSHARE_EMPTY_MNTNS not supported\");\n+\t\tASSERT_TRUE(false)\n+\t\t\tTH_LOG(\"unshare(UNSHARE_EMPTY_MNTNS): %m\");\n+\t}\n+\tdfd = open(\"/\", O_RDONLY | O_DIRECTORY | O_CLOEXEC);\n+\tASSERT_GE(dfd, 0);\n+\tASSERT_EQ(readdir_hold_check(\u0026hold, dfd, \u0026stalled), 0);\n+\t/* the lookup came back while the readdir was stuck in its fault */\n+\tEXPECT_FALSE(stalled);\n+\tclose(dfd);\n+\treaddir_hold_destroy(\u0026hold);\n+}\n+\n+TEST_HARNESS_MAIN\ndiff --git a/tools/testing/selftests/filesystems/overlayfs/.gitignore b/tools/testing/selftests/filesystems/overlayfs/.gitignore\nindex 077f7a1281687..b343cc430051d 100644\n--- a/tools/testing/selftests/filesystems/overlayfs/.gitignore\n+++ b/tools/testing/selftests/filesystems/overlayfs/.gitignore\n@@ -2,3 +2,4 @@\n dev_in_maps\n set_layers_via_fds\n idmapped_mounts\n+automount_in_layer\ndiff --git a/tools/testing/selftests/filesystems/overlayfs/Makefile b/tools/testing/selftests/filesystems/overlayfs/Makefile\nindex b3185f684add6..382a59bda5e70 100644\n--- a/tools/testing/selftests/filesystems/overlayfs/Makefile\n+++ b/tools/testing/selftests/filesystems/overlayfs/Makefile\n@@ -9,6 +9,7 @@ LOCAL_HDRS += ../wrappers.h log.h\n TEST_GEN_PROGS := dev_in_maps\n TEST_GEN_PROGS += set_layers_via_fds\n TEST_GEN_PROGS += idmapped_mounts\n+TEST_GEN_PROGS += automount_in_layer\n \n include ../../lib.mk\n \ndiff --git a/tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c b/tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c\nnew file mode 100644\nindex 0000000000000..0476c4582bdfc\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c\n@@ -0,0 +1,174 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * A layer of an overlay is a private clone of the mount it was given and\n+ * belongs to no mount namespace. fanotify hands out descriptors on it. An\n+ * automount triggered through one has no namespace to go into: the open has\n+ * to fail, not oops with namespace_sem held.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cdirent.h\u003e\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003cpoll.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003cunistd.h\u003e\n+#include \u003clinux/magic.h\u003e\n+#include \u003csys/fanotify.h\u003e\n+#include \u003csys/mount.h\u003e\n+#include \u003csys/stat.h\u003e\n+#include \u003csys/vfs.h\u003e\n+\n+#include \"../../kselftest_harness.h\"\n+\n+#define DIR_LEN\t\t64\n+#define PATH_LEN\t192\n+\n+static bool have_fs(const char *name)\n+{\n+\tchar line[128];\n+\tbool found = false;\n+\tFILE *f;\n+\n+\tf = fopen(\"/proc/filesystems\", \"re\");\n+\tif (!f)\n+\t\treturn false;\n+\twhile (fgets(line, sizeof(line), f)) {\n+\t\tchar *nl = strchr(line, '\\n');\n+\t\tchar *tab = strchr(line, '\\t');\n+\n+\t\tif (nl)\n+\t\t\t*nl = 0;\n+\t\tif (tab \u0026\u0026 !strcmp(tab + 1, name))\n+\t\t\tfound = true;\n+\t}\n+\tfclose(f);\n+\treturn found;\n+}\n+\n+static int mnt_id_of(int fd)\n+{\n+\tchar path[64], buf[4096], *p;\n+\tssize_t n;\n+\tint info;\n+\n+\tsnprintf(path, sizeof(path), \"/proc/self/fdinfo/%d\", fd);\n+\tinfo = open(path, O_RDONLY | O_CLOEXEC);\n+\tif (info \u003c 0)\n+\t\treturn -1;\n+\tn = read(info, buf, sizeof(buf) - 1);\n+\tclose(info);\n+\tif (n \u003c= 0)\n+\t\treturn -1;\n+\tbuf[n] = 0;\n+\tp = strstr(buf, \"mnt_id:\");\n+\treturn p ? atoi(p + strlen(\"mnt_id:\")) : -1;\n+}\n+\n+static bool on_debugfs(int fd)\n+{\n+\tstruct statfs sf;\n+\n+\treturn !fstatfs(fd, \u0026sf) \u0026\u0026 sf.f_type == DEBUGFS_MAGIC;\n+}\n+\n+FIXTURE(layer) {\n+\tchar base[DIR_LEN];\n+\tint fan;\n+\tint evfd;\t/* on the layer clone of the lower debugfs */\n+};\n+\n+FIXTURE_SETUP(layer)\n+{\n+\tchar lower[PATH_LEN], other[PATH_LEN], ovl[PATH_LEN], opts[2 * PATH_LEN + 16];\n+\tstruct fanotify_event_metadata *ev;\n+\tstruct pollfd pfd;\n+\tchar buf[4096];\n+\tint lfd, lower_id;\n+\tssize_t n;\n+\tDIR *d;\n+\n+\tself-\u003efan = -1;\n+\tself-\u003eevfd = -1;\n+\tif (geteuid())\n+\t\tSKIP(return, \"test requires root\");\n+\tif (!have_fs(\"debugfs\") || !have_fs(\"tracefs\"))\n+\t\tSKIP(return, \"test requires debugfs with the tracefs automount\");\n+\tif (!have_fs(\"overlay\"))\n+\t\tSKIP(return, \"test requires overlayfs\");\n+\n+\tsnprintf(self-\u003ebase, sizeof(self-\u003ebase), \"/tmp/layer.XXXXXX\");\n+\tASSERT_NE(mkdtemp(self-\u003ebase), NULL);\n+\tASSERT_EQ(unshare(CLONE_NEWNS), 0);\n+\tASSERT_EQ(mount(\"\", \"/\", NULL, MS_REC | MS_PRIVATE, NULL), 0);\n+\tASSERT_EQ(mount(\"tmpfs\", self-\u003ebase, \"tmpfs\", 0, \"mode=0755\"), 0);\n+\tsnprintf(lower, sizeof(lower), \"%s/lower\", self-\u003ebase);\n+\tsnprintf(other, sizeof(other), \"%s/other\", self-\u003ebase);\n+\tsnprintf(ovl, sizeof(ovl), \"%s/ovl\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(lower, 0755), 0);\n+\tASSERT_EQ(mkdir(other, 0755), 0);\n+\tASSERT_EQ(mkdir(ovl, 0755), 0);\n+\tASSERT_EQ(mount(\"debugfs\", lower, \"debugfs\", 0, NULL), 0);\n+\tsnprintf(opts, sizeof(opts), \"lowerdir=%s:%s\", lower, other);\n+\tASSERT_EQ(mount(\"overlay\", ovl, \"overlay\", MS_RDONLY, opts), 0);\n+\n+\tself-\u003efan = fanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK | FAN_CLOEXEC,\n+\t\t\t\t O_RDONLY | O_CLOEXEC);\n+\tASSERT_GE(self-\u003efan, 0);\n+\tASSERT_EQ(fanotify_mark(self-\u003efan, FAN_MARK_ADD | FAN_MARK_FILESYSTEM,\n+\t\t\t\tFAN_OPEN | FAN_ONDIR, AT_FDCWD, lower), 0);\n+\tlfd = open(lower, O_RDONLY | O_DIRECTORY | O_CLOEXEC);\n+\tASSERT_GE(lfd, 0);\n+\tlower_id = mnt_id_of(lfd);\n+\tclose(lfd);\n+\n+\t/* the overlay opens its lower directory through the layer clone */\n+\td = opendir(ovl);\n+\tASSERT_NE(d, NULL);\n+\tclosedir(d);\n+\tpfd.fd = self-\u003efan;\n+\tpfd.events = POLLIN;\n+\tASSERT_EQ(poll(\u0026pfd, 1, 5000), 1);\n+\tn = read(self-\u003efan, buf, sizeof(buf));\n+\tASSERT_GT(n, 0);\n+\tfor (ev = (void *)buf; FAN_EVENT_OK(ev, n); ev = FAN_EVENT_NEXT(ev, n)) {\n+\t\tif (ev-\u003efd \u003c 0)\n+\t\t\tcontinue;\n+\t\tif (self-\u003eevfd \u003c 0 \u0026\u0026 on_debugfs(ev-\u003efd) \u0026\u0026\n+\t\t mnt_id_of(ev-\u003efd) != lower_id)\n+\t\t\tself-\u003eevfd = ev-\u003efd;\n+\t\telse\n+\t\t\tclose(ev-\u003efd);\n+\t}\n+\tASSERT_GE(self-\u003eevfd, 0)\n+\t\tTH_LOG(\"no event on the layer clone\");\n+}\n+\n+FIXTURE_TEARDOWN(layer)\n+{\n+\tif (self-\u003eevfd \u003e= 0)\n+\t\tclose(self-\u003eevfd);\n+\tif (self-\u003efan \u003e= 0)\n+\t\tclose(self-\u003efan);\n+\tumount2(self-\u003ebase, MNT_DETACH);\n+\trmdir(self-\u003ebase);\n+}\n+\n+TEST_F(layer, automount_below_the_clone_is_refused)\n+{\n+\tstruct stat st;\n+\tint fd;\n+\n+\t/* the automount point is there */\n+\tASSERT_EQ(fstatat(self-\u003eevfd, \"tracing\", \u0026st, AT_NO_AUTOMOUNT), 0);\n+\t/* the clone is in no namespace, so the automount has nowhere to go */\n+\tfd = openat(self-\u003eevfd, \"tracing\", O_RDONLY | O_DIRECTORY | O_CLOEXEC);\n+\tEXPECT_LT(fd, 0);\n+\tEXPECT_EQ(errno, EINVAL);\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+}\n+\n+TEST_HARNESS_MAIN\ndiff --git a/tools/testing/selftests/filesystems/readdir_hold.h b/tools/testing/selftests/filesystems/readdir_hold.h\nnew file mode 100644\nindex 0000000000000..57eee1bef4700\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/readdir_hold.h\n@@ -0,0 +1,224 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * Hold a readdir of a directory in the page fault of its buffer and see\n+ * whether a create and a lookup in that directory wait for it. For a\n+ * directory that is permanently empty they must not.\n+ */\n+#ifndef __SELFTESTS_READDIR_HOLD_H\n+#define __SELFTESTS_READDIR_HOLD_H\n+\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003cpoll.h\u003e\n+#include \u003cpthread.h\u003e\n+#include \u003cstdbool.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003cunistd.h\u003e\n+#include \u003clinux/userfaultfd.h\u003e\n+#include \u003csys/ioctl.h\u003e\n+#include \u003csys/mman.h\u003e\n+#include \u003csys/stat.h\u003e\n+#include \u003csys/syscall.h\u003e\n+\n+#define HOLD_FAULT_MS\t5000\t/* for the reader to reach the fault */\n+#define HOLD_QUEUE_MS\t2000\t/* for the create to queue up behind it */\n+#define HOLD_LOOKUP_MS\t5000\t/* for the lookup to come back */\n+\n+struct readdir_hold {\n+\tint uffd;\n+\tint taskdir;\t\t/* /proc/self/task, from before any namespace change */\n+\tlong page_size;\n+\tchar *page;\t\t/* faults until released */\n+\tint dfd;\n+\tpid_t creator_tid;\n+\tint created;\n+\tint done[2];\t\t/* the finder writes a byte when it is back */\n+};\n+\n+/*\n+ * The fault happens in the kernel, so the userfaultfd needs CAP_SYS_PTRACE\n+ * in the initial user namespace or vm.unprivileged_userfaultfd. Call this\n+ * before entering a user namespace.\n+ */\n+static inline int readdir_hold_init(struct readdir_hold *h)\n+{\n+\tstruct uffdio_api api = { .api = UFFD_API };\n+\n+\th-\u003epage = MAP_FAILED;\n+\th-\u003epage_size = sysconf(_SC_PAGESIZE);\n+\th-\u003etaskdir = open(\"/proc/self/task\", O_RDONLY | O_DIRECTORY | O_CLOEXEC);\n+\th-\u003euffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);\n+\tif (h-\u003euffd \u003c 0 || h-\u003etaskdir \u003c 0 || ioctl(h-\u003euffd, UFFDIO_API, \u0026api)) {\n+\t\tif (h-\u003euffd \u003e= 0)\n+\t\t\tclose(h-\u003euffd);\n+\t\tif (h-\u003etaskdir \u003e= 0)\n+\t\t\tclose(h-\u003etaskdir);\n+\t\th-\u003euffd = h-\u003etaskdir = -1;\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\n+\n+static inline void readdir_hold_destroy(struct readdir_hold *h)\n+{\n+\tif (h-\u003euffd \u003e= 0)\n+\t\tclose(h-\u003euffd);\n+\tif (h-\u003etaskdir \u003e= 0)\n+\t\tclose(h-\u003etaskdir);\n+\th-\u003euffd = h-\u003etaskdir = -1;\n+}\n+\n+static inline void *readdir_hold_reader(void *arg)\n+{\n+\tstruct readdir_hold *h = arg;\n+\n+\t/* the first byte written to the buffer faults until released */\n+\tsyscall(__NR_getdents64, h-\u003edfd, h-\u003epage, h-\u003epage_size);\n+\treturn NULL;\n+}\n+\n+static inline void *readdir_hold_creator(void *arg)\n+{\n+\tstruct readdir_hold *h = arg;\n+\n+\th-\u003ecreator_tid = syscall(__NR_gettid);\n+\t/* takes the directory lock exclusive before it fails */\n+\tmkdirat(h-\u003edfd, \"x\", 0755);\n+\t__atomic_store_n(\u0026h-\u003ecreated, 1, __ATOMIC_RELEASE);\n+\treturn NULL;\n+}\n+\n+static inline void *readdir_hold_finder(void *arg)\n+{\n+\tstruct readdir_hold *h = arg;\n+\tint fd;\n+\n+\t/* a lookup that misses the dcache takes the lock shared */\n+\tfd = openat(h-\u003edfd, \"no_such_name\", O_RDONLY | O_CLOEXEC);\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+\tif (write(h-\u003edone[1], \"x\", 1) != 1)\n+\t\tperror(\"readdir_hold: finder\");\n+\treturn NULL;\n+}\n+\n+/* the creator is back, or waits in the kernel for the lock */\n+static inline bool readdir_hold_creator_settled(struct readdir_hold *h)\n+{\n+\tchar path[32], buf[256], *p;\n+\tssize_t n;\n+\tint fd;\n+\n+\tif (__atomic_load_n(\u0026h-\u003ecreated, __ATOMIC_ACQUIRE))\n+\t\treturn true;\n+\tif (!h-\u003ecreator_tid)\n+\t\treturn false;\n+\tsnprintf(path, sizeof(path), \"%d/stat\", h-\u003ecreator_tid);\n+\tfd = openat(h-\u003etaskdir, path, O_RDONLY | O_CLOEXEC);\n+\tif (fd \u003c 0)\n+\t\treturn false;\n+\tn = read(fd, buf, sizeof(buf) - 1);\n+\tclose(fd);\n+\tif (n \u003c= 0)\n+\t\treturn false;\n+\tbuf[n] = 0;\n+\t/* \"pid (comm) state ...\" */\n+\tp = strrchr(buf, ')');\n+\treturn p \u0026\u0026 p[1] == ' ' \u0026\u0026 p[2] == 'D';\n+}\n+\n+static inline bool readdir_hold_faulted(struct readdir_hold *h)\n+{\n+\tstruct pollfd pfd = { .fd = h-\u003euffd, .events = POLLIN };\n+\tstruct uffd_msg msg;\n+\n+\tif (poll(\u0026pfd, 1, HOLD_FAULT_MS) != 1)\n+\t\treturn false;\n+\tif (read(h-\u003euffd, \u0026msg, sizeof(msg)) != sizeof(msg))\n+\t\treturn false;\n+\treturn msg.event == UFFD_EVENT_PAGEFAULT;\n+}\n+\n+/* let the reader go on */\n+static inline void readdir_hold_release(struct readdir_hold *h)\n+{\n+\tstruct uffdio_copy cp = {\n+\t\t.dst = (unsigned long)h-\u003epage,\n+\t\t.len = h-\u003epage_size,\n+\t};\n+\tvoid *zero;\n+\n+\tzero = calloc(1, h-\u003epage_size);\n+\tif (!zero)\n+\t\treturn;\n+\tcp.src = (unsigned long)zero;\n+\tif (ioctl(h-\u003euffd, UFFDIO_COPY, \u0026cp) \u0026\u0026 errno != EEXIST)\n+\t\tperror(\"readdir_hold: UFFDIO_COPY\");\n+\tfree(zero);\n+}\n+\n+/*\n+ * A readdir of @dfd that sticks in the fault of its buffer, then a create\n+ * and a lookup in @dfd. Whether the lookup came back while the readdir was\n+ * still stuck goes to @stalled. Returns -1 when that could not be found\n+ * out.\n+ */\n+static inline int readdir_hold_check(struct readdir_hold *h, int dfd,\n+\t\t\t\t bool *stalled)\n+{\n+\tpthread_t reader, creator, finder;\n+\tstruct uffdio_register reg = {};\n+\tstruct pollfd pfd;\n+\tint ret = -1, i;\n+\n+\th-\u003edfd = dfd;\n+\th-\u003ecreated = 0;\n+\th-\u003ecreator_tid = 0;\n+\th-\u003epage = mmap(NULL, h-\u003epage_size, PROT_READ | PROT_WRITE,\n+\t\t MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n+\tif (h-\u003epage == MAP_FAILED)\n+\t\treturn -1;\n+\treg.range.start = (unsigned long)h-\u003epage;\n+\treg.range.len = h-\u003epage_size;\n+\treg.mode = UFFDIO_REGISTER_MODE_MISSING;\n+\tif (ioctl(h-\u003euffd, UFFDIO_REGISTER, \u0026reg) || pipe2(h-\u003edone, O_CLOEXEC))\n+\t\tgoto out_page;\n+\n+\tif (pthread_create(\u0026reader, NULL, readdir_hold_reader, h))\n+\t\tgoto out_pipe;\n+\tif (!readdir_hold_faulted(h))\n+\t\tgoto out_reader;\n+\tif (pthread_create(\u0026creator, NULL, readdir_hold_creator, h))\n+\t\tgoto out_reader;\n+\tfor (i = 0; i \u003c HOLD_QUEUE_MS / 10 \u0026\u0026 !readdir_hold_creator_settled(h); i++)\n+\t\tusleep(10000);\n+\tif (pthread_create(\u0026finder, NULL, readdir_hold_finder, h))\n+\t\tgoto out_creator;\n+\n+\tpfd.fd = h-\u003edone[0];\n+\tpfd.events = POLLIN;\n+\t*stalled = poll(\u0026pfd, 1, HOLD_LOOKUP_MS) != 1;\n+\tret = 0;\n+\n+\treaddir_hold_release(h);\n+\tpthread_join(finder, NULL);\n+out_creator:\n+\tif (ret)\n+\t\treaddir_hold_release(h);\n+\tpthread_join(creator, NULL);\n+out_reader:\n+\tif (ret)\n+\t\treaddir_hold_release(h);\n+\tpthread_join(reader, NULL);\n+out_pipe:\n+\tclose(h-\u003edone[0]);\n+\tclose(h-\u003edone[1]);\n+out_page:\n+\tmunmap(h-\u003epage, h-\u003epage_size);\n+\th-\u003epage = MAP_FAILED;\n+\treturn ret;\n+}\n+\n+#endif /* __SELFTESTS_READDIR_HOLD_H */\ndiff --git a/tools/testing/selftests/filesystems/rw_hint_test.c b/tools/testing/selftests/filesystems/rw_hint_test.c\nnew file mode 100644\nindex 0000000000000..d1930f82f63b5\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/rw_hint_test.c\n@@ -0,0 +1,129 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * F_SET_RW_HINT is refused on an immutable inode. Nothing is ever written\n+ * to it and it may be shared with everybody, like a namespace file or the\n+ * root of an empty mount namespace.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdint.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003cunistd.h\u003e\n+#include \u003csys/ioctl.h\u003e\n+#include \u003csys/stat.h\u003e\n+#include \u003csys/wait.h\u003e\n+\n+#include \"../kselftest_harness.h\"\n+\n+/* \u003clinux/fs.h\u003e and \u003clinux/fcntl.h\u003e don't mix with the libc headers */\n+#ifndef FS_IOC_GETFLAGS\n+#define FS_IOC_GETFLAGS\t\t_IOR('f', 1, long)\n+#define FS_IOC_SETFLAGS\t\t_IOW('f', 2, long)\n+#endif\n+#ifndef FS_IMMUTABLE_FL\n+#define FS_IMMUTABLE_FL\t\t0x00000010\n+#endif\n+#ifndef F_LINUX_SPECIFIC_BASE\n+#define F_LINUX_SPECIFIC_BASE\t1024\n+#endif\n+#ifndef F_GET_RW_HINT\n+#define F_GET_RW_HINT\t\t(F_LINUX_SPECIFIC_BASE + 11)\n+#define F_SET_RW_HINT\t\t(F_LINUX_SPECIFIC_BASE + 12)\n+#endif\n+#ifndef RWH_WRITE_LIFE_SHORT\n+#define RWH_WRITE_LIFE_SHORT\t2\n+#endif\n+#ifndef UNSHARE_EMPTY_MNTNS\n+#define UNSHARE_EMPTY_MNTNS\t0x00100000\n+#endif\n+\n+static int set_hint(int fd, uint64_t hint)\n+{\n+\treturn fcntl(fd, F_SET_RW_HINT, \u0026hint);\n+}\n+\n+static long get_hint(int fd)\n+{\n+\tuint64_t hint;\n+\n+\tif (fcntl(fd, F_GET_RW_HINT, \u0026hint))\n+\t\treturn -1;\n+\treturn hint;\n+}\n+\n+TEST(immutable_file)\n+{\n+\tchar path[] = \"/tmp/rw_hint.XXXXXX\";\n+\tint fd, flags;\n+\n+\tif (geteuid())\n+\t\tSKIP(return, \"test requires root\");\n+\n+\tfd = mkstemp(path);\n+\tASSERT_GE(fd, 0);\n+\tunlink(path);\n+\tASSERT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0);\n+\tEXPECT_EQ(get_hint(fd), RWH_WRITE_LIFE_SHORT);\n+\n+\tif (ioctl(fd, FS_IOC_GETFLAGS, \u0026flags)) {\n+\t\tclose(fd);\n+\t\tSKIP(return, \"no file attributes on this filesystem\");\n+\t}\n+\tflags |= FS_IMMUTABLE_FL;\n+\tASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, \u0026flags), 0);\n+\tEXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1);\n+\tEXPECT_EQ(errno, EPERM);\n+\tflags \u0026= ~FS_IMMUTABLE_FL;\n+\tASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, \u0026flags), 0);\n+\tEXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0);\n+\tclose(fd);\n+}\n+\n+TEST(namespace_file)\n+{\n+\tint fd;\n+\n+\tif (geteuid())\n+\t\tSKIP(return, \"test requires root\");\n+\n+\tfd = open(\"/proc/self/ns/mnt\", O_RDONLY | O_CLOEXEC);\n+\tASSERT_GE(fd, 0);\n+\tEXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1);\n+\tEXPECT_EQ(errno, EPERM);\n+\tclose(fd);\n+}\n+\n+TEST(empty_mntns_root)\n+{\n+\tint status;\n+\tpid_t pid;\n+\n+\tif (geteuid())\n+\t\tSKIP(return, \"test requires root\");\n+\n+\tpid = fork();\n+\tASSERT_GE(pid, 0);\n+\tif (pid == 0) {\n+\t\tint fd;\n+\n+\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\n+\t\t\t_exit(errno == EINVAL ? 100 : 1);\n+\t\tfd = open(\"/\", O_RDONLY | O_DIRECTORY | O_CLOEXEC);\n+\t\tif (fd \u003c 0)\n+\t\t\t_exit(2);\n+\t\tif (set_hint(fd, RWH_WRITE_LIFE_SHORT) == 0)\n+\t\t\t_exit(3);\n+\t\t_exit(errno == EPERM ? 0 : 4);\n+\t}\n+\tASSERT_EQ(waitpid(pid, \u0026status, 0), pid);\n+\tASSERT_TRUE(WIFEXITED(status));\n+\tif (WEXITSTATUS(status) == 100)\n+\t\tSKIP(return, \"UNSHARE_EMPTY_MNTNS not supported\");\n+\tEXPECT_EQ(WEXITSTATUS(status), 0);\n+}\n+\n+TEST_HARNESS_MAIN\ndiff --git a/tools/testing/selftests/filesystems/umount_propagation/Makefile b/tools/testing/selftests/filesystems/umount_propagation/Makefile\nindex eb85612abf8d1..31f783a92b231 100644\n--- a/tools/testing/selftests/filesystems/umount_propagation/Makefile\n+++ b/tools/testing/selftests/filesystems/umount_propagation/Makefile\n@@ -1,5 +1,5 @@\n # SPDX-License-Identifier: GPL-2.0\n-TEST_GEN_PROGS := umount_propagation_test shrink_submounts_test\n+TEST_GEN_PROGS := umount_propagation_test shrink_submounts_test locked_mount_test\n \n CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)\n \ndiff --git a/tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c b/tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c\nnew file mode 100644\nindex 0000000000000..0799b2ba545d7\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c\n@@ -0,0 +1,432 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * MNT_LOCKED keeps the owner of a user namespace from revealing what a\n+ * mount covers. The lock has to be set on the copy in that namespace and\n+ * only there, it has to survive the expiry of a mount placed beneath the\n+ * locked one, and it has to survive the propagated umount of such a copy.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003cunistd.h\u003e\n+#include \u003csys/mount.h\u003e\n+#include \u003csys/prctl.h\u003e\n+#include \u003csys/stat.h\u003e\n+#include \u003csys/syscall.h\u003e\n+#include \u003csys/wait.h\u003e\n+\n+#include \"../../kselftest_harness.h\"\n+\n+#ifndef MOVE_MOUNT_F_EMPTY_PATH\n+#define MOVE_MOUNT_F_EMPTY_PATH\t0x00000004\n+#endif\n+#ifndef MOVE_MOUNT_BENEATH\n+#define MOVE_MOUNT_BENEATH\t0x00000200\n+#endif\n+\n+#define DIR_LEN\t\t64\n+#define PATH_LEN\t192\n+#define FLAGS\t\t(MS_NOSUID | MS_NODEV | MS_NOEXEC)\n+\n+/* exit codes of the children, each test says what they mean */\n+enum {\n+\tCHILD_OK,\n+\tCHILD_SETUP,\n+\tCHILD_STEP1,\n+\tCHILD_STEP2,\n+\tCHILD_STEP3,\n+\tCHILD_STEP4,\n+};\n+\n+static int write_file(const char *path, const char *s)\n+{\n+\tssize_t n = -1;\n+\tint fd;\n+\n+\tfd = open(path, O_WRONLY | O_CLOEXEC);\n+\tif (fd \u003e= 0) {\n+\t\tn = write(fd, s, strlen(s));\n+\t\tclose(fd);\n+\t}\n+\treturn n == (ssize_t)strlen(s) ? 0 : -1;\n+}\n+\n+static int create_file(const char *path, const char *s)\n+{\n+\tssize_t n = -1;\n+\tint fd;\n+\n+\tfd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644);\n+\tif (fd \u003e= 0) {\n+\t\tn = write(fd, s, strlen(s));\n+\t\tclose(fd);\n+\t}\n+\treturn n == (ssize_t)strlen(s) ? 0 : -1;\n+}\n+\n+/* Root in a new user namespace with a copy of the mount namespace. */\n+static int enter_userns(void)\n+{\n+\tuid_t uid = getuid();\n+\tgid_t gid = getgid();\n+\tchar map[32];\n+\n+\tprctl(PR_SET_DUMPABLE, 1);\n+\tif (unshare(CLONE_NEWUSER | CLONE_NEWNS))\n+\t\treturn -1;\n+\tif (write_file(\"/proc/self/setgroups\", \"deny\") \u0026\u0026 errno != ENOENT)\n+\t\treturn -1;\n+\tsnprintf(map, sizeof(map), \"0 %d 1\", uid);\n+\tif (write_file(\"/proc/self/uid_map\", map))\n+\t\treturn -1;\n+\tsnprintf(map, sizeof(map), \"0 %d 1\", gid);\n+\tif (write_file(\"/proc/self/gid_map\", map))\n+\t\treturn -1;\n+\treturn setgid(0) || setuid(0) ? -1 : 0;\n+}\n+\n+static int wait_child(pid_t pid)\n+{\n+\tint status;\n+\n+\tif (waitpid(pid, \u0026status, 0) != pid || !WIFEXITED(status))\n+\t\treturn -1;\n+\treturn WEXITSTATUS(status);\n+}\n+\n+static int wait_byte(int fd)\n+{\n+\tchar c;\n+\n+\treturn read(fd, \u0026c, 1) == 1 ? 0 : -1;\n+}\n+\n+static int send_byte(int fd)\n+{\n+\treturn write(fd, \"x\", 1) == 1 ? 0 : -1;\n+}\n+\n+/* A read of @path fails: the file is covered. */\n+static bool covered(const char *path)\n+{\n+\tint fd = open(path, O_RDONLY | O_CLOEXEC);\n+\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+\treturn fd \u003c 0;\n+}\n+\n+FIXTURE(locked_mount) {\n+\tchar base[DIR_LEN];\n+\tbool tracing;\t\t/* debugfs with the tracefs automount is there */\n+};\n+\n+FIXTURE_SETUP(locked_mount)\n+{\n+\tchar p[PATH_LEN];\n+\tstruct stat st;\n+\n+\tif (geteuid())\n+\t\tSKIP(return, \"test requires root\");\n+\n+\tsnprintf(self-\u003ebase, sizeof(self-\u003ebase), \"/tmp/locked_mount.XXXXXX\");\n+\tASSERT_NE(mkdtemp(self-\u003ebase), NULL);\n+\tASSERT_EQ(unshare(CLONE_NEWNS), 0);\n+\tASSERT_EQ(mount(\"\", \"/\", NULL, MS_REC | MS_PRIVATE, NULL), 0);\n+\tASSERT_EQ(mount(\"tmpfs\", self-\u003ebase, \"tmpfs\", 0, \"mode=0755\"), 0);\n+\n+\t/* an automount that a user can name: the tracefs below debugfs */\n+\tsnprintf(p, sizeof(p), \"%s/dbg\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(p, 0755), 0);\n+\tself-\u003etracing = !mount(\"debugfs\", p, \"debugfs\", FLAGS, NULL);\n+\tif (self-\u003etracing) {\n+\t\t/* the cases trigger it themselves */\n+\t\tsnprintf(p, sizeof(p), \"%s/dbg/tracing\", self-\u003ebase);\n+\t\tself-\u003etracing = !fstatat(AT_FDCWD, p, \u0026st, AT_NO_AUTOMOUNT) \u0026\u0026\n+\t\t\t\tS_ISDIR(st.st_mode);\n+\t}\n+}\n+\n+FIXTURE_TEARDOWN(locked_mount)\n+{\n+\tumount2(self-\u003ebase, MNT_DETACH);\n+\trmdir(self-\u003ebase);\n+}\n+\n+/*\n+ * The child keeps a directory descriptor on the host's debugfs mount, moves\n+ * to a user namespace of its own and triggers the automount through the\n+ * descriptor. The mount goes below the host's mount and propagates into the\n+ * child's copy. The child's copy has to be locked, the host's not.\n+ */\n+static int automount_child(const char *base, int dfd, int to_host, int from_host)\n+{\n+\tchar p[PATH_LEN];\n+\tstruct stat st;\n+\n+\tif (enter_userns())\n+\t\treturn CHILD_SETUP;\n+\tif (fstatat(dfd, \"tracing/.\", \u0026st, 0))\n+\t\treturn CHILD_STEP1;\n+\tif (send_byte(to_host) || wait_byte(from_host))\n+\t\treturn CHILD_SETUP;\n+\t/* the flags of the copy are locked: EPERM */\n+\tsnprintf(p, sizeof(p), \"%s/dbg/tracing\", base);\n+\tif (!mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL) || errno != EPERM)\n+\t\treturn CHILD_STEP2;\n+\treturn CHILD_OK;\n+}\n+\n+TEST_F(locked_mount, automount_locked_in_the_triggering_namespace)\n+{\n+\tint to_host[2], from_host[2], dfd, ret;\n+\tchar p[PATH_LEN];\n+\tpid_t pid;\n+\n+\tif (!self-\u003etracing)\n+\t\tSKIP(return, \"test requires debugfs with the tracefs automount\");\n+\n+\tsnprintf(p, sizeof(p), \"%s/dbg\", self-\u003ebase);\n+\tASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0);\n+\tdfd = open(p, O_RDONLY | O_DIRECTORY | O_CLOEXEC);\n+\tASSERT_GE(dfd, 0);\n+\tASSERT_EQ(pipe(to_host), 0);\n+\tASSERT_EQ(pipe(from_host), 0);\n+\n+\tpid = fork();\n+\tASSERT_GE(pid, 0);\n+\tif (pid == 0)\n+\t\t_exit(automount_child(self-\u003ebase, dfd, to_host[1], from_host[0]));\n+\tclose(dfd);\n+\tASSERT_EQ(wait_byte(to_host[0]), 0);\n+\n+\t/* the host's own mount isn't locked: the flags can go */\n+\tsnprintf(p, sizeof(p), \"%s/dbg/tracing\", self-\u003ebase);\n+\tEXPECT_EQ(mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL), 0);\n+\n+\tASSERT_EQ(send_byte(from_host[1]), 0);\n+\tret = wait_child(pid);\n+\tTH_LOG(\"child exit code %d\", ret);\n+\tEXPECT_EQ(ret, CHILD_OK);\n+}\n+\n+/*\n+ * A copy of a tree with a locked cover. The child puts a shrinkable mount\n+ * beneath the cover, which hands the lock down, unmounts the cover and then\n+ * asks for the umount of an unlocked ancestor. That expires the shrinkable\n+ * mount on a kernel that doesn't look at the lock, and the covered\n+ * directory is bare.\n+ */\n+static int expiry_child(const char *base)\n+{\n+\tchar srv[PATH_LEN], shr[PATH_LEN], x[PATH_LEN], c[PATH_LEN];\n+\tchar hidden[PATH_LEN], secret[PATH_LEN];\n+\n+\tsnprintf(srv, sizeof(srv), \"%s/srv\", base);\n+\tsnprintf(shr, sizeof(shr), \"%s/shr\", base);\n+\tsnprintf(x, sizeof(x), \"%s/x\", base);\n+\tsnprintf(c, sizeof(c), \"%s/c\", base);\n+\tsnprintf(hidden, sizeof(hidden), \"%s/x/hidden\", base);\n+\tsnprintf(secret, sizeof(secret), \"%s/x/hidden/secret\", base);\n+\n+\tif (enter_userns())\n+\t\treturn CHILD_SETUP;\n+\tif (mount(srv, x, NULL, MS_BIND | MS_REC, NULL) ||\n+\t mount(shr, c, NULL, MS_BIND, NULL))\n+\t\treturn CHILD_SETUP;\n+\t/* the cover is locked */\n+\tif (!umount2(hidden, 0) || errno != EINVAL)\n+\t\treturn CHILD_STEP1;\n+\tif (syscall(__NR_move_mount, AT_FDCWD, c, AT_FDCWD, hidden, MOVE_MOUNT_BENEATH))\n+\t\treturn CHILD_STEP2;\n+\t/* the lock moved down, the cover may go */\n+\tif (umount2(hidden, 0))\n+\t\treturn CHILD_STEP3;\n+\t/* the holder of the lock may not, in any way */\n+\tif (!umount2(hidden, 0) || errno != EINVAL)\n+\t\treturn CHILD_STEP4;\n+\tif (chdir(x))\n+\t\treturn CHILD_SETUP;\n+\tumount2(x, 0);\n+\treturn covered(secret) ? CHILD_OK : CHILD_STEP4;\n+}\n+\n+TEST_F(locked_mount, expiry_leaves_a_locked_mount_alone)\n+{\n+\tchar p[PATH_LEN], q[PATH_LEN];\n+\tpid_t pid;\n+\tint ret;\n+\n+\tif (!self-\u003etracing)\n+\t\tSKIP(return, \"test requires debugfs with the tracefs automount\");\n+\n+\tsnprintf(p, sizeof(p), \"%s/dbg/tracing\", self-\u003ebase);\n+\tsnprintf(q, sizeof(q), \"%s/shr\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(q, 0755), 0);\n+\t/* a bind of an automount is shrinkable as well */\n+\tASSERT_EQ(mount(p, q, NULL, MS_BIND, NULL), 0);\n+\tsnprintf(p, sizeof(p), \"%s/srv\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(p, 0755), 0);\n+\tASSERT_EQ(mount(\"tmpfs\", p, \"tmpfs\", 0, \"mode=0755\"), 0);\n+\tsnprintf(p, sizeof(p), \"%s/srv/hidden\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(p, 0755), 0);\n+\tsnprintf(p, sizeof(p), \"%s/srv/hidden/secret\", self-\u003ebase);\n+\tASSERT_EQ(create_file(p, \"covered-by-root\\n\"), 0);\n+\tsnprintf(p, sizeof(p), \"%s/srv/hidden\", self-\u003ebase);\n+\tASSERT_EQ(mount(\"tmpfs\", p, \"tmpfs\", 0, \"mode=0755\"), 0);\n+\tsnprintf(p, sizeof(p), \"%s/x\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(p, 0755), 0);\n+\tsnprintf(p, sizeof(p), \"%s/c\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(p, 0755), 0);\n+\n+\tpid = fork();\n+\tASSERT_GE(pid, 0);\n+\tif (pid == 0)\n+\t\t_exit(expiry_child(self-\u003ebase));\n+\tret = wait_child(pid);\n+\tTH_LOG(\"child exit code %d\", ret);\n+\tEXPECT_EQ(ret, CHILD_OK);\n+}\n+\n+/*\n+ * The copy of the mount tree that a user namespace gets at its creation has\n+ * the automounts in it locked unless they are on an expiry list. A bind of\n+ * such a tree inside the namespace copies the lock to the automount but not\n+ * to the root of the bind, so the child may ask for the umount of that root.\n+ * That must not expire the locked automount below it: the root is busy, the\n+ * umount fails and the automount has to be there afterwards.\n+ */\n+static int copied_tree_child(const char *base)\n+{\n+\tchar dbg[PATH_LEN], x[PATH_LEN], tracing[PATH_LEN];\n+\tstruct stat root, st;\n+\n+\tsnprintf(dbg, sizeof(dbg), \"%s/dbg\", base);\n+\tsnprintf(x, sizeof(x), \"%s/x\", base);\n+\tsnprintf(tracing, sizeof(tracing), \"%s/x/tracing\", base);\n+\n+\tif (enter_userns())\n+\t\treturn CHILD_SETUP;\n+\tif (mount(dbg, x, NULL, MS_BIND | MS_REC, NULL))\n+\t\treturn CHILD_SETUP;\n+\t/* the copy of the automount carries the lock */\n+\tif (!umount2(tracing, 0) || errno != EINVAL)\n+\t\treturn CHILD_STEP1;\n+\t/* the root of the bind doesn't; keep it busy */\n+\tif (chdir(x))\n+\t\treturn CHILD_SETUP;\n+\tif (!umount2(x, 0) || errno != EBUSY)\n+\t\treturn CHILD_STEP2;\n+\t/* the automount below it must not have gone */\n+\tif (stat(x, \u0026root) || fstatat(AT_FDCWD, tracing, \u0026st, AT_NO_AUTOMOUNT))\n+\t\treturn CHILD_SETUP;\n+\treturn st.st_dev != root.st_dev ? CHILD_OK : CHILD_STEP3;\n+}\n+\n+TEST_F(locked_mount, umount_of_a_bind_leaves_a_locked_automount_alone)\n+{\n+\tchar p[PATH_LEN];\n+\tstruct stat st;\n+\tpid_t pid;\n+\tint ret;\n+\n+\tif (!self-\u003etracing)\n+\t\tSKIP(return, \"test requires debugfs with the tracefs automount\");\n+\n+\t/* the copy the child gets has to contain the automount */\n+\tsnprintf(p, sizeof(p), \"%s/dbg/tracing/.\", self-\u003ebase);\n+\tASSERT_EQ(stat(p, \u0026st), 0);\n+\tsnprintf(p, sizeof(p), \"%s/x\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(p, 0755), 0);\n+\n+\tpid = fork();\n+\tASSERT_GE(pid, 0);\n+\tif (pid == 0)\n+\t\t_exit(copied_tree_child(self-\u003ebase));\n+\tret = wait_child(pid);\n+\tTH_LOG(\"child exit code %d\", ret);\n+\tEXPECT_EQ(ret, CHILD_OK);\n+}\n+\n+/*\n+ * Z is a user namespace with a copy of a tree in which P/d is covered by a\n+ * locked mount. The host mounts X on P/d, which propagates beneath Z's\n+ * cover, and unmounts it again. Z's cover has to be locked afterwards as\n+ * it was before.\n+ */\n+static int propagation_child(const char *base, int to_host, int from_host)\n+{\n+\tchar d[PATH_LEN], secret[PATH_LEN];\n+\n+\tsnprintf(d, sizeof(d), \"%s/P/d\", base);\n+\tsnprintf(secret, sizeof(secret), \"%s/P/d/secret\", base);\n+\n+\tif (enter_userns())\n+\t\treturn CHILD_SETUP;\n+\t/* the cover is locked */\n+\tif (!umount2(d, 0) || errno != EINVAL)\n+\t\treturn CHILD_STEP1;\n+\tif (send_byte(to_host) || wait_byte(from_host))\n+\t\treturn CHILD_SETUP;\n+\t/* X came and went beneath it: still locked */\n+\tif (!umount2(d, 0) || errno != EINVAL)\n+\t\treturn CHILD_STEP2;\n+\treturn covered(secret) ? CHILD_OK : CHILD_STEP3;\n+}\n+\n+TEST_F(locked_mount, propagated_copy_keeps_the_cover_locked)\n+{\n+\tint to_host[2], from_host[2], ret;\n+\tchar p[PATH_LEN];\n+\tpid_t pid;\n+\n+\tsnprintf(p, sizeof(p), \"%s/P\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(p, 0755), 0);\n+\tASSERT_EQ(mount(\"tmpfs\", p, \"tmpfs\", 0, \"mode=0755\"), 0);\n+\tASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0);\n+\tsnprintf(p, sizeof(p), \"%s/P/d\", self-\u003ebase);\n+\tASSERT_EQ(mkdir(p, 0755), 0);\n+\tsnprintf(p, sizeof(p), \"%s/P/d/secret\", self-\u003ebase);\n+\tASSERT_EQ(create_file(p, \"covered-by-root\\n\"), 0);\n+\tASSERT_EQ(pipe(to_host), 0);\n+\tASSERT_EQ(pipe(from_host), 0);\n+\n+\tpid = fork();\n+\tASSERT_GE(pid, 0);\n+\tif (pid == 0) {\n+\t\t/* M: a manager's namespace that covers P/d for Z */\n+\t\tpid_t z;\n+\n+\t\tif (unshare(CLONE_NEWNS))\n+\t\t\t_exit(CHILD_SETUP);\n+\t\tsnprintf(p, sizeof(p), \"%s/P\", self-\u003ebase);\n+\t\tif (mount(NULL, p, NULL, MS_SLAVE, NULL))\n+\t\t\t_exit(CHILD_SETUP);\n+\t\tsnprintf(p, sizeof(p), \"%s/P/d\", self-\u003ebase);\n+\t\tif (mount(\"tmpfs\", p, \"tmpfs\", 0, \"mode=0755\"))\n+\t\t\t_exit(CHILD_SETUP);\n+\t\tz = fork();\n+\t\tif (z \u003c 0)\n+\t\t\t_exit(CHILD_SETUP);\n+\t\tif (z == 0)\n+\t\t\t_exit(propagation_child(self-\u003ebase, to_host[1], from_host[0]));\n+\t\t_exit(wait_child(z));\n+\t}\n+\tASSERT_EQ(wait_byte(to_host[0]), 0);\n+\n+\t/* the host mounts on P/d and unmounts again; both propagate */\n+\tsnprintf(p, sizeof(p), \"%s/P/d\", self-\u003ebase);\n+\tASSERT_EQ(mount(\"tmpfs\", p, \"tmpfs\", 0, \"mode=0755\"), 0);\n+\tASSERT_EQ(umount2(p, 0), 0);\n+\n+\tASSERT_EQ(send_byte(from_host[1]), 0);\n+\tret = wait_child(pid);\n+\tTH_LOG(\"child exit code %d\", ret);\n+\tEXPECT_EQ(ret, CHILD_OK);\n+}\n+\n+TEST_HARNESS_MAIN\n"
} |
| 2/1 | 2026/10/03 03:35 | agent | patch-evaluator |
2mModel:core Args: null Results: {
"EnableConfigs": [
"DEBUG_VFS",
"FHANDLE",
"FSNOTIFY",
"USER_NS"
],
"FocusSymbols": [
"fcntl_set_rw_hint",
"subtree_unobstructed",
"handle_to_path",
"step_into_slowpath",
"unlink_may_reveal",
"__detach_mounts",
"has_locked_children",
"attach_recursive_mnt",
"mark_mounts_for_expiry",
"shrink_submount",
"nullfs_dir_readdir",
"nullfs_nolock",
"fsnotify_add_mark_locked",
"fsnotify_add_mark_list"
],
"Reasoning": "The patch series modifies core VFS logic across mount namespace locking and propagation (attach_recursive_mnt, has_locked_children), mount detach and expiry handling (__detach_mounts, shrink_submount, and adding a VFS_WARN_ON_ONCE assertion in mark_mounts_for_expiry), refwalk lookup revealing unlinked dentries (unlink_may_reveal in step_into_slowpath), lockless readdir execution for immutable filesystems (iterate_dir with FOP_IMMUTABLE), nullfs directory and file operations, file handle subtree decode checks (subtree_unobstructed in fhandle), fcntl rw_hint checks on immutable inodes, and fsnotify mark validation. All modified paths are reachable via standard system calls and virtualized environments, making this change an ideal candidate for fuzzing.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit f2c7e28a87ef20978c41877ec1ef9d1356a8d6a0
Author: syz-cluster <triage@syzkaller.com>
Date: Sat Oct 3 03:34:56 2026 +0000
syz-cluster: applied patch under review
diff --git a/fs/fcntl.c b/fs/fcntl.c
index c158f082f1da4..9b71bc9d71d15 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -372,6 +372,9 @@ static long fcntl_set_rw_hint(struct file *file, unsigned long arg)
u64 __user *argp = (u64 __user *)arg;
u64 hint;
+ /* nothing is ever written to it */
+ if (IS_IMMUTABLE(inode))
+ return -EPERM;
if (!inode_owner_or_capable(file_mnt_idmap(file), inode))
return -EPERM;
diff --git a/fs/fhandle.c b/fs/fhandle.c
index f8829231e3d75..d22f2e065677a 100644
--- a/fs/fhandle.c
+++ b/fs/fhandle.c
@@ -298,6 +298,22 @@ static bool capable_wrt_mount(struct mount *mount)
return mnt_ns && ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN);
}
+/*
+ * Does the caller have an unobstructed way to everything below @root? Only
+ * if the mount is mounted, the caller is privileged over its mount namespace
+ * and no locked child covers something below @root->dentry. One answer from
+ * under mount_lock: an umount in between clears ->mnt_ns and takes the
+ * children off the mount, the locked ones too.
+ */
+static bool subtree_unobstructed(const struct path *root)
+{
+ struct mount *mnt = real_mount(root->mnt);
+
+ guard(mount_locked_reader)();
+ return is_mounted(root->mnt) && capable_wrt_mount(mnt) &&
+ !has_locked_children(mnt, root->dentry);
+}
+
static inline int may_decode_fh(struct handle_to_path_ctx *ctx,
unsigned int o_flags)
{
@@ -332,9 +348,7 @@ static inline int may_decode_fh(struct handle_to_path_ctx *ctx,
if (ns_capable(root->mnt->mnt_sb->s_user_ns, CAP_SYS_ADMIN))
ctx->flags = HANDLE_CHECK_PERMS;
- else if (is_mounted(root->mnt) &&
- capable_wrt_mount(real_mount(root->mnt)) &&
- !has_locked_children(real_mount(root->mnt), root->dentry))
+ else if (subtree_unobstructed(root))
ctx->flags = HANDLE_CHECK_PERMS | HANDLE_CHECK_SUBTREE;
else
return -EPERM;
diff --git a/fs/mount.h b/fs/mount.h
index 2223fb141499f..4e68e5cbc2549 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -6,6 +6,7 @@
#include <linux/fs_pin.h>
extern struct file_system_type nullfs_fs_type;
+extern struct vfsmount *knullfs;
extern struct list_head notify_list;
struct mnt_namespace {
diff --git a/fs/namei.c b/fs/namei.c
index 20a6534ea3eff..c87c14ee1a252 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2086,6 +2086,33 @@ static noinline const char *pick_link(struct nameidata *nd, struct path *link,
return NULL;
}
+/*
+ * Be careful in case the dentry is unlinked or renamed. Any mounts
+ * stacked on top of it are going away. We need to make sure that we
+ * don't reveal the underyling dentry during refwalk. In rcuwalk we
+ * catch this via d_seq and another lookup for the name. Give the same
+ * guarantee in refwalk.
+ */
+static bool unlink_may_reveal(struct nameidata *nd, int flags,
+ struct path *path, struct dentry *dentry)
+{
+ /* ".." and LOOKUP_DOWN may land on an unhashed directory */
+ if (flags & WALK_NOFOLLOW)
+ return false;
+ if (nd->flags & LOOKUP_REVAL)
+ return false;
+ /* We crossed onto a mount and the name led us here while it still existed */
+ if (path->mnt != nd->path.mnt)
+ return false;
+ /* only a name on its way out is flagged */
+ if (likely(!cant_mount(dentry)))
+ return false;
+ if (!d_unlinked(dentry))
+ return false;
+ dput(no_free_ptr(path->dentry));
+ return true;
+}
+
/*
* Do we need to follow links? We _really_ want to be able
* to do this check without having to look at inode->i_op,
@@ -2115,6 +2142,8 @@ static noinline const char *step_into_slowpath(struct nameidata *nd, int flags,
if (unlikely(!inode))
return ERR_PTR(-ENOENT);
} else {
+ if (unlikely(unlink_may_reveal(nd, flags, &path, dentry)))
+ return ERR_PTR(-ESTALE);
dput(nd->path.dentry);
if (nd->path.mnt != path.mnt)
mntput(nd->path.mnt);
diff --git a/fs/namespace.c b/fs/namespace.c
index fcf42f192aae9..e1b0ade95b0d8 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -80,6 +80,7 @@ static u64 mnt_id_ctr = MNT_UNIQUE_ID_OFFSET;
static struct hlist_head *mount_hashtable __ro_after_init;
static struct hlist_head *mountpoint_hashtable __ro_after_init;
static struct kmem_cache *mnt_cache __ro_after_init;
+struct vfsmount *knullfs __ro_after_init; /* private nullfs instance */
static DECLARE_RWSEM(namespace_sem);
static HLIST_HEAD(unmounted); /* protected by namespace_sem */
static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */
@@ -1996,6 +1997,9 @@ static int do_umount(struct mount *mnt, int flags)
* detach_mounts allows lazily unmounting those mounts instead of
* leaking them.
*
+ * The dentry is unhashed before the mounts go so that no lookup finds
+ * what they covered. The caller removes it for good afterwards.
+ *
* The caller may hold dentry->d_inode->i_rwsem.
*/
void __detach_mounts(struct dentry *dentry)
@@ -2009,6 +2013,8 @@ void __detach_mounts(struct dentry *dentry)
if (!lookup_mountpoint(dentry, &mp))
return;
+ /* the name goes first, what covered it goes second */
+ d_drop(dentry);
event++;
while (mp.node.next) {
mnt = hlist_entry(mp.node.next, struct mount, mnt_mp_list);
@@ -2348,7 +2354,7 @@ void dissolve_on_fput(struct vfsmount *mnt)
}
/* locks: namespace_shared && pinned(mnt) || mount_locked_reader */
-static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)
+bool has_locked_children(struct mount *mnt, struct dentry *dentry)
{
struct mount *child;
@@ -2362,12 +2368,6 @@ static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)
return false;
}
-bool has_locked_children(struct mount *mnt, struct dentry *dentry)
-{
- guard(mount_locked_reader)();
- return __has_locked_children(mnt, dentry);
-}
-
/* locks: namespace_shared && pinned(mnt) || mount_locked_reader */
static bool __has_children(struct mount *mnt, struct dentry *dentry)
{
@@ -2436,7 +2436,7 @@ struct vfsmount *clone_private_mount(const struct path *path)
if (!ns_capable(old_mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
return ERR_PTR(-EPERM);
- if (__has_locked_children(old_mnt, path->dentry))
+ if (has_locked_children(old_mnt, path->dentry))
return ERR_PTR(-EINVAL);
new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE);
@@ -2599,11 +2599,11 @@ enum mnt_tree_flags_t {
static int attach_recursive_mnt(struct mount *source_mnt,
const struct pinned_mountpoint *dest)
{
- struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
struct mount *dest_mnt = dest->parent;
struct mountpoint *dest_mp = dest->mp;
HLIST_HEAD(tree_list);
struct mnt_namespace *ns = dest_mnt->mnt_ns;
+ struct user_namespace *user_ns = ns->user_ns;
struct pinned_mountpoint root = {};
struct mountpoint *shorter = NULL;
struct mount *child, *p;
@@ -2612,6 +2612,22 @@ static int attach_recursive_mnt(struct mount *source_mnt,
int err = 0;
bool moving = mnt_has_parent(source_mnt);
+ /*
+ * A caller in an unprivileged mount namespaces may trigger an
+ * automount and propagate locked mounts into privileged mount
+ * namespaces. Take ownership from the target mount namespace.
+ * It's equivalent for everything but the automount case.
+ *
+ * Detached trees in anonymous mount namespaces by be handed
+ * over via SCM_RIGHTS or inherited in other ways on purpose
+ * the attaching task's mount namespace is authoritative, not
+ * the creator of the detached tree.
+ */
+ if (is_anon_ns(ns))
+ user_ns = current->nsproxy->mnt_ns->user_ns;
+ else
+ user_ns = ns->user_ns;
+
/*
* Preallocate a mountpoint in case the new mounts need to be
* mounted beneath mounts on the same mountpoint.
@@ -2691,15 +2707,17 @@ static int attach_recursive_mnt(struct mount *source_mnt,
/*
* If @q was locked it was meant to hide
* whatever was under it. Let @child take over
- * that job and lock it, then we can unlock @q.
- * That'll allow another namespace to shed @q
- * and reveal @child. Clearly, that mounter
- * consented to this by not severing the mount
- * relationship. Otherwise, what's the point.
+ * that job and lock it. If @child is the mount
+ * the caller placed we can then unlock @q:
+ * nothing another namespace does removes it
+ * again. A propagated copy goes away when the
+ * mounter of the original unmounts it, so @q
+ * keeps its lock.
*/
if (IS_MNT_LOCKED(q)) {
child->mnt.mnt_flags |= MNT_LOCKED;
- q->mnt.mnt_flags &= ~MNT_LOCKED;
+ if (child == source_mnt)
+ q->mnt.mnt_flags &= ~MNT_LOCKED;
}
mnt_change_mountpoint(r, mp, q);
}
@@ -2796,6 +2814,11 @@ static void do_lock_mount(const struct path *path,
scoped_guard(mount_locked_reader) {
m = where_to_mount(path, &dentry, beneath);
+ /* sticky, so it takes no locks to refuse it */
+ if (unlikely(cant_mount(dentry))) {
+ res->parent = ERR_PTR(-ENOENT);
+ return;
+ }
if (&m->mnt != path->mnt) {
mntget(&m->mnt);
dget(dentry);
@@ -3033,7 +3056,7 @@ static struct mount *__do_loopback(const struct path *old_path,
if (recurse && !old->mnt_ns)
return ERR_PTR(-EINVAL);
- if (!recurse && __has_locked_children(old, old_path->dentry))
+ if (!recurse && has_locked_children(old, old_path->dentry))
return ERR_PTR(-EINVAL);
if (recurse)
@@ -3521,7 +3544,7 @@ static int do_set_group(const struct path *from_path, const struct path *to_path
return -EINVAL;
/* From mount should not have locked children in place of To's root */
- if (__has_locked_children(from, to->mnt.mnt_root))
+ if (has_locked_children(from, to->mnt.mnt_root))
return -EINVAL;
/* Setting sharing groups is only allowed on private mounts */
@@ -3801,7 +3824,7 @@ static int do_add_mount(struct mount *newmnt, const struct pinned_mountpoint *mp
if (!(mnt_flags & MNT_SHRINKABLE))
return -EINVAL;
/* ... and for those we'd better have mountpoint still alive */
- if (!parent->mnt_ns)
+ if (!is_mounted(&parent->mnt))
return -EINVAL;
}
@@ -4011,6 +4034,8 @@ void mark_mounts_for_expiry(struct list_head *mounts)
list_for_each_entry_safe(mnt, next, mounts, mnt_expire) {
if (!is_mounted(&mnt->mnt))
continue;
+ /* lock_mnt_tree() leaves expirable mounts alone */
+ VFS_WARN_ON_ONCE(IS_MNT_LOCKED(mnt));
if (!xchg(&mnt->mnt_expiry_mark, 1) ||
propagate_mount_busy(mnt, 1))
continue;
@@ -4037,7 +4062,8 @@ EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
*/
static bool shrink_submount(struct mount *mnt)
{
- if (propagate_mount_busy(mnt, 1))
+ /* not the kernel's to remove either */
+ if (IS_MNT_LOCKED(mnt) || propagate_mount_busy(mnt, 1))
return false;
touch_mnt_namespace(mnt->mnt_ns);
umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);
@@ -6315,7 +6341,7 @@ static void __init init_mount_tree(void)
*
* (1) nullfs with mount id 1
* (2) mutable rootfs with mount id 2
- * (3) private nullfs for kthreads (SB_KERNMOUNT)
+ * (3) private nullfs for kthreads (SB_KERNMOUNT), kept in knullfs
*
* with (2) mounted on top of (1). The init_task's root and pwd
* are pointed at (3) so all kthreads start isolated in nullfs.
@@ -6350,11 +6376,15 @@ static void __init init_mount_tree(void)
init_mnt_ns.nr_mounts++;
}
- nullfs_mnt = kern_mount(&nullfs_fs_type);
- if (IS_ERR(nullfs_mnt))
+ knullfs = kern_mount(&nullfs_fs_type);
+ if (IS_ERR(knullfs))
panic("VFS: Failed to create private nullfs instance");
- root.mnt = nullfs_mnt;
- root.dentry = nullfs_mnt->mnt_root;
+ /* nothing is ever mounted on the root of a kernel thread */
+ dont_mount(knullfs->mnt_root);
+ /* and nothing is ever written through it */
+ knullfs->mnt_flags |= MNT_READONLY;
+ root.mnt = knullfs;
+ root.dentry = knullfs->mnt_root;
init_task.nsproxy->mnt_ns = &init_mnt_ns;
get_mnt_ns(&init_mnt_ns);
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index b2640d836a712..d17628580a570 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -903,6 +903,10 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, void *obj,
if (WARN_ON(!fsnotify_valid_obj_type(obj_type)))
return -EINVAL;
+ /* the filesystem doesn't want its objects watched */
+ if (sb && (sb->s_type->fs_flags & FS_DISALLOW_NOTIFY))
+ return -EINVAL;
+
/*
* Attach the sb info before attaching a connector to any object on sb.
* The sb info will remain attached as long as sb lives.
diff --git a/fs/nullfs.c b/fs/nullfs.c
index e06352c7b2ccf..bfc04bca39407 100644
--- a/fs/nullfs.c
+++ b/fs/nullfs.c
@@ -10,6 +10,43 @@ static const struct super_operations nullfs_super_operations = {
.statfs = simple_statfs,
};
+static loff_t nullfs_dir_llseek(struct file *file, loff_t offset, int whence)
+{
+ /* an empty directory has two entries . and .. at offsets 0 and 1 */
+ return generic_file_llseek_size(file, offset, whence, 2, 2);
+}
+
+static int nullfs_dir_readdir(struct file *file, struct dir_context *ctx)
+{
+ dir_emit_dots(file, ctx);
+ return 0;
+}
+
+/* the one inode of nullfs is shared by every holder, so no locks on it */
+static int nullfs_nolock(struct file *file, int cmd, struct file_lock *fl)
+{
+ return -ENOLCK;
+}
+
+/* and no leases or delegations */
+static int nullfs_nolease(struct file *file, int arg, struct file_lease **flp,
+ void **priv)
+{
+ return -EINVAL;
+}
+
+/* what libfs gives an empty directory, plus the refusal of file locks */
+static const struct file_operations nullfs_dir_operations = {
+ .llseek = nullfs_dir_llseek,
+ .read = generic_read_dir,
+ .iterate_shared = nullfs_dir_readdir,
+ .fsync = noop_fsync,
+ .lock = nullfs_nolock,
+ .flock = nullfs_nolock,
+ .setlease = nullfs_nolease,
+ .fop_flags = FOP_IMMUTABLE,
+};
+
static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)
{
struct inode *inode;
@@ -30,10 +67,11 @@ static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)
/* nullfs is permanently empty... */
make_empty_dir_inode(inode);
+ inode->i_fop = &nullfs_dir_operations;
simple_inode_init_ts(inode);
inode->i_ino = 1;
- /* ... and immutable. */
- inode->i_flags |= S_IMMUTABLE;
+ /* ... and immutable, reading it leaves no trace either. */
+ inode->i_flags |= S_IMMUTABLE | S_NOATIME;
s->s_root = d_make_root(inode);
if (!s->s_root)
@@ -61,6 +99,7 @@ static int nullfs_init_fs_context(struct fs_context *fc)
struct file_system_type nullfs_fs_type = {
.name = "nullfs",
+ .fs_flags = FS_DISALLOW_NOTIFY,
.init_fs_context = nullfs_init_fs_context,
.kill_sb = kill_anon_super,
};
diff --git a/fs/readdir.c b/fs/readdir.c
index 76bb1ae3a4504..f2288841337ad 100644
--- a/fs/readdir.c
+++ b/fs/readdir.c
@@ -87,6 +87,8 @@ EXPORT_SYMBOL(wrap_directory_iterator);
int iterate_dir(struct file *file, struct dir_context *ctx)
{
struct inode *inode = file_inode(file);
+ /* never an entry, never removed: nothing for the lock to keep still */
+ bool locked = !(file->f_op->fop_flags & FOP_IMMUTABLE);
int res = -ENOTDIR;
if (!file->f_op->iterate_shared)
@@ -100,9 +102,11 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
if (res)
goto out;
- res = down_read_killable(&inode->i_rwsem);
- if (res)
- goto out;
+ if (locked) {
+ res = down_read_killable(&inode->i_rwsem);
+ if (res)
+ goto out;
+ }
res = -ENOENT;
if (!IS_DEADDIR(inode)) {
@@ -112,7 +116,8 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
fsnotify_access(file);
file_accessed(file);
}
- inode_unlock_shared(inode);
+ if (locked)
+ inode_unlock_shared(inode);
out:
return res;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index f9d1e05e8ae68..deb411e866617 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1978,6 +1978,8 @@ struct file_operations {
#define FOP_ASYNC_LOCK ((__force fop_flags_t)(1 << 6))
/* File system supports uncached read/write buffered IO */
#define FOP_DONTCACHE ((__force fop_flags_t)(1 << 7))
+/* Never changes and is never removed, readdir of a directory takes no lock */
+#define FOP_IMMUTABLE ((__force fop_flags_t)(1 << 8))
/* Wrap a directory iterator that needs exclusive inode access */
int wrap_directory_iterator(struct file *, struct dir_context *,
@@ -2296,6 +2298,7 @@ struct file_system_type {
#define FS_POWER_FREEZE 256 /* Always freeze on suspend/hibernate */
#define FS_USERNS_MOUNT_RESTRICTED 512 /* Restrict mount in userns if not already visible */
#define FS_USERNS_DELEGATABLE 1024 /* Can be mounted inside userns from outside */
+#define FS_DISALLOW_NOTIFY 2048 /* No fsnotify marks on its objects */
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
int (*init_fs_context)(struct fs_context *);
const struct fs_parameter_spec *parameters;
diff --git a/tools/testing/selftests/filesystems/.gitignore b/tools/testing/selftests/filesystems/.gitignore
index 9eb185fb2f9dd..62f7b1c466497 100644
--- a/tools/testing/selftests/filesystems/.gitignore
+++ b/tools/testing/selftests/filesystems/.gitignore
@@ -7,3 +7,4 @@ anon_inode_test
kernfs_test
idmapped_tmpfile
ustat_test
+rw_hint_test
diff --git a/tools/testing/selftests/filesystems/Makefile b/tools/testing/selftests/filesystems/Makefile
index 03be337c1f351..93e2cc9123b04 100644
--- a/tools/testing/selftests/filesystems/Makefile
+++ b/tools/testing/selftests/filesystems/Makefile
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
CFLAGS += $(KHDR_INCLUDES)
-TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test
+TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test rw_hint_test
TEST_GEN_PROGS += idmapped_tmpfile
TEST_GEN_PROGS_EXTENDED := dnotify_test
diff --git a/tools/testing/selftests/filesystems/empty_mntns/.gitignore b/tools/testing/selftests/filesystems/empty_mntns/.gitignore
index 32125b3eaa801..27bcbcaeb1d19 100644
--- a/tools/testing/selftests/filesystems/empty_mntns/.gitignore
+++ b/tools/testing/selftests/filesystems/empty_mntns/.gitignore
@@ -3,3 +3,5 @@ clone3_empty_mntns_test
empty_mntns_test
overmount_chroot_test
internal_sb_reconfigure_test
+nullfs_atime_test
+root_readdir_test
diff --git a/tools/testing/selftests/filesystems/empty_mntns/Makefile b/tools/testing/selftests/filesystems/empty_mntns/Makefile
index b64818b962ca5..22af2164c54e9 100644
--- a/tools/testing/selftests/filesystems/empty_mntns/Makefile
+++ b/tools/testing/selftests/filesystems/empty_mntns/Makefile
@@ -4,7 +4,9 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
LDLIBS += -lcap
TEST_GEN_PROGS := empty_mntns_test overmount_chroot_test clone3_empty_mntns_test
-TEST_GEN_PROGS += internal_sb_reconfigure_test
+TEST_GEN_PROGS += internal_sb_reconfigure_test nullfs_atime_test root_readdir_test
+
+LOCAL_HDRS += ../readdir_hold.h
include ../../lib.mk
@@ -12,3 +14,4 @@ $(OUTPUT)/empty_mntns_test: ../utils.c
$(OUTPUT)/overmount_chroot_test: ../utils.c
$(OUTPUT)/clone3_empty_mntns_test: ../utils.c
$(OUTPUT)/internal_sb_reconfigure_test: ../utils.c
+$(OUTPUT)/root_readdir_test: LDLIBS += -pthread
diff --git a/tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c b/tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c
new file mode 100644
index 0000000000000..51e34f3c4f541
--- /dev/null
+++ b/tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * The root of every empty mount namespace is the same nullfs inode. A read
+ * of it by one user must not change the access time another user sees.
+ */
+#define _GNU_SOURCE
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
+#include "../../kselftest_harness.h"
+
+#ifndef UNSHARE_EMPTY_MNTNS
+#define UNSHARE_EMPTY_MNTNS 0x00100000
+#endif
+
+enum {
+ CHILD_OK,
+ CHILD_UNSUPPORTED,
+ CHILD_SETUP,
+ CHILD_CHANGED,
+};
+
+static int wait_byte(int fd)
+{
+ char c;
+
+ return read(fd, &c, 1) == 1 ? 0 : -1;
+}
+
+static int send_byte(int fd)
+{
+ return write(fd, "x", 1) == 1 ? 0 : -1;
+}
+
+static int empty_mntns(void)
+{
+ if (!unshare(UNSHARE_EMPTY_MNTNS))
+ return 0;
+ return errno == EINVAL ? CHILD_UNSUPPORTED : CHILD_SETUP;
+}
+
+/* the watcher: stats its root before and after the reader read its own */
+static int watcher(int to_reader, int from_reader)
+{
+ struct stat before, after;
+ int ret;
+
+ ret = empty_mntns();
+ if (ret)
+ return ret;
+ if (stat("/", &before))
+ return CHILD_SETUP;
+ if (send_byte(to_reader) || wait_byte(from_reader))
+ return CHILD_SETUP;
+ if (stat("/", &after))
+ return CHILD_SETUP;
+ if (before.st_atim.tv_sec != after.st_atim.tv_sec ||
+ before.st_atim.tv_nsec != after.st_atim.tv_nsec)
+ return CHILD_CHANGED;
+ return CHILD_OK;
+}
+
+/* the reader: lists its own root, which is the same inode */
+static int reader(int to_watcher, int from_watcher)
+{
+ struct dirent *de;
+ DIR *d;
+ int ret;
+
+ ret = empty_mntns();
+ if (ret)
+ return ret;
+ if (wait_byte(from_watcher))
+ return CHILD_SETUP;
+ d = opendir("/");
+ if (!d)
+ return CHILD_SETUP;
+ while ((de = readdir(d)))
+ ;
+ closedir(d);
+ return send_byte(to_watcher) ? CHILD_SETUP : CHILD_OK;
+}
+
+static int wait_child(pid_t pid)
+{
+ int status;
+
+ if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status))
+ return -1;
+ return WEXITSTATUS(status);
+}
+
+TEST(empty_mntns_root_atime)
+{
+ int to_reader[2], to_watcher[2], w, r;
+ pid_t watcher_pid, reader_pid;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+ ASSERT_EQ(pipe(to_reader), 0);
+ ASSERT_EQ(pipe(to_watcher), 0);
+
+ watcher_pid = fork();
+ ASSERT_GE(watcher_pid, 0);
+ if (watcher_pid == 0)
+ _exit(watcher(to_reader[1], to_watcher[0]));
+ reader_pid = fork();
+ ASSERT_GE(reader_pid, 0);
+ if (reader_pid == 0)
+ _exit(reader(to_watcher[1], to_reader[0]));
+
+ r = wait_child(reader_pid);
+ w = wait_child(watcher_pid);
+ if (r == CHILD_UNSUPPORTED || w == CHILD_UNSUPPORTED)
+ SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
+ EXPECT_EQ(r, CHILD_OK);
+ EXPECT_EQ(w, CHILD_OK)
+ TH_LOG("the access time of the root changed while this namespace did nothing");
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c b/tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c
new file mode 100644
index 0000000000000..0ff5442470270
--- /dev/null
+++ b/tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Reading the root of an empty mount namespace holds nothing that anybody
+ * else waits for: the directory never has an entry, so a readdir stuck in
+ * the page fault of its buffer stalls neither a create nor a lookup in it.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "../../kselftest_harness.h"
+#include "../readdir_hold.h"
+#include "empty_mntns.h"
+
+TEST(readdir_blocks_nobody)
+{
+ struct readdir_hold hold;
+ bool stalled;
+ int dfd;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+ if (readdir_hold_init(&hold))
+ SKIP(return, "test requires userfaultfd");
+ if (unshare(UNSHARE_EMPTY_MNTNS)) {
+ readdir_hold_destroy(&hold);
+ if (errno == EINVAL)
+ SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
+ ASSERT_TRUE(false)
+ TH_LOG("unshare(UNSHARE_EMPTY_MNTNS): %m");
+ }
+ dfd = open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(dfd, 0);
+ ASSERT_EQ(readdir_hold_check(&hold, dfd, &stalled), 0);
+ /* the lookup came back while the readdir was stuck in its fault */
+ EXPECT_FALSE(stalled);
+ close(dfd);
+ readdir_hold_destroy(&hold);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/overlayfs/.gitignore b/tools/testing/selftests/filesystems/overlayfs/.gitignore
index 077f7a1281687..b343cc430051d 100644
--- a/tools/testing/selftests/filesystems/overlayfs/.gitignore
+++ b/tools/testing/selftests/filesystems/overlayfs/.gitignore
@@ -2,3 +2,4 @@
dev_in_maps
set_layers_via_fds
idmapped_mounts
+automount_in_layer
diff --git a/tools/testing/selftests/filesystems/overlayfs/Makefile b/tools/testing/selftests/filesystems/overlayfs/Makefile
index b3185f684add6..382a59bda5e70 100644
--- a/tools/testing/selftests/filesystems/overlayfs/Makefile
+++ b/tools/testing/selftests/filesystems/overlayfs/Makefile
@@ -9,6 +9,7 @@ LOCAL_HDRS += ../wrappers.h log.h
TEST_GEN_PROGS := dev_in_maps
TEST_GEN_PROGS += set_layers_via_fds
TEST_GEN_PROGS += idmapped_mounts
+TEST_GEN_PROGS += automount_in_layer
include ../../lib.mk
diff --git a/tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c b/tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c
new file mode 100644
index 0000000000000..0476c4582bdfc
--- /dev/null
+++ b/tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c
@@ -0,0 +1,174 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * A layer of an overlay is a private clone of the mount it was given and
+ * belongs to no mount namespace. fanotify hands out descriptors on it. An
+ * automount triggered through one has no namespace to go into: the open has
+ * to fail, not oops with namespace_sem held.
+ */
+#define _GNU_SOURCE
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/magic.h>
+#include <sys/fanotify.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/vfs.h>
+
+#include "../../kselftest_harness.h"
+
+#define DIR_LEN 64
+#define PATH_LEN 192
+
+static bool have_fs(const char *name)
+{
+ char line[128];
+ bool found = false;
+ FILE *f;
+
+ f = fopen("/proc/filesystems", "re");
+ if (!f)
+ return false;
+ while (fgets(line, sizeof(line), f)) {
+ char *nl = strchr(line, '\n');
+ char *tab = strchr(line, '\t');
+
+ if (nl)
+ *nl = 0;
+ if (tab && !strcmp(tab + 1, name))
+ found = true;
+ }
+ fclose(f);
+ return found;
+}
+
+static int mnt_id_of(int fd)
+{
+ char path[64], buf[4096], *p;
+ ssize_t n;
+ int info;
+
+ snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd);
+ info = open(path, O_RDONLY | O_CLOEXEC);
+ if (info < 0)
+ return -1;
+ n = read(info, buf, sizeof(buf) - 1);
+ close(info);
+ if (n <= 0)
+ return -1;
+ buf[n] = 0;
+ p = strstr(buf, "mnt_id:");
+ return p ? atoi(p + strlen("mnt_id:")) : -1;
+}
+
+static bool on_debugfs(int fd)
+{
+ struct statfs sf;
+
+ return !fstatfs(fd, &sf) && sf.f_type == DEBUGFS_MAGIC;
+}
+
+FIXTURE(layer) {
+ char base[DIR_LEN];
+ int fan;
+ int evfd; /* on the layer clone of the lower debugfs */
+};
+
+FIXTURE_SETUP(layer)
+{
+ char lower[PATH_LEN], other[PATH_LEN], ovl[PATH_LEN], opts[2 * PATH_LEN + 16];
+ struct fanotify_event_metadata *ev;
+ struct pollfd pfd;
+ char buf[4096];
+ int lfd, lower_id;
+ ssize_t n;
+ DIR *d;
+
+ self->fan = -1;
+ self->evfd = -1;
+ if (geteuid())
+ SKIP(return, "test requires root");
+ if (!have_fs("debugfs") || !have_fs("tracefs"))
+ SKIP(return, "test requires debugfs with the tracefs automount");
+ if (!have_fs("overlay"))
+ SKIP(return, "test requires overlayfs");
+
+ snprintf(self->base, sizeof(self->base), "/tmp/layer.XXXXXX");
+ ASSERT_NE(mkdtemp(self->base), NULL);
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+ ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, "mode=0755"), 0);
+ snprintf(lower, sizeof(lower), "%s/lower", self->base);
+ snprintf(other, sizeof(other), "%s/other", self->base);
+ snprintf(ovl, sizeof(ovl), "%s/ovl", self->base);
+ ASSERT_EQ(mkdir(lower, 0755), 0);
+ ASSERT_EQ(mkdir(other, 0755), 0);
+ ASSERT_EQ(mkdir(ovl, 0755), 0);
+ ASSERT_EQ(mount("debugfs", lower, "debugfs", 0, NULL), 0);
+ snprintf(opts, sizeof(opts), "lowerdir=%s:%s", lower, other);
+ ASSERT_EQ(mount("overlay", ovl, "overlay", MS_RDONLY, opts), 0);
+
+ self->fan = fanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK | FAN_CLOEXEC,
+ O_RDONLY | O_CLOEXEC);
+ ASSERT_GE(self->fan, 0);
+ ASSERT_EQ(fanotify_mark(self->fan, FAN_MARK_ADD | FAN_MARK_FILESYSTEM,
+ FAN_OPEN | FAN_ONDIR, AT_FDCWD, lower), 0);
+ lfd = open(lower, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(lfd, 0);
+ lower_id = mnt_id_of(lfd);
+ close(lfd);
+
+ /* the overlay opens its lower directory through the layer clone */
+ d = opendir(ovl);
+ ASSERT_NE(d, NULL);
+ closedir(d);
+ pfd.fd = self->fan;
+ pfd.events = POLLIN;
+ ASSERT_EQ(poll(&pfd, 1, 5000), 1);
+ n = read(self->fan, buf, sizeof(buf));
+ ASSERT_GT(n, 0);
+ for (ev = (void *)buf; FAN_EVENT_OK(ev, n); ev = FAN_EVENT_NEXT(ev, n)) {
+ if (ev->fd < 0)
+ continue;
+ if (self->evfd < 0 && on_debugfs(ev->fd) &&
+ mnt_id_of(ev->fd) != lower_id)
+ self->evfd = ev->fd;
+ else
+ close(ev->fd);
+ }
+ ASSERT_GE(self->evfd, 0)
+ TH_LOG("no event on the layer clone");
+}
+
+FIXTURE_TEARDOWN(layer)
+{
+ if (self->evfd >= 0)
+ close(self->evfd);
+ if (self->fan >= 0)
+ close(self->fan);
+ umount2(self->base, MNT_DETACH);
+ rmdir(self->base);
+}
+
+TEST_F(layer, automount_below_the_clone_is_refused)
+{
+ struct stat st;
+ int fd;
+
+ /* the automount point is there */
+ ASSERT_EQ(fstatat(self->evfd, "tracing", &st, AT_NO_AUTOMOUNT), 0);
+ /* the clone is in no namespace, so the automount has nowhere to go */
+ fd = openat(self->evfd, "tracing", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ EXPECT_LT(fd, 0);
+ EXPECT_EQ(errno, EINVAL);
+ if (fd >= 0)
+ close(fd);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/readdir_hold.h b/tools/testing/selftests/filesystems/readdir_hold.h
new file mode 100644
index 0000000000000..57eee1bef4700
--- /dev/null
+++ b/tools/testing/selftests/filesystems/readdir_hold.h
@@ -0,0 +1,224 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Hold a readdir of a directory in the page fault of its buffer and see
+ * whether a create and a lookup in that directory wait for it. For a
+ * directory that is permanently empty they must not.
+ */
+#ifndef __SELFTESTS_READDIR_HOLD_H
+#define __SELFTESTS_READDIR_HOLD_H
+
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/userfaultfd.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+
+#define HOLD_FAULT_MS 5000 /* for the reader to reach the fault */
+#define HOLD_QUEUE_MS 2000 /* for the create to queue up behind it */
+#define HOLD_LOOKUP_MS 5000 /* for the lookup to come back */
+
+struct readdir_hold {
+ int uffd;
+ int taskdir; /* /proc/self/task, from before any namespace change */
+ long page_size;
+ char *page; /* faults until released */
+ int dfd;
+ pid_t creator_tid;
+ int created;
+ int done[2]; /* the finder writes a byte when it is back */
+};
+
+/*
+ * The fault happens in the kernel, so the userfaultfd needs CAP_SYS_PTRACE
+ * in the initial user namespace or vm.unprivileged_userfaultfd. Call this
+ * before entering a user namespace.
+ */
+static inline int readdir_hold_init(struct readdir_hold *h)
+{
+ struct uffdio_api api = { .api = UFFD_API };
+
+ h->page = MAP_FAILED;
+ h->page_size = sysconf(_SC_PAGESIZE);
+ h->taskdir = open("/proc/self/task", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ h->uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
+ if (h->uffd < 0 || h->taskdir < 0 || ioctl(h->uffd, UFFDIO_API, &api)) {
+ if (h->uffd >= 0)
+ close(h->uffd);
+ if (h->taskdir >= 0)
+ close(h->taskdir);
+ h->uffd = h->taskdir = -1;
+ return -1;
+ }
+ return 0;
+}
+
+static inline void readdir_hold_destroy(struct readdir_hold *h)
+{
+ if (h->uffd >= 0)
+ close(h->uffd);
+ if (h->taskdir >= 0)
+ close(h->taskdir);
+ h->uffd = h->taskdir = -1;
+}
+
+static inline void *readdir_hold_reader(void *arg)
+{
+ struct readdir_hold *h = arg;
+
+ /* the first byte written to the buffer faults until released */
+ syscall(__NR_getdents64, h->dfd, h->page, h->page_size);
+ return NULL;
+}
+
+static inline void *readdir_hold_creator(void *arg)
+{
+ struct readdir_hold *h = arg;
+
+ h->creator_tid = syscall(__NR_gettid);
+ /* takes the directory lock exclusive before it fails */
+ mkdirat(h->dfd, "x", 0755);
+ __atomic_store_n(&h->created, 1, __ATOMIC_RELEASE);
+ return NULL;
+}
+
+static inline void *readdir_hold_finder(void *arg)
+{
+ struct readdir_hold *h = arg;
+ int fd;
+
+ /* a lookup that misses the dcache takes the lock shared */
+ fd = openat(h->dfd, "no_such_name", O_RDONLY | O_CLOEXEC);
+ if (fd >= 0)
+ close(fd);
+ if (write(h->done[1], "x", 1) != 1)
+ perror("readdir_hold: finder");
+ return NULL;
+}
+
+/* the creator is back, or waits in the kernel for the lock */
+static inline bool readdir_hold_creator_settled(struct readdir_hold *h)
+{
+ char path[32], buf[256], *p;
+ ssize_t n;
+ int fd;
+
+ if (__atomic_load_n(&h->created, __ATOMIC_ACQUIRE))
+ return true;
+ if (!h->creator_tid)
+ return false;
+ snprintf(path, sizeof(path), "%d/stat", h->creator_tid);
+ fd = openat(h->taskdir, path, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return false;
+ n = read(fd, buf, sizeof(buf) - 1);
+ close(fd);
+ if (n <= 0)
+ return false;
+ buf[n] = 0;
+ /* "pid (comm) state ..." */
+ p = strrchr(buf, ')');
+ return p && p[1] == ' ' && p[2] == 'D';
+}
+
+static inline bool readdir_hold_faulted(struct readdir_hold *h)
+{
+ struct pollfd pfd = { .fd = h->uffd, .events = POLLIN };
+ struct uffd_msg msg;
+
+ if (poll(&pfd, 1, HOLD_FAULT_MS) != 1)
+ return false;
+ if (read(h->uffd, &msg, sizeof(msg)) != sizeof(msg))
+ return false;
+ return msg.event == UFFD_EVENT_PAGEFAULT;
+}
+
+/* let the reader go on */
+static inline void readdir_hold_release(struct readdir_hold *h)
+{
+ struct uffdio_copy cp = {
+ .dst = (unsigned long)h->page,
+ .len = h->page_size,
+ };
+ void *zero;
+
+ zero = calloc(1, h->page_size);
+ if (!zero)
+ return;
+ cp.src = (unsigned long)zero;
+ if (ioctl(h->uffd, UFFDIO_COPY, &cp) && errno != EEXIST)
+ perror("readdir_hold: UFFDIO_COPY");
+ free(zero);
+}
+
+/*
+ * A readdir of @dfd that sticks in the fault of its buffer, then a create
+ * and a lookup in @dfd. Whether the lookup came back while the readdir was
+ * still stuck goes to @stalled. Returns -1 when that could not be found
+ * out.
+ */
+static inline int readdir_hold_check(struct readdir_hold *h, int dfd,
+ bool *stalled)
+{
+ pthread_t reader, creator, finder;
+ struct uffdio_register reg = {};
+ struct pollfd pfd;
+ int ret = -1, i;
+
+ h->dfd = dfd;
+ h->created = 0;
+ h->creator_tid = 0;
+ h->page = mmap(NULL, h->page_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (h->page == MAP_FAILED)
+ return -1;
+ reg.range.start = (unsigned long)h->page;
+ reg.range.len = h->page_size;
+ reg.mode = UFFDIO_REGISTER_MODE_MISSING;
+ if (ioctl(h->uffd, UFFDIO_REGISTER, ®) || pipe2(h->done, O_CLOEXEC))
+ goto out_page;
+
+ if (pthread_create(&reader, NULL, readdir_hold_reader, h))
+ goto out_pipe;
+ if (!readdir_hold_faulted(h))
+ goto out_reader;
+ if (pthread_create(&creator, NULL, readdir_hold_creator, h))
+ goto out_reader;
+ for (i = 0; i < HOLD_QUEUE_MS / 10 && !readdir_hold_creator_settled(h); i++)
+ usleep(10000);
+ if (pthread_create(&finder, NULL, readdir_hold_finder, h))
+ goto out_creator;
+
+ pfd.fd = h->done[0];
+ pfd.events = POLLIN;
+ *stalled = poll(&pfd, 1, HOLD_LOOKUP_MS) != 1;
+ ret = 0;
+
+ readdir_hold_release(h);
+ pthread_join(finder, NULL);
+out_creator:
+ if (ret)
+ readdir_hold_release(h);
+ pthread_join(creator, NULL);
+out_reader:
+ if (ret)
+ readdir_hold_release(h);
+ pthread_join(reader, NULL);
+out_pipe:
+ close(h->done[0]);
+ close(h->done[1]);
+out_page:
+ munmap(h->page, h->page_size);
+ h->page = MAP_FAILED;
+ return ret;
+}
+
+#endif /* __SELFTESTS_READDIR_HOLD_H */
diff --git a/tools/testing/selftests/filesystems/rw_hint_test.c b/tools/testing/selftests/filesystems/rw_hint_test.c
new file mode 100644
index 0000000000000..d1930f82f63b5
--- /dev/null
+++ b/tools/testing/selftests/filesystems/rw_hint_test.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * F_SET_RW_HINT is refused on an immutable inode. Nothing is ever written
+ * to it and it may be shared with everybody, like a namespace file or the
+ * root of an empty mount namespace.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
+#include "../kselftest_harness.h"
+
+/* <linux/fs.h> and <linux/fcntl.h> don't mix with the libc headers */
+#ifndef FS_IOC_GETFLAGS
+#define FS_IOC_GETFLAGS _IOR('f', 1, long)
+#define FS_IOC_SETFLAGS _IOW('f', 2, long)
+#endif
+#ifndef FS_IMMUTABLE_FL
+#define FS_IMMUTABLE_FL 0x00000010
+#endif
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+#ifndef F_GET_RW_HINT
+#define F_GET_RW_HINT (F_LINUX_SPECIFIC_BASE + 11)
+#define F_SET_RW_HINT (F_LINUX_SPECIFIC_BASE + 12)
+#endif
+#ifndef RWH_WRITE_LIFE_SHORT
+#define RWH_WRITE_LIFE_SHORT 2
+#endif
+#ifndef UNSHARE_EMPTY_MNTNS
+#define UNSHARE_EMPTY_MNTNS 0x00100000
+#endif
+
+static int set_hint(int fd, uint64_t hint)
+{
+ return fcntl(fd, F_SET_RW_HINT, &hint);
+}
+
+static long get_hint(int fd)
+{
+ uint64_t hint;
+
+ if (fcntl(fd, F_GET_RW_HINT, &hint))
+ return -1;
+ return hint;
+}
+
+TEST(immutable_file)
+{
+ char path[] = "/tmp/rw_hint.XXXXXX";
+ int fd, flags;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+
+ fd = mkstemp(path);
+ ASSERT_GE(fd, 0);
+ unlink(path);
+ ASSERT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0);
+ EXPECT_EQ(get_hint(fd), RWH_WRITE_LIFE_SHORT);
+
+ if (ioctl(fd, FS_IOC_GETFLAGS, &flags)) {
+ close(fd);
+ SKIP(return, "no file attributes on this filesystem");
+ }
+ flags |= FS_IMMUTABLE_FL;
+ ASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, &flags), 0);
+ EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1);
+ EXPECT_EQ(errno, EPERM);
+ flags &= ~FS_IMMUTABLE_FL;
+ ASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, &flags), 0);
+ EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0);
+ close(fd);
+}
+
+TEST(namespace_file)
+{
+ int fd;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+
+ fd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1);
+ EXPECT_EQ(errno, EPERM);
+ close(fd);
+}
+
+TEST(empty_mntns_root)
+{
+ int status;
+ pid_t pid;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ int fd;
+
+ if (unshare(UNSHARE_EMPTY_MNTNS))
+ _exit(errno == EINVAL ? 100 : 1);
+ fd = open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ if (fd < 0)
+ _exit(2);
+ if (set_hint(fd, RWH_WRITE_LIFE_SHORT) == 0)
+ _exit(3);
+ _exit(errno == EPERM ? 0 : 4);
+ }
+ ASSERT_EQ(waitpid(pid, &status, 0), pid);
+ ASSERT_TRUE(WIFEXITED(status));
+ if (WEXITSTATUS(status) == 100)
+ SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
+ EXPECT_EQ(WEXITSTATUS(status), 0);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/umount_propagation/Makefile b/tools/testing/selftests/filesystems/umount_propagation/Makefile
index eb85612abf8d1..31f783a92b231 100644
--- a/tools/testing/selftests/filesystems/umount_propagation/Makefile
+++ b/tools/testing/selftests/filesystems/umount_propagation/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
-TEST_GEN_PROGS := umount_propagation_test shrink_submounts_test
+TEST_GEN_PROGS := umount_propagation_test shrink_submounts_test locked_mount_test
CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
diff --git a/tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c b/tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c
new file mode 100644
index 0000000000000..0799b2ba545d7
--- /dev/null
+++ b/tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c
@@ -0,0 +1,432 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MNT_LOCKED keeps the owner of a user namespace from revealing what a
+ * mount covers. The lock has to be set on the copy in that namespace and
+ * only there, it has to survive the expiry of a mount placed beneath the
+ * locked one, and it has to survive the propagated umount of such a copy.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mount.h>
+#include <sys/prctl.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/wait.h>
+
+#include "../../kselftest_harness.h"
+
+#ifndef MOVE_MOUNT_F_EMPTY_PATH
+#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004
+#endif
+#ifndef MOVE_MOUNT_BENEATH
+#define MOVE_MOUNT_BENEATH 0x00000200
+#endif
+
+#define DIR_LEN 64
+#define PATH_LEN 192
+#define FLAGS (MS_NOSUID | MS_NODEV | MS_NOEXEC)
+
+/* exit codes of the children, each test says what they mean */
+enum {
+ CHILD_OK,
+ CHILD_SETUP,
+ CHILD_STEP1,
+ CHILD_STEP2,
+ CHILD_STEP3,
+ CHILD_STEP4,
+};
+
+static int write_file(const char *path, const char *s)
+{
+ ssize_t n = -1;
+ int fd;
+
+ fd = open(path, O_WRONLY | O_CLOEXEC);
+ if (fd >= 0) {
+ n = write(fd, s, strlen(s));
+ close(fd);
+ }
+ return n == (ssize_t)strlen(s) ? 0 : -1;
+}
+
+static int create_file(const char *path, const char *s)
+{
+ ssize_t n = -1;
+ int fd;
+
+ fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
+ if (fd >= 0) {
+ n = write(fd, s, strlen(s));
+ close(fd);
+ }
+ return n == (ssize_t)strlen(s) ? 0 : -1;
+}
+
+/* Root in a new user namespace with a copy of the mount namespace. */
+static int enter_userns(void)
+{
+ uid_t uid = getuid();
+ gid_t gid = getgid();
+ char map[32];
+
+ prctl(PR_SET_DUMPABLE, 1);
+ if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
+ return -1;
+ if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
+ return -1;
+ snprintf(map, sizeof(map), "0 %d 1", uid);
+ if (write_file("/proc/self/uid_map", map))
+ return -1;
+ snprintf(map, sizeof(map), "0 %d 1", gid);
+ if (write_file("/proc/self/gid_map", map))
+ return -1;
+ return setgid(0) || setuid(0) ? -1 : 0;
+}
+
+static int wait_child(pid_t pid)
+{
+ int status;
+
+ if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status))
+ return -1;
+ return WEXITSTATUS(status);
+}
+
+static int wait_byte(int fd)
+{
+ char c;
+
+ return read(fd, &c, 1) == 1 ? 0 : -1;
+}
+
+static int send_byte(int fd)
+{
+ return write(fd, "x", 1) == 1 ? 0 : -1;
+}
+
+/* A read of @path fails: the file is covered. */
+static bool covered(const char *path)
+{
+ int fd = open(path, O_RDONLY | O_CLOEXEC);
+
+ if (fd >= 0)
+ close(fd);
+ return fd < 0;
+}
+
+FIXTURE(locked_mount) {
+ char base[DIR_LEN];
+ bool tracing; /* debugfs with the tracefs automount is there */
+};
+
+FIXTURE_SETUP(locked_mount)
+{
+ char p[PATH_LEN];
+ struct stat st;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+
+ snprintf(self->base, sizeof(self->base), "/tmp/locked_mount.XXXXXX");
+ ASSERT_NE(mkdtemp(self->base), NULL);
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+ ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, "mode=0755"), 0);
+
+ /* an automount that a user can name: the tracefs below debugfs */
+ snprintf(p, sizeof(p), "%s/dbg", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ self->tracing = !mount("debugfs", p, "debugfs", FLAGS, NULL);
+ if (self->tracing) {
+ /* the cases trigger it themselves */
+ snprintf(p, sizeof(p), "%s/dbg/tracing", self->base);
+ self->tracing = !fstatat(AT_FDCWD, p, &st, AT_NO_AUTOMOUNT) &&
+ S_ISDIR(st.st_mode);
+ }
+}
+
+FIXTURE_TEARDOWN(locked_mount)
+{
+ umount2(self->base, MNT_DETACH);
+ rmdir(self->base);
+}
+
+/*
+ * The child keeps a directory descriptor on the host's debugfs mount, moves
+ * to a user namespace of its own and triggers the automount through the
+ * descriptor. The mount goes below the host's mount and propagates into the
+ * child's copy. The child's copy has to be locked, the host's not.
+ */
+static int automount_child(const char *base, int dfd, int to_host, int from_host)
+{
+ char p[PATH_LEN];
+ struct stat st;
+
+ if (enter_userns())
+ return CHILD_SETUP;
+ if (fstatat(dfd, "tracing/.", &st, 0))
+ return CHILD_STEP1;
+ if (send_byte(to_host) || wait_byte(from_host))
+ return CHILD_SETUP;
+ /* the flags of the copy are locked: EPERM */
+ snprintf(p, sizeof(p), "%s/dbg/tracing", base);
+ if (!mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL) || errno != EPERM)
+ return CHILD_STEP2;
+ return CHILD_OK;
+}
+
+TEST_F(locked_mount, automount_locked_in_the_triggering_namespace)
+{
+ int to_host[2], from_host[2], dfd, ret;
+ char p[PATH_LEN];
+ pid_t pid;
+
+ if (!self->tracing)
+ SKIP(return, "test requires debugfs with the tracefs automount");
+
+ snprintf(p, sizeof(p), "%s/dbg", self->base);
+ ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0);
+ dfd = open(p, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(dfd, 0);
+ ASSERT_EQ(pipe(to_host), 0);
+ ASSERT_EQ(pipe(from_host), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0)
+ _exit(automount_child(self->base, dfd, to_host[1], from_host[0]));
+ close(dfd);
+ ASSERT_EQ(wait_byte(to_host[0]), 0);
+
+ /* the host's own mount isn't locked: the flags can go */
+ snprintf(p, sizeof(p), "%s/dbg/tracing", self->base);
+ EXPECT_EQ(mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL), 0);
+
+ ASSERT_EQ(send_byte(from_host[1]), 0);
+ ret = wait_child(pid);
+ TH_LOG("child exit code %d", ret);
+ EXPECT_EQ(ret, CHILD_OK);
+}
+
+/*
+ * A copy of a tree with a locked cover. The child puts a shrinkable mount
+ * beneath the cover, which hands the lock down, unmounts the cover and then
+ * asks for the umount of an unlocked ancestor. That expires the shrinkable
+ * mount on a kernel that doesn't look at the lock, and the covered
+ * directory is bare.
+ */
+static int expiry_child(const char *base)
+{
+ char srv[PATH_LEN], shr[PATH_LEN], x[PATH_LEN], c[PATH_LEN];
+ char hidden[PATH_LEN], secret[PATH_LEN];
+
+ snprintf(srv, sizeof(srv), "%s/srv", base);
+ snprintf(shr, sizeof(shr), "%s/shr", base);
+ snprintf(x, sizeof(x), "%s/x", base);
+ snprintf(c, sizeof(c), "%s/c", base);
+ snprintf(hidden, sizeof(hidden), "%s/x/hidden", base);
+ snprintf(secret, sizeof(secret), "%s/x/hidden/secret", base);
+
+ if (enter_userns())
+ return CHILD_SETUP;
+ if (mount(srv, x, NULL, MS_BIND | MS_REC, NULL) ||
+ mount(shr, c, NULL, MS_BIND, NULL))
+ return CHILD_SETUP;
+ /* the cover is locked */
+ if (!umount2(hidden, 0) || errno != EINVAL)
+ return CHILD_STEP1;
+ if (syscall(__NR_move_mount, AT_FDCWD, c, AT_FDCWD, hidden, MOVE_MOUNT_BENEATH))
+ return CHILD_STEP2;
+ /* the lock moved down, the cover may go */
+ if (umount2(hidden, 0))
+ return CHILD_STEP3;
+ /* the holder of the lock may not, in any way */
+ if (!umount2(hidden, 0) || errno != EINVAL)
+ return CHILD_STEP4;
+ if (chdir(x))
+ return CHILD_SETUP;
+ umount2(x, 0);
+ return covered(secret) ? CHILD_OK : CHILD_STEP4;
+}
+
+TEST_F(locked_mount, expiry_leaves_a_locked_mount_alone)
+{
+ char p[PATH_LEN], q[PATH_LEN];
+ pid_t pid;
+ int ret;
+
+ if (!self->tracing)
+ SKIP(return, "test requires debugfs with the tracefs automount");
+
+ snprintf(p, sizeof(p), "%s/dbg/tracing", self->base);
+ snprintf(q, sizeof(q), "%s/shr", self->base);
+ ASSERT_EQ(mkdir(q, 0755), 0);
+ /* a bind of an automount is shrinkable as well */
+ ASSERT_EQ(mount(p, q, NULL, MS_BIND, NULL), 0);
+ snprintf(p, sizeof(p), "%s/srv", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
+ snprintf(p, sizeof(p), "%s/srv/hidden", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ snprintf(p, sizeof(p), "%s/srv/hidden/secret", self->base);
+ ASSERT_EQ(create_file(p, "covered-by-root\n"), 0);
+ snprintf(p, sizeof(p), "%s/srv/hidden", self->base);
+ ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
+ snprintf(p, sizeof(p), "%s/x", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ snprintf(p, sizeof(p), "%s/c", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0)
+ _exit(expiry_child(self->base));
+ ret = wait_child(pid);
+ TH_LOG("child exit code %d", ret);
+ EXPECT_EQ(ret, CHILD_OK);
+}
+
+/*
+ * The copy of the mount tree that a user namespace gets at its creation has
+ * the automounts in it locked unless they are on an expiry list. A bind of
+ * such a tree inside the namespace copies the lock to the automount but not
+ * to the root of the bind, so the child may ask for the umount of that root.
+ * That must not expire the locked automount below it: the root is busy, the
+ * umount fails and the automount has to be there afterwards.
+ */
+static int copied_tree_child(const char *base)
+{
+ char dbg[PATH_LEN], x[PATH_LEN], tracing[PATH_LEN];
+ struct stat root, st;
+
+ snprintf(dbg, sizeof(dbg), "%s/dbg", base);
+ snprintf(x, sizeof(x), "%s/x", base);
+ snprintf(tracing, sizeof(tracing), "%s/x/tracing", base);
+
+ if (enter_userns())
+ return CHILD_SETUP;
+ if (mount(dbg, x, NULL, MS_BIND | MS_REC, NULL))
+ return CHILD_SETUP;
+ /* the copy of the automount carries the lock */
+ if (!umount2(tracing, 0) || errno != EINVAL)
+ return CHILD_STEP1;
+ /* the root of the bind doesn't; keep it busy */
+ if (chdir(x))
+ return CHILD_SETUP;
+ if (!umount2(x, 0) || errno != EBUSY)
+ return CHILD_STEP2;
+ /* the automount below it must not have gone */
+ if (stat(x, &root) || fstatat(AT_FDCWD, tracing, &st, AT_NO_AUTOMOUNT))
+ return CHILD_SETUP;
+ return st.st_dev != root.st_dev ? CHILD_OK : CHILD_STEP3;
+}
+
+TEST_F(locked_mount, umount_of_a_bind_leaves_a_locked_automount_alone)
+{
+ char p[PATH_LEN];
+ struct stat st;
+ pid_t pid;
+ int ret;
+
+ if (!self->tracing)
+ SKIP(return, "test requires debugfs with the tracefs automount");
+
+ /* the copy the child gets has to contain the automount */
+ snprintf(p, sizeof(p), "%s/dbg/tracing/.", self->base);
+ ASSERT_EQ(stat(p, &st), 0);
+ snprintf(p, sizeof(p), "%s/x", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0)
+ _exit(copied_tree_child(self->base));
+ ret = wait_child(pid);
+ TH_LOG("child exit code %d", ret);
+ EXPECT_EQ(ret, CHILD_OK);
+}
+
+/*
+ * Z is a user namespace with a copy of a tree in which P/d is covered by a
+ * locked mount. The host mounts X on P/d, which propagates beneath Z's
+ * cover, and unmounts it again. Z's cover has to be locked afterwards as
+ * it was before.
+ */
+static int propagation_child(const char *base, int to_host, int from_host)
+{
+ char d[PATH_LEN], secret[PATH_LEN];
+
+ snprintf(d, sizeof(d), "%s/P/d", base);
+ snprintf(secret, sizeof(secret), "%s/P/d/secret", base);
+
+ if (enter_userns())
+ return CHILD_SETUP;
+ /* the cover is locked */
+ if (!umount2(d, 0) || errno != EINVAL)
+ return CHILD_STEP1;
+ if (send_byte(to_host) || wait_byte(from_host))
+ return CHILD_SETUP;
+ /* X came and went beneath it: still locked */
+ if (!umount2(d, 0) || errno != EINVAL)
+ return CHILD_STEP2;
+ return covered(secret) ? CHILD_OK : CHILD_STEP3;
+}
+
+TEST_F(locked_mount, propagated_copy_keeps_the_cover_locked)
+{
+ int to_host[2], from_host[2], ret;
+ char p[PATH_LEN];
+ pid_t pid;
+
+ snprintf(p, sizeof(p), "%s/P", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
+ ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0);
+ snprintf(p, sizeof(p), "%s/P/d", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ snprintf(p, sizeof(p), "%s/P/d/secret", self->base);
+ ASSERT_EQ(create_file(p, "covered-by-root\n"), 0);
+ ASSERT_EQ(pipe(to_host), 0);
+ ASSERT_EQ(pipe(from_host), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ /* M: a manager's namespace that covers P/d for Z */
+ pid_t z;
+
+ if (unshare(CLONE_NEWNS))
+ _exit(CHILD_SETUP);
+ snprintf(p, sizeof(p), "%s/P", self->base);
+ if (mount(NULL, p, NULL, MS_SLAVE, NULL))
+ _exit(CHILD_SETUP);
+ snprintf(p, sizeof(p), "%s/P/d", self->base);
+ if (mount("tmpfs", p, "tmpfs", 0, "mode=0755"))
+ _exit(CHILD_SETUP);
+ z = fork();
+ if (z < 0)
+ _exit(CHILD_SETUP);
+ if (z == 0)
+ _exit(propagation_child(self->base, to_host[1], from_host[0]));
+ _exit(wait_child(z));
+ }
+ ASSERT_EQ(wait_byte(to_host[0]), 0);
+
+ /* the host mounts on P/d and unmounts again; both propagate */
+ snprintf(p, sizeof(p), "%s/P/d", self->base);
+ ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
+ ASSERT_EQ(umount2(p, 0), 0);
+
+ ASSERT_EQ(send_byte(from_host[1]), 0);
+ ret = wait_child(pid);
+ TH_LOG("child exit code %d", ret);
+ EXPECT_EQ(ret, CHILD_OK);
+}
+
+TEST_HARNESS_MAIN
|
| 3/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24296 output: 24 thoughts: 967 Thoughts: **VFS Patch Analysis and Fuzzing Strategy** Okay, let's break this down systematically. First, I need to determine if this patch is even *worth* fuzzing. We have to consider its impact and potential for triggering vulnerabilities. The patch modifies quite a few core VFS components, that's a good sign. Specifically, these files and functionalities jump out at me: * **`fs/fcntl.c`:** The added immutable check in `fcntl_set_rw_hint` is interesting. Any time we're dealing with access control, it's worth a look. * **`fs/fhandle.c`:** The `subtree_unobstructed` helper affects file handle decoding which is used for things like `open_by_handle_at`, so, potentially security-relevant. * **`fs/namespace.c`:** This is the heart of mount namespace operations. The changes to locking (`has_locked_children`), `attach_recursive_mnt`, `do_lock_mount`, `do_add_mount`, `mark_mounts_for_expiry` (especially with the `VFS_WARN_ON_ONCE`), and `shrink_submount` are all red flags for race conditions and logic errors. The `mark_mounts_for_expiry` change in particular is very interesting. * **`fs/namei.c`:** `unlink_may_reveal` in `step_into_slowpath` is a classic area for TOCTOU bugs or path traversal issues. * **`fs/readdir.c`:** The lockless `readdir` path when `FOP_IMMUTABLE` is set is a good candidate to fuzz in combination with a file system that supports this `FOP_IMMUTABLE` functionality. * **`fs/nullfs.c`, `include/linux/fs.h`, and `fs/notify/mark.c`:** Nullfs modifications plus the `FOP_IMMUTABLE` flag and `FS_DISALLOW_NOTIFY` are interesting. They are likely related and worth investigating as a cohesive unit. This might provide us a new file system to use when fuzzing. My conclusion is that this is *definitely* worth fuzzing. It touches core VFS code in several high-risk areas: mount namespaces, path walking, locking, and file handle operations. The addition of the runtime assertion `VFS_WARN_ON_ONCE` is a big green light. We know fuzzing these changes is likely to be fruitful. Now, let's figure out the best fuzzing strategy. We need to identify relevant configuration options (using `grepper`) and think about FocusSymbols and EnableConfigs. First, let's explore nullfs. What triggers the initialization of this file system? Is it modular or always compiled in? Are there any configuration options to consider? I need to find its Kconfig dependencies to understand whether it is a good target for fuzzing. |
| 4/2 | 2026/10/03 03:35 | tool | grepper |
0mArgs:{
"Expression": "nullfs",
"PathPrefix": "fs/"
}Results: {
"Output": "fs/Makefile=10=obj-y :=\topen.o read_write.o file_table.o super.o \\\n--\nfs/Makefile-18-\t\tkernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \\\nfs/Makefile:19:\t\tfile_attr.o fserror.o nullfs.o failfs.o\nfs/Makefile-20-\n--\nfs/fs_struct.c=155=EXPORT_SYMBOL_GPL(unshare_fs_struct);\n--\nfs/fs_struct.c-181- * Be aggressive about this: We simply reject operating on stale\nfs/fs_struct.c:182: * fs_struct state by reverting to nullfs. Every kworker that does\nfs/fs_struct.c-183- * lookups after this point will fail. Every usermodehelper call will\n--\nfs/fs_struct.c=231=void __init init_userspace_fs(void)\n--\nfs/fs_struct.c-235-\nfs/fs_struct.c:236:\t/* Move PID 1 from nullfs into the initramfs. */\nfs/fs_struct.c-237-\tm = topmost_overmount(current-\u003ensproxy-\u003emnt_ns-\u003eroot);\n--\nfs/mount.h-7-\nfs/mount.h:8:extern struct file_system_type nullfs_fs_type;\nfs/mount.h:9:extern struct vfsmount *knullfs;\nfs/mount.h-10-extern struct list_head notify_list;\n--\nfs/namespace.c=82=static struct kmem_cache *mnt_cache __ro_after_init;\nfs/namespace.c:83:struct vfsmount *knullfs __ro_after_init;\t/* private nullfs instance */\nfs/namespace.c-84-static DECLARE_RWSEM(namespace_sem);\n--\nfs/namespace.c=3173=static struct mnt_namespace *create_new_namespace(struct path *path,\n--\nfs/namespace.c-3204-\nfs/namespace.c:3205:\tVFS_WARN_ON_ONCE(old_ns_root-\u003emnt.mnt_sb-\u003es_type != \u0026nullfs_fs_type);\nfs/namespace.c-3206-\n--\nfs/namespace.c=4792=int path_pivot_root(struct path *new, struct path *old)\n--\nfs/namespace.c-4876- *\nfs/namespace.c:4877: * The immutable nullfs filesystem is mounted as the true root of the VFS\nfs/namespace.c-4878- * hierarchy. The mutable rootfs (tmpfs/ramfs) is layered on top of this,\n--\nfs/namespace.c=6310=struct mnt_namespace init_mnt_ns = {\n--\nfs/namespace.c-6317-\nfs/namespace.c:6318:static void __init mount_rootfs_on_nullfs(struct vfsmount *mnt,\nfs/namespace.c:6319:\t\t\t\t\t struct vfsmount *nullfs_mnt)\nfs/namespace.c-6320-{\nfs/namespace.c-6321-\tstruct path root = {\nfs/namespace.c:6322:\t\t.mnt\t= nullfs_mnt,\nfs/namespace.c:6323:\t\t.dentry\t= nullfs_mnt-\u003emnt_root,\nfs/namespace.c-6324-\t};\n--\nfs/namespace.c-6327-\tif (unlikely(IS_ERR(mp.parent)))\nfs/namespace.c:6328:\t\tpanic(\"VFS: Failed to mount rootfs on nullfs\");\nfs/namespace.c-6329-\tscoped_guard(mount_writer)\n--\nfs/namespace.c=6333=static void __init init_mount_tree(void)\nfs/namespace.c-6334-{\nfs/namespace.c:6335:\tstruct vfsmount *mnt, *nullfs_mnt;\nfs/namespace.c-6336-\tstruct mount *mnt_root;\n--\nfs/namespace.c-6341-\t *\nfs/namespace.c:6342:\t * (1) nullfs with mount id 1\nfs/namespace.c-6343-\t * (2) mutable rootfs with mount id 2\nfs/namespace.c:6344:\t * (3) private nullfs for kthreads (SB_KERNMOUNT), kept in knullfs\nfs/namespace.c-6345-\t *\nfs/namespace.c-6346-\t * with (2) mounted on top of (1). The init_task's root and pwd\nfs/namespace.c:6347:\t * are pointed at (3) so all kthreads start isolated in nullfs.\nfs/namespace.c-6348-\t */\nfs/namespace.c:6349:\tnullfs_mnt = vfs_kern_mount(\u0026nullfs_fs_type, 0, \"nullfs\", NULL);\nfs/namespace.c:6350:\tif (IS_ERR(nullfs_mnt))\nfs/namespace.c:6351:\t\tpanic(\"VFS: Failed to create nullfs\");\nfs/namespace.c-6352-\n--\nfs/namespace.c-6356-\nfs/namespace.c:6357:\tVFS_WARN_ON_ONCE(real_mount(nullfs_mnt)-\u003emnt_id != 1);\nfs/namespace.c-6358-\tVFS_WARN_ON_ONCE(real_mount(mnt)-\u003emnt_id != 2);\nfs/namespace.c-6359-\nfs/namespace.c:6360:\t/* The namespace root is the nullfs mnt. */\nfs/namespace.c:6361:\tmnt_root\t\t= real_mount(nullfs_mnt);\nfs/namespace.c-6362-\tinit_mnt_ns.root\t= mnt_root;\nfs/namespace.c-6363-\nfs/namespace.c:6364:\tmount_rootfs_on_nullfs(mnt, nullfs_mnt);\nfs/namespace.c-6365-\nfs/namespace.c:6366:\tpr_info(\"VFS: Finished mounting rootfs on nullfs\\n\");\nfs/namespace.c-6367-\n--\nfs/namespace.c-6378-\nfs/namespace.c:6379:\tknullfs = kern_mount(\u0026nullfs_fs_type);\nfs/namespace.c:6380:\tif (IS_ERR(knullfs))\nfs/namespace.c:6381:\t\tpanic(\"VFS: Failed to create private nullfs instance\");\nfs/namespace.c-6382-\t/* nothing is ever mounted on the root of a kernel thread */\nfs/namespace.c:6383:\tdont_mount(knullfs-\u003emnt_root);\nfs/namespace.c-6384-\t/* and nothing is ever written through it */\nfs/namespace.c:6385:\tknullfs-\u003emnt_flags |= MNT_READONLY;\nfs/namespace.c:6386:\troot.mnt\t= knullfs;\nfs/namespace.c:6387:\troot.dentry\t= knullfs-\u003emnt_root;\nfs/namespace.c-6388-\n--\nfs/nullfs.c-8-\nfs/nullfs.c:9:static const struct super_operations nullfs_super_operations = {\nfs/nullfs.c-10-\t.statfs\t= simple_statfs,\n--\nfs/nullfs.c-12-\nfs/nullfs.c:13:static loff_t nullfs_dir_llseek(struct file *file, loff_t offset, int whence)\nfs/nullfs.c-14-{\n--\nfs/nullfs.c-18-\nfs/nullfs.c:19:static int nullfs_dir_readdir(struct file *file, struct dir_context *ctx)\nfs/nullfs.c-20-{\n--\nfs/nullfs.c-24-\nfs/nullfs.c:25:/* the one inode of nullfs is shared by every holder, so no locks on it */\nfs/nullfs.c:26:static int nullfs_nolock(struct file *file, int cmd, struct file_lock *fl)\nfs/nullfs.c-27-{\n--\nfs/nullfs.c-31-/* and no leases or delegations */\nfs/nullfs.c:32:static int nullfs_nolease(struct file *file, int arg, struct file_lease **flp,\nfs/nullfs.c-33-\t\t\t void **priv)\n--\nfs/nullfs.c-38-/* what libfs gives an empty directory, plus the refusal of file locks */\nfs/nullfs.c:39:static const struct file_operations nullfs_dir_operations = {\nfs/nullfs.c:40:\t.llseek\t\t= nullfs_dir_llseek,\nfs/nullfs.c-41-\t.read\t\t= generic_read_dir,\nfs/nullfs.c:42:\t.iterate_shared\t= nullfs_dir_readdir,\nfs/nullfs.c-43-\t.fsync\t\t= noop_fsync,\nfs/nullfs.c:44:\t.lock\t\t= nullfs_nolock,\nfs/nullfs.c:45:\t.flock\t\t= nullfs_nolock,\nfs/nullfs.c:46:\t.setlease\t= nullfs_nolease,\nfs/nullfs.c-47-\t.fop_flags\t= FOP_IMMUTABLE,\n--\nfs/nullfs.c-49-\nfs/nullfs.c:50:static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)\nfs/nullfs.c-51-{\n--\nfs/nullfs.c-57-\ts-\u003es_magic\t\t= NULL_FS_MAGIC;\nfs/nullfs.c:58:\ts-\u003es_op\t\t\t= \u0026nullfs_super_operations;\nfs/nullfs.c-59-\ts-\u003es_export_op\t\t= NULL;\n--\nfs/nullfs.c-67-\nfs/nullfs.c:68:\t/* nullfs is permanently empty... */\nfs/nullfs.c-69-\tmake_empty_dir_inode(inode);\nfs/nullfs.c:70:\tinode-\u003ei_fop = \u0026nullfs_dir_operations;\nfs/nullfs.c-71-\tsimple_inode_init_ts(inode);\n--\nfs/nullfs.c-82-\nfs/nullfs.c:83:static int nullfs_fs_get_tree(struct fs_context *fc)\nfs/nullfs.c-84-{\nfs/nullfs.c:85:\treturn get_tree_nodev(fc, nullfs_fs_fill_super);\nfs/nullfs.c-86-}\nfs/nullfs.c-87-\nfs/nullfs.c:88:static const struct fs_context_operations nullfs_fs_context_ops = {\nfs/nullfs.c:89:\t.get_tree\t= nullfs_fs_get_tree,\nfs/nullfs.c-90-};\nfs/nullfs.c-91-\nfs/nullfs.c:92:static int nullfs_init_fs_context(struct fs_context *fc)\nfs/nullfs.c-93-{\nfs/nullfs.c:94:\tfc-\u003eops\t\t= \u0026nullfs_fs_context_ops;\nfs/nullfs.c-95-\tfc-\u003esb_flags\t|= SB_NOUSER;\n--\nfs/nullfs.c-99-\nfs/nullfs.c:100:struct file_system_type nullfs_fs_type = {\nfs/nullfs.c:101:\t.name\t\t\t= \"nullfs\",\nfs/nullfs.c-102-\t.fs_flags\t\t= FS_DISALLOW_NOTIFY,\nfs/nullfs.c:103:\t.init_fs_context\t= nullfs_init_fs_context,\nfs/nullfs.c-104-\t.kill_sb\t\t= kill_anon_super,\n"
} |
| 5/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29034 output: 26 thoughts: 49 Thoughts: Okay, here's my interpretation of those thoughts, presented as my own mental process, given my expertise: **Checking Filesystem Handle Implementation** Alright, so `nullfs.o` is unconditionally built, according to the `fs/Makefile` as an `obj-y`. I need to figure out the status of the file handle implementation though. I need to make sure I know how it's handled, since it is a critical piece of the filesystem. I recall that `fs/fhandle.c` handles that functionality, but I should check the Makefile in `fs/` to confirm that it's compiled. Let me see if there is an `fhandle.o` declared there. |
| 6/2 | 2026/10/03 03:35 | tool | grepper |
0mArgs:{
"Expression": "fhandle\\.o",
"PathPrefix": "fs/"
}Results: {
"Output": "fs/Makefile=48=obj-$(CONFIG_SYSCTL)\t\t+= drop_caches.o sysctls.o\nfs/Makefile-49-\nfs/Makefile:50:obj-$(CONFIG_FHANDLE)\t\t+= fhandle.o\nfs/Makefile-51-obj-y\t\t\t\t+= iomap/\n"
} |
| 7/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29343 output: 27 thoughts: 32 Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person: **Navigating the Build Process** Right, so `CONFIG_FHANDLE` is clearly the key here, and it's compiling `fhandle.o`. Makes sense. Now, I need to understand how this ties into file system notifications, and I suspect a deeper dive is required. My gut feeling tells me the `fsnotify` code is related. Best to check the build rules within `fs/notify/Makefile` directly. That's probably the most efficient way to trace the dependencies and understand where `fhandle.o` fits into the broader picture of file system event monitoring. Let's see what that Makefile reveals. |
| 8/2 | 2026/10/03 03:35 | tool | grepper |
0mArgs:{
"Expression": "mark\\.o",
"PathPrefix": "fs/notify/"
}Results: {
"Output": "fs/notify/Makefile-1-# SPDX-License-Identifier: GPL-2.0\nfs/notify/Makefile:2:obj-$(CONFIG_FSNOTIFY)\t\t+= fsnotify.o notification.o group.o mark.o \\\nfs/notify/Makefile-3-\t\t\t\t fdinfo.o\n"
} |
| 9/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29639 output: 22 thoughts: 39 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Investigating Filesystem Notifications and Empty Mount Namespaces** Alright, *CONFIG_FSNOTIFY* is definitely worth keeping in mind here, as it's directly related to the changes we're exploring. But, specifically, my immediate question is centered around *UNSHARE_EMPTY_MNTNS*. Where exactly is that flag defined and, more importantly, how is it *handled* within the kernel? The implications for our work are significant if we want a complete understanding. It's time to fire up `grepper` and get digging. Let's trace that variable down and see what the code around it is doing. That'll be the best way to get a solid grasp of its impact. |
| 10/2 | 2026/10/03 03:35 | tool | grepper |
0mArgs:{
"Expression": "UNSHARE_EMPTY_MNTNS"
}Results: {
"Output": "drivers/base/devtmpfs.c=412=static noinline int __init devtmpfs_setup(void *p)\n--\ndrivers/base/devtmpfs.c-415-\ndrivers/base/devtmpfs.c:416:\terr = ksys_unshare(UNSHARE_EMPTY_MNTNS);\ndrivers/base/devtmpfs.c-417-\tif (err)\n--\ninclude/uapi/linux/sched.h-53- */\ninclude/uapi/linux/sched.h:54:#define UNSHARE_EMPTY_MNTNS 0x00100000 /* Unshare an empty mount namespace. */\ninclude/uapi/linux/sched.h-55-\n--\nkernel/fork.c=3161=static int check_unshare_flags(unsigned long unshare_flags)\n--\nkernel/fork.c-3164-\t\t\t\tCLONE_VM|CLONE_FILES|CLONE_SYSVSEM|\nkernel/fork.c:3165:\t\t\t\tCLONE_NS_ALL | UNSHARE_EMPTY_MNTNS))\nkernel/fork.c-3166-\t\treturn -EINVAL;\n--\nkernel/fork.c=3236=int ksys_unshare(unsigned long unshare_flags)\n--\nkernel/fork.c-3263-\t */\nkernel/fork.c:3264:\tif (unshare_flags \u0026 UNSHARE_EMPTY_MNTNS)\nkernel/fork.c-3265-\t\tunshare_flags |= CLONE_NEWNS;\n--\nkernel/nsproxy.c=211=int unshare_nsproxy_namespaces(unsigned long unshare_flags,\n--\nkernel/nsproxy.c-225-\t/*\nkernel/nsproxy.c:226:\t * Convert the 32-bit UNSHARE_EMPTY_MNTNS (which aliases\nkernel/nsproxy.c-227-\t * CLONE_PARENT_SETTID) to the unique 64-bit CLONE_EMPTY_MNTNS.\nkernel/nsproxy.c-228-\t */\nkernel/nsproxy.c:229:\tif (flags \u0026 UNSHARE_EMPTY_MNTNS) {\nkernel/nsproxy.c:230:\t\tflags \u0026= ~(u64)UNSHARE_EMPTY_MNTNS;\nkernel/nsproxy.c-231-\t\tflags |= CLONE_EMPTY_MNTNS;\n--\ntools/perf/trace/beauty/include/uapi/linux/sched.h-53- */\ntools/perf/trace/beauty/include/uapi/linux/sched.h:54:#define UNSHARE_EMPTY_MNTNS 0x00100000 /* Unshare an empty mount namespace. */\ntools/perf/trace/beauty/include/uapi/linux/sched.h-55-\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-9- * kernel_clone() before copy_process(), unlike unshare() where it goes\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:10: * through UNSHARE_EMPTY_MNTNS -\u003e CLONE_EMPTY_MNTNS conversion in\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-11- * unshare_nsproxy_namespaces().\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns.h-9-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns.h:10:#ifndef UNSHARE_EMPTY_MNTNS\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns.h:11:#define UNSHARE_EMPTY_MNTNS\t0x00100000\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns.h-12-#endif\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-2-/*\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:3: * Tests for empty mount namespace creation via UNSHARE_EMPTY_MNTNS\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-4- *\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=26=static bool unshare_empty_mntns_supported(void)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-38-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:39:\t\tif (unshare(UNSHARE_EMPTY_MNTNS) \u0026\u0026 errno == EINVAL)\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-40-\t\t\t_exit(1);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=56=FIXTURE_SETUP(empty_mntns)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-58-\tif (!unshare_empty_mntns_supported())\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:59:\t\tSKIP(return, \"UNSHARE_EMPTY_MNTNS not supported\");\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-60-}\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=65=TEST_F(empty_mntns, basic)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-77-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:78:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-79-\t\t\t_exit(2);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-98-/*\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:99: * UNSHARE_EMPTY_MNTNS combined with CLONE_NEWUSER.\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-100- *\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=105=TEST_F(empty_mntns, with_clone_newuser)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-130-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:131:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-132-\t\t\t_exit(5);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-142-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:143:/* UNSHARE_EMPTY_MNTNS combined with other namespace flags */\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-144-TEST_F(empty_mntns, with_other_ns_flags)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-154-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:155:\t\tif (unshare(UNSHARE_EMPTY_MNTNS | CLONE_NEWUTS | CLONE_NEWIPC))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-156-\t\t\t_exit(2);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=168=TEST_F(empty_mntns, eperm_without_caps)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-179-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:180:\t\tif (unshare(UNSHARE_EMPTY_MNTNS) == 0)\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-181-\t\t\t_exit(1);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=193=TEST_F(empty_mntns, many_source_mounts)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-231-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:232:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-233-\t\t\t_exit(9);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=245=TEST_F(empty_mntns, cwd_reset)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-274-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:275:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-276-\t\t\t_exit(7);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=301=TEST_F(empty_mntns, mount_properties)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-314-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:315:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-316-\t\t\t_exit(2);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-345-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:346:/* Consecutive UNSHARE_EMPTY_MNTNS calls produce new namespaces */\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-347-TEST_F(empty_mntns, repeated_unshare)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-359-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:360:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-361-\t\t\t_exit(2);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-367-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:368:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-369-\t\t\t_exit(4);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=386=TEST_F(empty_mntns, root_is_own_parent)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-399-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:400:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-401-\t\t\t_exit(2);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=423=TEST_F(empty_mntns, listmount_single_entry)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-437-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:438:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-439-\t\t\t_exit(2);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c=467=TEST_F(empty_mntns, overmount_tmpfs)\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-481-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:482:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-483-\t\t\t_exit(2);\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-610-/*\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c:611: * Tests below do not require UNSHARE_EMPTY_MNTNS support.\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c-612- */\n--\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c=48=static int empty_mntns_child(void)\n--\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c-53-\t\treturn CHILD_USERNS;\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c:54:\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c-55-\t\treturn CHILD_UNSHARE;\n--\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c=73=FIXTURE_SETUP(internal_sb_reconfigure)\n--\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c-82-\t\t\t_exit(1);\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c:83:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c-84-\t\t\t_exit(1);\n--\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c-88-\tif (!WIFEXITED(status) || WEXITSTATUS(status))\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c:89:\t\tSKIP(return, \"UNSHARE_EMPTY_MNTNS not supported\");\ntools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c-90-}\n--\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c-19-\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c:20:#ifndef UNSHARE_EMPTY_MNTNS\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c:21:#define UNSHARE_EMPTY_MNTNS\t0x00100000\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c-22-#endif\n--\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c=43=static int empty_mntns(void)\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c-44-{\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c:45:\tif (!unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c-46-\t\treturn 0;\n--\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c=101=TEST(empty_mntns_root_atime)\n--\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c-122-\tif (r == CHILD_UNSUPPORTED || w == CHILD_UNSUPPORTED)\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c:123:\t\tSKIP(return, \"UNSHARE_EMPTY_MNTNS not supported\");\ntools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c-124-\tEXPECT_EQ(r, CHILD_OK);\n--\ntools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c=19=TEST(readdir_blocks_nobody)\n--\ntools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c-28-\t\tSKIP(return, \"test requires userfaultfd\");\ntools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c:29:\tif (unshare(UNSHARE_EMPTY_MNTNS)) {\ntools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c-30-\t\treaddir_hold_destroy(\u0026hold);\ntools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c-31-\t\tif (errno == EINVAL)\ntools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c:32:\t\t\tSKIP(return, \"UNSHARE_EMPTY_MNTNS not supported\");\ntools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c-33-\t\tASSERT_TRUE(false)\ntools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c:34:\t\t\tTH_LOG(\"unshare(UNSHARE_EMPTY_MNTNS): %m\");\ntools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c-35-\t}\n--\ntools/testing/selftests/filesystems/rw_hint_test.c-39-#endif\ntools/testing/selftests/filesystems/rw_hint_test.c:40:#ifndef UNSHARE_EMPTY_MNTNS\ntools/testing/selftests/filesystems/rw_hint_test.c:41:#define UNSHARE_EMPTY_MNTNS\t0x00100000\ntools/testing/selftests/filesystems/rw_hint_test.c-42-#endif\n--\ntools/testing/selftests/filesystems/rw_hint_test.c=100=TEST(empty_mntns_root)\n--\ntools/testing/selftests/filesystems/rw_hint_test.c-112-\ntools/testing/selftests/filesystems/rw_hint_test.c:113:\t\tif (unshare(UNSHARE_EMPTY_MNTNS))\ntools/testing/selftests/filesystems/rw_hint_test.c-114-\t\t\t_exit(errno == EINVAL ? 100 : 1);\n--\ntools/testing/selftests/filesystems/rw_hint_test.c-124-\tif (WEXITSTATUS(status) == 100)\ntools/testing/selftests/filesystems/rw_hint_test.c:125:\t\tSKIP(return, \"UNSHARE_EMPTY_MNTNS not supported\");\ntools/testing/selftests/filesystems/rw_hint_test.c-126-\tEXPECT_EQ(WEXITSTATUS(status), 0);\n"
} |
| 11/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35261 output: 22 thoughts: 96 Thoughts: Okay, let's break this down. **Investigating the Implementation of `nullfs`/`UNSHARE_EMPTY_MNTNS`** Right, so I need to track down the origins of `nullfs` and/or `UNSHARE_EMPTY_MNTNS`. The ideal would be to dive into the commit history directly, but I don't have the luxury of a full `git log` tool here. Instead, I'm going to leverage `grepper`. My initial thought is to examine where `UNSHARE_EMPTY_MNTNS` is actually *used* in the kernel, and the most logical places to start poking around would be in core areas like `kernel/fork.c`, `kernel/nsproxy.c`, and `fs/namespace.c`. These are the obvious spots for any functionality related to process forking, namespace management, and file system structure modification. I expect to find the implementation details related to setting the flag there. Since `UNSHARE_EMPTY_MNTNS` might be related to other things, I will check the related flag, `CLONE_EMPTY_MNTNS`, to see if that gives me any other context around how this is handled in the kernel. |
| 12/2 | 2026/10/03 03:35 | tool | grepper |
0mArgs:{
"Expression": "CLONE_EMPTY_MNTNS"
}Results: {
"Output": "fs/namespace.c=4353=struct mnt_namespace *copy_mnt_ns(u64 flags, struct mnt_namespace *ns,\n--\nfs/namespace.c-4378-\nfs/namespace.c:4379:\tif (flags \u0026 CLONE_EMPTY_MNTNS)\nfs/namespace.c-4380-\t\tcopy_flags = 0;\n--\nfs/namespace.c-4385-\nfs/namespace.c:4386:\tif (flags \u0026 CLONE_EMPTY_MNTNS)\nfs/namespace.c-4387-\t\tnew = clone_mnt(old, old-\u003emnt.mnt_root, copy_flags);\n--\nfs/namespace.c-4399-\nfs/namespace.c:4400:\tif (flags \u0026 CLONE_EMPTY_MNTNS) {\nfs/namespace.c-4401-\t\t/*\n--\ninclude/uapi/linux/sched.h-41-#define CLONE_PIDFD_AUTOKILL\t(1ULL \u003c\u003c 36) /* Kill child when clone pidfd closes. */\ninclude/uapi/linux/sched.h:42:#define CLONE_EMPTY_MNTNS\t(1ULL \u003c\u003c 37) /* Create an empty mount namespace. */\ninclude/uapi/linux/sched.h-43-\n--\nkernel/fork.c=2712=pid_t kernel_clone(struct kernel_clone_args *args)\n--\nkernel/fork.c-2725-\t */\nkernel/fork.c:2726:\tif (clone_flags \u0026 CLONE_EMPTY_MNTNS) {\nkernel/fork.c-2727-\t\tclone_flags |= CLONE_NEWNS;\n--\nkernel/fork.c=3007=static bool clone3_args_valid(struct kernel_clone_args *kargs)\n--\nkernel/fork.c-3012-\t CLONE_INTO_CGROUP | CLONE_AUTOREAP | CLONE_NNP |\nkernel/fork.c:3013:\t CLONE_PIDFD_AUTOKILL | CLONE_EMPTY_MNTNS))\nkernel/fork.c-3014-\t\treturn false;\n--\nkernel/nsproxy.c=211=int unshare_nsproxy_namespaces(unsigned long unshare_flags,\n--\nkernel/nsproxy.c-226-\t * Convert the 32-bit UNSHARE_EMPTY_MNTNS (which aliases\nkernel/nsproxy.c:227:\t * CLONE_PARENT_SETTID) to the unique 64-bit CLONE_EMPTY_MNTNS.\nkernel/nsproxy.c-228-\t */\n--\nkernel/nsproxy.c-230-\t\tflags \u0026= ~(u64)UNSHARE_EMPTY_MNTNS;\nkernel/nsproxy.c:231:\t\tflags |= CLONE_EMPTY_MNTNS;\nkernel/nsproxy.c-232-\t}\n--\ntools/perf/trace/beauty/include/uapi/linux/sched.h-41-#define CLONE_PIDFD_AUTOKILL\t(1ULL \u003c\u003c 36) /* Kill child when clone pidfd closes. */\ntools/perf/trace/beauty/include/uapi/linux/sched.h:42:#define CLONE_EMPTY_MNTNS\t(1ULL \u003c\u003c 37) /* Create an empty mount namespace. */\ntools/perf/trace/beauty/include/uapi/linux/sched.h-43-\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-2-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:3: * Tests for empty mount namespace creation via clone3() CLONE_EMPTY_MNTNS\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-4- *\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-6- * namespaces, which is distinct from the unshare() path tested in\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:7: * empty_mntns_test.c. With clone3(), CLONE_EMPTY_MNTNS (0x2000000000ULL)\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-8- * is a 64-bit flag that implies CLONE_NEWNS. The implication happens in\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-9- * kernel_clone() before copy_process(), unlike unshare() where it goes\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:10: * through UNSHARE_EMPTY_MNTNS -\u003e CLONE_EMPTY_MNTNS conversion in\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-11- * unshare_nsproxy_namespaces().\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=33=static pid_t clone3_empty_mntns(uint64_t extra_flags)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-35-\tstruct __clone_args args = {\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:36:\t\t.flags\t\t= CLONE_EMPTY_MNTNS | extra_flags,\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-37-\t\t.exit_signal\t= SIGCHLD,\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=77=FIXTURE_SETUP(clone3_empty_mntns)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-79-\tif (!clone3_empty_mntns_supported())\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:80:\t\tSKIP(return, \"CLONE_EMPTY_MNTNS via clone3 not supported\");\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-81-}\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=83=FIXTURE_TEARDOWN(clone3_empty_mntns) {}\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-85-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:86: * Basic clone3() with CLONE_EMPTY_MNTNS: child gets empty mount namespace\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-87- * with exactly 1 mount and root == cwd.\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=89=TEST_F(clone3_empty_mntns, basic)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-127-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:128: * CLONE_EMPTY_MNTNS implies CLONE_NEWNS. Verify that it works without\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-129- * explicitly setting CLONE_NEWNS (tests fork.c:2627-2630).\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=131=TEST_F(clone3_empty_mntns, implies_newns)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-148-\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:149:\t\t/* Only CLONE_EMPTY_MNTNS, no explicit CLONE_NEWNS. */\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-150-\t\tinner = clone3_empty_mntns(0);\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-171-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:172: * Helper macro: generate a test that clones with CLONE_EMPTY_MNTNS |\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-173- * @extra_flags and verifies the child has exactly one mount.\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=176=TEST_F(clone3_empty_mntns, test_name)\t\t\t\t\t\\\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-202-\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:203:/* Redundant CLONE_NEWNS | CLONE_EMPTY_MNTNS should succeed. */\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-204-TEST_CLONE3_FLAGS(with_explicit_newns, CLONE_NEWNS)\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-205-\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:206:/* CLONE_EMPTY_MNTNS combined with CLONE_NEWUSER. */\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-207-TEST_CLONE3_FLAGS(with_newuser, CLONE_NEWUSER)\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-208-\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:209:/* CLONE_EMPTY_MNTNS combined with other namespace flags. */\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-210-TEST_CLONE3_FLAGS(with_other_ns_flags, CLONE_NEWUTS | CLONE_NEWIPC)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-212-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:213: * CLONE_EMPTY_MNTNS combined with CLONE_NEWPID.\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-214- */\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=215=TEST_F(clone3_empty_mntns, with_newpid)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-247-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:248: * CLONE_EMPTY_MNTNS | CLONE_FS must fail because the implied CLONE_NEWNS\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-249- * and CLONE_FS are mutually exclusive (fork.c:1981).\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=251=TEST_F(clone3_empty_mntns, with_clone_fs_fails)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-259-\t\tstruct __clone_args args = {\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:260:\t\t\t.flags\t\t= CLONE_EMPTY_MNTNS | CLONE_FS,\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-261-\t\t\t.exit_signal\t= SIGCHLD,\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-285-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:286: * CLONE_EMPTY_MNTNS combined with CLONE_PIDFD returns a valid pidfd.\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-287- */\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=288=TEST_F(clone3_empty_mntns, with_pidfd)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-296-\t\tstruct __clone_args args = {\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:297:\t\t\t.flags\t\t= CLONE_EMPTY_MNTNS | CLONE_PIDFD,\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-298-\t\t\t.exit_signal\t= SIGCHLD,\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=333=TEST_F(clone3_empty_mntns, eperm_without_caps)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-364-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:365: * Parent's mount namespace is unaffected after clone3 with CLONE_EMPTY_MNTNS.\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-366- */\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=580=TEST_F(clone3_empty_mntns, child_overmount_tmpfs)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-703-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:704: * Multiple clone3 calls with CLONE_EMPTY_MNTNS produce children with\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-705- * distinct mount namespace root mount IDs.\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=784=TEST_F(clone3_empty_mntns, setns_into_child_mntns)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-856-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:857: * Tests below do not require CLONE_EMPTY_MNTNS support.\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-858- */\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c=863=TEST(unknown_flags_rejected)\n--\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-894-/*\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c:895: * Regular clone3 with CLONE_NEWNS (without CLONE_EMPTY_MNTNS) still\ntools/testing/selftests/filesystems/empty_mntns/clone3_empty_mntns_test.c-896- * copies the full mount tree.\n--\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns.h-13-\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns.h:14:#ifndef CLONE_EMPTY_MNTNS\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns.h:15:#define CLONE_EMPTY_MNTNS\t(1ULL \u003c\u003c 37)\ntools/testing/selftests/filesystems/empty_mntns/empty_mntns.h-16-#endif\n"
} |
| 13/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40166 output: 17 thoughts: 756 Thoughts: **Diving into the Patch: A Detailed Examination** Okay, let's break this down. First, the `fcntl_set_rw_hint` change in `fs/fcntl.c`. It's straightforward: a check for immutable inodes. Seems like the code previously didn't handle this case, and now it's returning -EPERM if the inode is immutable, which is the correct behavior. Makes sense; you wouldn't want to mess with hints on an immutable file. There's a comment noting that nothing is written to it. It's a subtle but important addition. Next, `fs/fhandle.c`. The introduction of `subtree_unobstructed` is the key. It's refactoring the permission checks within the `get_name` function. Before, we were duplicating the logic to determine if a subtree was accessible. Now, we have a clear function that encapsulates this check: basically, is the mount still there, and are we capable of writing to it, and does it not have any locked children? The refactoring is a good step towards improving the readability and maintainability of the code, so kudos to the author. Finally, we've got `fs/namei.c`. This is where it gets interesting, with `unlink_may_reveal`. The code appears to be addressing a potential race condition or security issue related to unlinking files, specifically when dealing with mounts and ".." lookups. It's trying to determine if an unlink operation *might* reveal information about a file that's in the process of being unlinked (but, crucially, *still exists*). The function meticulously checks several conditions to achieve this, including: if we are not following symlinks, a revalidation lookup is not happening, if it's the mount we're traversing, if the name still exists, if it's a mount, and if it's unlinked, and if it's a mount. If the unlink *could* reveal this information, it returns -ESTALE, which is the intended behavior. This is a crucial check to prevent data leakage and other potentially catastrophic events. However, I need to go find where `cant_mount` is defined, so I understand the full context of that check. |
| 14/2 | 2026/10/03 03:35 | tool | grepper |
0mArgs:{
"Expression": "cant_mount"
}Results: {
"Output": "fs/dcache.c=1589=int d_set_mounted(struct dentry *dentry)\n--\nfs/dcache.c-1603-\tspin_lock(\u0026dentry-\u003ed_lock);\nfs/dcache.c:1604:\tif (!d_unlinked(dentry) \u0026\u0026 !cant_mount(dentry)) {\nfs/dcache.c-1605-\t\tret = -EBUSY;\n--\nfs/namei.c=2096=static bool unlink_may_reveal(struct nameidata *nd, int flags,\n--\nfs/namei.c-2107-\t/* only a name on its way out is flagged */\nfs/namei.c:2108:\tif (likely(!cant_mount(dentry)))\nfs/namei.c-2109-\t\treturn false;\n--\nfs/namespace.c=2800=static void do_lock_mount(const struct path *path,\n--\nfs/namespace.c-2817-\t\t\t/* sticky, so it takes no locks to refuse it */\nfs/namespace.c:2818:\t\t\tif (unlikely(cant_mount(dentry))) {\nfs/namespace.c-2819-\t\t\t\tres-\u003eparent = ERR_PTR(-ENOENT);\n--\nfs/namespace.c-2836-\t\t\terr = -EAGAIN;\t\t// something moved, retry\nfs/namespace.c:2837:\t\telse if (unlikely(cant_mount(dentry) || !is_mounted(path-\u003emnt)))\nfs/namespace.c-2838-\t\t\terr = -ENOENT;\t\t// not to be mounted on\n--\nfs/namespace.c=3935=static void lock_mount_exact(const struct path *path,\n--\nfs/namespace.c-3946-\tnamespace_lock();\nfs/namespace.c:3947:\tif (unlikely(cant_mount(dentry)))\nfs/namespace.c-3948-\t\terr = -ENOENT;\n--\ninclude/linux/dcache.h=399=static inline int d_unlinked(const struct dentry *dentry)\n--\ninclude/linux/dcache.h-403-\ninclude/linux/dcache.h:404:static inline int cant_mount(const struct dentry *dentry)\ninclude/linux/dcache.h-405-{\n--\nmm/swapfile.c=3613=SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)\n--\nmm/swapfile.c-3663-\tinode_lock(inode);\nmm/swapfile.c:3664:\tif (d_unlinked(dentry) || cant_mount(dentry)) {\nmm/swapfile.c-3665-\t\terror = -ENOENT;\n"
} |
| 15/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42127 output: 35 thoughts: 1398 Thoughts: **Analysis of Recent Filesystem Changes** Okay, let's break down these filesystem changes. First, in `__detach_mounts`, the addition of `d_drop(dentry)` before detaching mounts is crucial. This is a significant change, probably related to ensuring that the dentry is dropped *before* the mount is detached, which could have implications for how the filesystem handles races during unmount operations. This directly impacts the fundamental structure of the mount detachment process. Next, in `step_into_slowpath`, the check for `cant_mount(dentry)` and `d_unlinked(dentry)` with the `-ESTALE` return is interesting. This looks like a defense against revealing underlying dentries when a file is unlinked or renamed while being accessed. It's a key optimization for preventing information leakage in concurrent environments. The change in `attach_recursive_mnt` regarding `IS_MNT_LOCKED(q)` is noteworthy. The conditional removal of the `MNT_LOCKED` flag, specifically when `child == source_mnt`, means the locking behavior is more refined now. This might be related to managing lock inheritance or propagation within a mount tree, perhaps to prevent unnecessary locking of the source mount during recursive operations. Moving on to user namespaces, the conditional assignment of `user_ns` based on `is_anon_ns(ns)` is expected. The code now correctly handles both anonymous and non-anonymous namespaces, ensuring the correct user namespace is used. In `do_lock_mount`, the use of `cant_mount(dentry)` within a `scoped_guard` and the `-ENOENT` return indicates a fast-fail path for attempted mount operations on dentries that are, for some reason, unusable. This is likely another safety mechanism to prevent errors or hangs during mount attempts, potentially related to handling sticky mounts. The check in `mark_mounts_for_expiry` for `IS_MNT_LOCKED(mnt)` within `VFS_WARN_ON_ONCE` before marking for expiry is an explicit enforcement of a locking invariant. It's a strong indication that mounts shouldn't be locked when they are scheduled for expiry. This is critical for preventing deadlocks during mount cleanup, possibly by ensuring that any lock held on the mount is explicitly released before it's marked as expired. In `shrink_submount`, the check for `IS_MNT_LOCKED(mnt)` *before* attempting unmount operations reinforces a similar principle: a locked mount can't be automatically shrunk. The inclusion of `propagate_mount_busy(mnt, 1)` further solidifies this point, indicating that the system's focus is on protecting locked mounts. The introduction of `nullfs_dir_operations` in `fs/nullfs.c` with its immutability flags is new, and interesting. The immutability flags (`FOP_IMMUTABLE`, `nullfs_nolock`, etc.) suggest a simplified, read-only directory structure. Finally, the most interesting point. The `iterate_dir` modification, specifically the conditional `down_read_killable(&inode->i_rwsem)` based on the `FOP_IMMUTABLE` flag is crucial. By *not* taking the read lock if the file operation is immutable, they're optimizing for this specific type of filesystem. The omission of the read lock is coupled with the skipped inode unlock, which means that the filesystem can avoid the overhead of locking if it does not require it. The `fsnotify_access(file)` and `file_accessed(file)` are still called. The changes in `iterate_dir` mean the filesystem should be fast and simple. The `FS_DISALLOW_NOTIFY` flag being set in `nullfs_fs_type` is the last piece. This means files in the nullfs filesystem will *not* be watched. Now, let's look at `fs/notify/mark.c` around line 903 to get some context... |
| 16/2 | 2026/10/03 03:35 | tool | read-file |
0mArgs:{
"File": "fs/notify/mark.c",
"FirstLine": 895,
"LineCount": 30
}Results: {
"Contents": " 895:\t{\n 896:\t\tstruct super_block *sb = fsnotify_object_sb(obj, obj_type);\n 897:\t\tstruct fsnotify_mark *lmark, *last = NULL;\n 898:\t\tstruct fsnotify_mark_connector *conn;\n 899:\t\tfsnotify_connp_t *connp;\n 900:\t\tint cmp;\n 901:\t\tint err = 0;\n 902:\t\n 903:\t\tif (WARN_ON(!fsnotify_valid_obj_type(obj_type)))\n 904:\t\t\treturn -EINVAL;\n 905:\t\n 906:\t\t/* the filesystem doesn't want its objects watched */\n 907:\t\tif (sb \u0026\u0026 (sb-\u003es_type-\u003efs_flags \u0026 FS_DISALLOW_NOTIFY))\n 908:\t\t\treturn -EINVAL;\n 909:\t\n 910:\t\t/*\n 911:\t\t * Attach the sb info before attaching a connector to any object on sb.\n 912:\t\t * The sb info will remain attached as long as sb lives.\n 913:\t\t */\n 914:\t\tif (sb \u0026\u0026 !fsnotify_sb_info(sb)) {\n 915:\t\t\terr = fsnotify_attach_info_to_sb(sb);\n 916:\t\t\tif (err)\n 917:\t\t\t\treturn err;\n 918:\t\t}\n 919:\t\n 920:\t\tconnp = fsnotify_object_connp(obj, obj_type);\n 921:\trestart:\n 922:\t\tspin_lock(\u0026mark-\u003elock);\n 923:\t\tconn = fsnotify_grab_connector(connp);\n 924:\t\tif (!conn) {\n"
} |
| 17/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 44880 output: 34 thoughts: 40 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into `fhandle.c` to Analyze Subtree Obstruction** Alright, so the task at hand requires a deep dive into the handling of file handles, specifically how we determine if a subtree is "unobstructed." My first instinct, given the context, is to zero in on the `subtree_unobstructed` function. I need to understand its logic, its dependencies, and what potential edge cases it might need to address. This function is, in all probability, where the core determination happens. Therefore, I'm heading straight to `fs/fhandle.c` to get a close look. Let's see... a quick mental note... I seem to recall that the critical code for `subtree_unobstructed` is likely somewhere around line 298. That's a good starting point. I'll focus my attention on that vicinity to get the details I require. Time to start digging! |
| 18/2 | 2026/10/03 03:35 | tool | read-file |
0mArgs:{
"File": "fs/fhandle.c",
"FirstLine": 295,
"LineCount": 65
}Results: {
"Contents": " 295:\t\t */\n 296:\t\tguard(rcu)();\n 297:\t\tmnt_ns = READ_ONCE(mount-\u003emnt_ns);\n 298:\t\treturn mnt_ns \u0026\u0026 ns_capable(mnt_ns-\u003euser_ns, CAP_SYS_ADMIN);\n 299:\t}\n 300:\t\n 301:\t/*\n 302:\t * Does the caller have an unobstructed way to everything below @root? Only\n 303:\t * if the mount is mounted, the caller is privileged over its mount namespace\n 304:\t * and no locked child covers something below @root-\u003edentry. One answer from\n 305:\t * under mount_lock: an umount in between clears -\u003emnt_ns and takes the\n 306:\t * children off the mount, the locked ones too.\n 307:\t */\n 308:\tstatic bool subtree_unobstructed(const struct path *root)\n 309:\t{\n 310:\t\tstruct mount *mnt = real_mount(root-\u003emnt);\n 311:\t\n 312:\t\tguard(mount_locked_reader)();\n 313:\t\treturn is_mounted(root-\u003emnt) \u0026\u0026 capable_wrt_mount(mnt) \u0026\u0026\n 314:\t\t !has_locked_children(mnt, root-\u003edentry);\n 315:\t}\n 316:\t\n 317:\tstatic inline int may_decode_fh(struct handle_to_path_ctx *ctx,\n 318:\t\t\t\t\tunsigned int o_flags)\n 319:\t{\n 320:\t\tstruct path *root = \u0026ctx-\u003eroot;\n 321:\t\n 322:\t\tif (capable(CAP_DAC_READ_SEARCH))\n 323:\t\t\treturn 0;\n 324:\t\n 325:\t\t/*\n 326:\t\t * Allow relaxed permissions of file handles if the caller has\n 327:\t\t * the ability to mount the filesystem or create a bind-mount of\n 328:\t\t * the provided @mountdirfd.\n 329:\t\t *\n 330:\t\t * In both cases the caller may be able to get an unobstructed\n 331:\t\t * way to the encoded file handle. If the caller is only able to\n 332:\t\t * create a bind-mount we need to verify that there are no\n 333:\t\t * locked mounts on top of it that could prevent us from getting\n 334:\t\t * to the encoded file.\n 335:\t\t *\n 336:\t\t * In principle, locked mounts can prevent the caller from\n 337:\t\t * mounting the filesystem but that only applies to procfs and\n 338:\t\t * sysfs neither of which support decoding file handles.\n 339:\t\t *\n 340:\t\t * Restrict to O_DIRECTORY to provide a deterministic API that\n 341:\t\t * avoids a confusing api in the face of disconnected non-dir\n 342:\t\t * dentries.\n 343:\t\t *\n 344:\t\t * There's only one dentry for each directory inode (VFS rule)...\n 345:\t\t */\n 346:\t\tif (!(o_flags \u0026 O_DIRECTORY))\n 347:\t\t\treturn -EPERM;\n 348:\t\n 349:\t\tif (ns_capable(root-\u003emnt-\u003emnt_sb-\u003es_user_ns, CAP_SYS_ADMIN))\n 350:\t\t\tctx-\u003eflags = HANDLE_CHECK_PERMS;\n 351:\t\telse if (subtree_unobstructed(root))\n 352:\t\t\tctx-\u003eflags = HANDLE_CHECK_PERMS | HANDLE_CHECK_SUBTREE;\n 353:\t\telse\n 354:\t\t\treturn -EPERM;\n 355:\t\n 356:\t\t/* Are we able to override DAC permissions? */\n 357:\t\tif (!ns_capable(current_user_ns(), CAP_DAC_READ_SEARCH))\n 358:\t\t\treturn -EPERM;\n 359:\t\n"
} |
| 19/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46194 output: 35 thoughts: 34 Thoughts: Okay, here's my take on those code snippets, thinking through the process as if I were analyzing them myself: **Diving into `fs/namei.c`** Alright, time to crack open `fs/namei.c`. Let's see what's going on under the hood of filename lookup. My focus right now is going to be specifically on understanding how the slow path works, which will probably involve `step_into_slowpath`. I need to get a clear picture of how the kernel handles more complex name resolution scenarios – the stuff that's not the straightforward, direct lookup. Also, I want to understand how potential security considerations regarding revealing information are handled, so I will also examine `unlink_may_reveal`. The goal is to fully understand potential vulnerabilities. |
| 20/2 | 2026/10/03 03:35 | tool | read-file |
0mArgs:{
"File": "fs/namei.c",
"FirstLine": 2115,
"LineCount": 45
}Results: {
"Contents": "2115:\t\n2116:\t/*\n2117:\t * Do we need to follow links? We _really_ want to be able\n2118:\t * to do this check without having to look at inode-\u003ei_op,\n2119:\t * so we keep a cache of \"no, this doesn't need follow_link\"\n2120:\t * for the common case.\n2121:\t *\n2122:\t * NOTE: dentry must be what nd-\u003enext_seq had been sampled from.\n2123:\t */\n2124:\tstatic noinline const char *step_into_slowpath(struct nameidata *nd, int flags,\n2125:\t\t\t struct dentry *dentry)\n2126:\t{\n2127:\t\tstruct path path;\n2128:\t\tstruct inode *inode;\n2129:\t\tint err;\n2130:\t\n2131:\t\terr = handle_mounts(nd, dentry, \u0026path);\n2132:\t\tif (unlikely(err \u003c 0))\n2133:\t\t\treturn ERR_PTR(err);\n2134:\t\tinode = path.dentry-\u003ed_inode;\n2135:\t\tif (likely(!d_is_symlink(path.dentry)) ||\n2136:\t\t ((flags \u0026 WALK_TRAILING) \u0026\u0026 !(nd-\u003eflags \u0026 LOOKUP_FOLLOW)) ||\n2137:\t\t (flags \u0026 WALK_NOFOLLOW)) {\n2138:\t\t\t/* not a symlink or should not follow */\n2139:\t\t\tif (nd-\u003eflags \u0026 LOOKUP_RCU) {\n2140:\t\t\t\tif (read_seqcount_retry(\u0026path.dentry-\u003ed_seq, nd-\u003enext_seq))\n2141:\t\t\t\t\treturn ERR_PTR(-ECHILD);\n2142:\t\t\t\tif (unlikely(!inode))\n2143:\t\t\t\t\treturn ERR_PTR(-ENOENT);\n2144:\t\t\t} else {\n2145:\t\t\t\tif (unlikely(unlink_may_reveal(nd, flags, \u0026path, dentry)))\n2146:\t\t\t\t\treturn ERR_PTR(-ESTALE);\n2147:\t\t\t\tdput(nd-\u003epath.dentry);\n2148:\t\t\t\tif (nd-\u003epath.mnt != path.mnt)\n2149:\t\t\t\t\tmntput(nd-\u003epath.mnt);\n2150:\t\t\t}\n2151:\t\t\tnd-\u003epath = path;\n2152:\t\t\tnd-\u003einode = inode;\n2153:\t\t\tnd-\u003eseq = nd-\u003enext_seq;\n2154:\t\t\treturn NULL;\n2155:\t\t}\n2156:\t\treturn pick_link(nd, \u0026path, inode, flags);\n2157:\t}\n2158:\t\n2159:\tstatic __always_inline const char *step_into(struct nameidata *nd, int flags,\n"
} |
| 21/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 47164 output: 34 thoughts: 19 Thoughts: Here's my take on those thoughts: **Peering into the Mount Namespace Detachment Logic** Okay, so I'm thinking, "Where's the action happening when a mount is detached?" I need to dig into the heart of the Linux filesystem namespace code to understand this process fully. Let's start by looking at `__detach_mounts` in `fs/namespace.c`. That function seems like the logical place to begin unraveling how these things get handled at the kernel level. I'm hoping to understand the exact mechanics of how a mount is detached from a namespace and what effects that has on the file system hierarchy. Knowing this should help in debugging any unexpected mount behavior I might encounter, or help me contribute to this code. |
| 22/2 | 2026/10/03 03:35 | tool | read-file |
0mArgs:{
"File": "fs/namespace.c",
"FirstLine": 2005,
"LineCount": 35
}Results: {
"Contents": "2005:\tvoid __detach_mounts(struct dentry *dentry)\n2006:\t{\n2007:\t\tstruct pinned_mountpoint mp = {};\n2008:\t\tstruct mount *mnt;\n2009:\t\n2010:\t\tguard(namespace_excl)();\n2011:\t\tguard(mount_writer)();\n2012:\t\n2013:\t\tif (!lookup_mountpoint(dentry, \u0026mp))\n2014:\t\t\treturn;\n2015:\t\n2016:\t\t/* the name goes first, what covered it goes second */\n2017:\t\td_drop(dentry);\n2018:\t\tevent++;\n2019:\t\twhile (mp.node.next) {\n2020:\t\t\tmnt = hlist_entry(mp.node.next, struct mount, mnt_mp_list);\n2021:\t\t\tif (mnt-\u003emnt.mnt_flags \u0026 MNT_UMOUNT) {\n2022:\t\t\t\tumount_mnt(mnt);\n2023:\t\t\t\thlist_add_head(\u0026mnt-\u003emnt_umount, \u0026unmounted);\n2024:\t\t\t}\n2025:\t\t\telse umount_tree(mnt, UMOUNT_CONNECTED);\n2026:\t\t}\n2027:\t\tunpin_mountpoint(\u0026mp);\n2028:\t}\n2029:\t\n2030:\t/*\n2031:\t * Is the caller allowed to modify his namespace?\n2032:\t */\n2033:\tbool may_mount(void)\n2034:\t{\n2035:\t\treturn ns_capable(current-\u003ensproxy-\u003emnt_ns-\u003euser_ns, CAP_SYS_ADMIN);\n2036:\t}\n2037:\t\n2038:\tstatic void warn_mandlock(void)\n2039:\t{\n"
} |
| 23/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 47866 output: 27 thoughts: 15 Thoughts: Okay, here's my summary, tailored for an expert audience, as if I'm thinking these things myself: **Investigating the `has_locked_children` Function** Alright, I need to get a handle on `has_locked_children`. First things first, let's trace its usage. I need to understand where it's being called – what are its dependencies? I'm thinking about the control flow, the data that's being passed in, and how its return value is being used within the larger system. Understanding the callers will illuminate its purpose in the broader context. Then, I'll switch gears and analyze the declaration itself. I need to understand the function signature, its parameters (data types, etc.), and the underlying logic of the function. I want to see how it determines whether or not a child is locked. What data structures are involved? What locks, if any, are used within the function itself? I want to confirm my understanding of it's operation. I want to build a mental model of its behavior before going any deeper. |
| 24/2 | 2026/10/03 03:35 | tool | grepper |
0mArgs:{
"Expression": "has_locked_children",
"PathPrefix": "fs/"
}Results: {
"Output": "fs/fhandle.c=308=static bool subtree_unobstructed(const struct path *root)\n--\nfs/fhandle.c-313-\treturn is_mounted(root-\u003emnt) \u0026\u0026 capable_wrt_mount(mnt) \u0026\u0026\nfs/fhandle.c:314:\t !has_locked_children(mnt, root-\u003edentry);\nfs/fhandle.c-315-}\n--\nfs/mount.h=212=static inline void move_from_ns(struct mount *mnt)\n--\nfs/mount.h-225-\nfs/mount.h:226:bool has_locked_children(struct mount *mnt, struct dentry *dentry);\nfs/mount.h-227-struct mnt_namespace *get_sequential_mnt_ns(struct mnt_namespace *mnt_ns,\n--\nfs/namespace.c=2324=void dissolve_on_fput(struct vfsmount *mnt)\n--\nfs/namespace.c-2356-/* locks: namespace_shared \u0026\u0026 pinned(mnt) || mount_locked_reader */\nfs/namespace.c:2357:bool has_locked_children(struct mount *mnt, struct dentry *dentry)\nfs/namespace.c-2358-{\n--\nfs/namespace.c=2411=struct vfsmount *clone_private_mount(const struct path *path)\n--\nfs/namespace.c-2438-\nfs/namespace.c:2439:\tif (has_locked_children(old_mnt, path-\u003edentry))\nfs/namespace.c-2440-\t\treturn ERR_PTR(-EINVAL);\n--\nfs/namespace.c=3041=static struct mount *__do_loopback(const struct path *old_path,\n--\nfs/namespace.c-3058-\nfs/namespace.c:3059:\tif (!recurse \u0026\u0026 has_locked_children(old, old_path-\u003edentry))\nfs/namespace.c-3060-\t\treturn ERR_PTR(-EINVAL);\n--\nfs/namespace.c=3517=static int do_set_group(const struct path *from_path, const struct path *to_path)\n--\nfs/namespace.c-3546-\t/* From mount should not have locked children in place of To's root */\nfs/namespace.c:3547:\tif (has_locked_children(from, to-\u003emnt.mnt_root))\nfs/namespace.c-3548-\t\treturn -EINVAL;\n"
} |
| 25/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48769 output: 34 thoughts: 140 Thoughts: Okay, here's my take on those changes. **Deconstructing the Locking Logic** Alright, I'm digging into this code and noticing a shift in how we're handling locked children. Previously, when dealing with `has_locked_children`, the code block acquired the `guard(mount_locked_reader)()` and then called the function, which was called `__has_locked_children`. Now, it seems like `__has_locked_children` has been renamed to just `has_locked_children`. This subtle rename is important. More importantly, the caller of `has_locked_children` now needs to satisfy a more complex lock acquisition criteria: `namespace_shared && pinned(mnt) || mount_locked_reader`. This suggests a potential refactoring to make the code more efficient, and I'll have to consider how this affects the potential for lock contention. I'm also seeing an example of this change in `fhandle.c`. The `guard(mount_locked_reader)()` was added to `subtree_unobstructed` before calling `has_locked_children(mnt, root->dentry)`. This makes sense, as the lock ensures the state of the subtree is stable before we evaluate its "unobstructed" status. That seems to fit the pattern. Okay, let's now switch gears and see how this plays out in `fs/namespace.c` when we're dealing with `mark_mounts_for_expiry`. This function is critical for maintaining consistency in the mount namespace. I'll need to see how the lock acquisition and the `has_locked_children` check intersect with the mount expiry process. |
| 26/2 | 2026/10/03 03:35 | tool | read-file |
0mArgs:{
"File": "fs/namespace.c",
"FirstLine": 4025,
"LineCount": 45
}Results: {
"Contents": "4025:\t\tguard(mount_writer)();\n4026:\t\n4027:\t\t/* extract from the expiration list every vfsmount that matches the\n4028:\t\t * following criteria:\n4029:\t\t * - already mounted\n4030:\t\t * - only referenced by its parent vfsmount\n4031:\t\t * - still marked for expiry (marked on the last call here; marks are\n4032:\t\t * cleared by mntput())\n4033:\t\t */\n4034:\t\tlist_for_each_entry_safe(mnt, next, mounts, mnt_expire) {\n4035:\t\t\tif (!is_mounted(\u0026mnt-\u003emnt))\n4036:\t\t\t\tcontinue;\n4037:\t\t\t/* lock_mnt_tree() leaves expirable mounts alone */\n4038:\t\t\tVFS_WARN_ON_ONCE(IS_MNT_LOCKED(mnt));\n4039:\t\t\tif (!xchg(\u0026mnt-\u003emnt_expiry_mark, 1) ||\n4040:\t\t\t\tpropagate_mount_busy(mnt, 1))\n4041:\t\t\t\tcontinue;\n4042:\t\t\tlist_move(\u0026mnt-\u003emnt_expire, \u0026graveyard);\n4043:\t\t}\n4044:\t\twhile (!list_empty(\u0026graveyard)) {\n4045:\t\t\tmnt = list_first_entry(\u0026graveyard, struct mount, mnt_expire);\n4046:\t\t\t/* an earlier umount_tree() may have moved a busy mount here */\n4047:\t\t\tif (propagate_mount_busy(mnt, 1)) {\n4048:\t\t\t\tlist_move(\u0026mnt-\u003emnt_expire, mounts);\n4049:\t\t\t\tcontinue;\n4050:\t\t\t}\n4051:\t\t\ttouch_mnt_namespace(mnt-\u003emnt_ns);\n4052:\t\t\tumount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);\n4053:\t\t}\n4054:\t}\n4055:\t\n4056:\tEXPORT_SYMBOL_GPL(mark_mounts_for_expiry);\n4057:\t\n4058:\t/*\n4059:\t * Unmount @mnt if it's a shrinkable mount without children that nobody uses.\n4060:\t *\n4061:\t * mount_lock must be held for write\n4062:\t */\n4063:\tstatic bool shrink_submount(struct mount *mnt)\n4064:\t{\n4065:\t\t/* not the kernel's to remove either */\n4066:\t\tif (IS_MNT_LOCKED(mnt) || propagate_mount_busy(mnt, 1))\n4067:\t\t\treturn false;\n4068:\t\ttouch_mnt_namespace(mnt-\u003emnt_ns);\n4069:\t\tumount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);\n"
} |
| 27/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50041 output: 25 thoughts: 52 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience: **Investigating a Recent VFS Change** Hmm, interesting. I see a new addition: `VFS_WARN_ON_ONCE(IS_MNT_LOCKED(mnt));`. My spidey-sense is tingling. That `VFS_WARN_ON_ONCE` construct is unfamiliar. It's often a good indicator of a recently added debugging or robustness check. Let's dig in a bit. Time to do a quick grep search for `VFS_WARN_ON_ONCE` to see where else it's used in the VFS code. Understanding its implementation will give me a better grasp of the potential implications of this new assertion. I'm especially keen to see the conditions under which it triggers and the usual call stacks that involve it. This could be a critical change to evaluate. |
| 28/2 | 2026/10/03 03:35 | tool | grepper |
0mArgs:{
"Expression": "#define VFS_WARN_ON_ONCE"
}Results: {
"Output": "include/linux/vfsdebug.h=10=void dump_inode(struct inode *inode, const char *reason);\n--\ninclude/linux/vfsdebug.h-13-#define VFS_WARN_ON(cond) (void)WARN_ON(cond)\ninclude/linux/vfsdebug.h:14:#define VFS_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)\ninclude/linux/vfsdebug.h-15-#define VFS_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format)\n--\ninclude/linux/vfsdebug.h-36-#define VFS_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)\ninclude/linux/vfsdebug.h:37:#define VFS_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)\ninclude/linux/vfsdebug.h-38-#define VFS_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)\n"
} |
| 29/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50574 output: 35 thoughts: 32 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Investigating `VFS_WARN_ON_ONCE` Usage** Alright, let's dive into the specifics of when `VFS_WARN_ON_ONCE` is actually activated within the kernel's file system infrastructure. I need to understand the contexts in which this warning mechanism triggers, which, in turn, helps me to assess potential subtle issues or coding practices within a complex file system. To get to the bottom of this, I'll need to dig into the source code where it's defined and used. My immediate task, then, is to begin by examining the macro's definition. The logical place to start is the header file where it resides. So, I need to open and read `include/linux/vfsdebug.h` – that's where the relevant pieces of the puzzle should be. I'm after the conditions and arguments involved that determine when the warning is actually emitted. |
| 30/2 | 2026/10/03 03:35 | tool | read-file |
0mArgs:{
"File": "include/linux/vfsdebug.h",
"FirstLine": 1,
"LineCount": 45
}Results: {
"Contents": " 1:\t/* SPDX-License-Identifier: GPL-2.0 */\n 2:\t#ifndef LINUX_VFS_DEBUG_H\n 3:\t#define LINUX_VFS_DEBUG_H 1\n 4:\t\n 5:\t#include \u003clinux/bug.h\u003e\n 6:\t\n 7:\tstruct inode;\n 8:\t\n 9:\t#ifdef CONFIG_DEBUG_VFS\n 10:\tvoid dump_inode(struct inode *inode, const char *reason);\n 11:\t\n 12:\t#define VFS_BUG_ON(cond) BUG_ON(cond)\n 13:\t#define VFS_WARN_ON(cond) (void)WARN_ON(cond)\n 14:\t#define VFS_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)\n 15:\t#define VFS_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format)\n 16:\t#define VFS_WARN(cond, format...) (void)WARN(cond, format)\n 17:\t\n 18:\t#define VFS_BUG_ON_INODE(cond, inode)\t\t({\t\t\t\\\n 19:\t\tif (unlikely(!!(cond))) {\t\t\t\t\t\\\n 20:\t\t\tdump_inode(inode, \"VFS_BUG_ON_INODE(\" #cond\")\");\\\n 21:\t\t\tBUG_ON(1);\t\t\t\t\t\t\\\n 22:\t\t}\t\t\t\t\t\t\t\t\\\n 23:\t})\n 24:\t\n 25:\t#define VFS_WARN_ON_INODE(cond, inode)\t\t({\t\t\t\\\n 26:\t\tint __ret_warn = !!(cond);\t\t\t\t\t\\\n 27:\t\t\t\t\t\t\t\t\t\t\\\n 28:\t\tif (unlikely(__ret_warn)) {\t\t\t\t\t\\\n 29:\t\t\tdump_inode(inode, \"VFS_WARN_ON_INODE(\" #cond\")\");\\\n 30:\t\t\tWARN_ON(1);\t\t\t\t\t\t\\\n 31:\t\t}\t\t\t\t\t\t\t\t\\\n 32:\t\tunlikely(__ret_warn);\t\t\t\t\t\t\\\n 33:\t})\n 34:\t#else\n 35:\t#define VFS_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)\n 36:\t#define VFS_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)\n 37:\t#define VFS_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)\n 38:\t#define VFS_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)\n 39:\t#define VFS_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond)\n 40:\t\n 41:\t#define VFS_BUG_ON_INODE(cond, inode) VFS_BUG_ON(cond)\n 42:\t#define VFS_WARN_ON_INODE(cond, inode) BUILD_BUG_ON_INVALID(cond)\n 43:\t#endif /* CONFIG_DEBUG_VFS */\n 44:\t\n 45:\t#endif\n"
} |
| 31/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51638 output: 19 thoughts: 40 Thoughts: Here's my take on the thought process: **Debugging the Virtual Filesystem - A Configuration Check** Okay, so I need to make sure `VFS_WARN_ON_ONCE` is going to behave as expected. It's a key debugging tool for the virtual filesystem, and I recall it relies on a particular configuration option. Right, the flag `CONFIG_DEBUG_VFS`. Let me double-check that this option is actually enabled. Time to dive into the Kconfig files and confirm that the build environment has the right settings. Need to ensure the configuration is set appropriately to get the expected debug output if and when the warning is triggered. A quick verification of the configuration setup is necessary. |
| 32/2 | 2026/10/03 03:35 | tool | grepper |
0mArgs:{
"Expression": "config DEBUG_VFS"
}Results: {
"Output": "lib/Kconfig.debug=839=config ARCH_HAS_DEBUG_VM_PGTABLE\n--\nlib/Kconfig.debug-844-\nlib/Kconfig.debug:845:config DEBUG_VFS\nlib/Kconfig.debug-846-\tbool \"Debug VFS\"\n"
} |
| 33/2 | 2026/10/03 03:35 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51930 output: 34 thoughts: 19 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Diving into Debugging Configuration** Okay, so I'm thinking, where should I start looking for this particular debug-related configuration? I need to understand how this is being handled. Let's start with `lib/Kconfig.debug`. It's generally the go-to place for debug-specific options. I'm going to jump to around line 845, that seems like a likely location for the relevant section based on past experience with this codebase and Kconfig structures. That's a reasonable first step to get my bearings and see what’s defined around there. I'm expecting to find either the definition I’m searching for, or pointers towards the relevant code/configuration. |
| 34/2 | 2026/10/03 03:36 | tool | read-file |
0mArgs:{
"File": "lib/Kconfig.debug",
"FirstLine": 840,
"LineCount": 20
}Results: {
"Contents": " 840:\t\tbool\n 841:\t\thelp\n 842:\t\t An architecture should select this when it can successfully\n 843:\t\t build and run DEBUG_VM_PGTABLE.\n 844:\t\n 845:\tconfig DEBUG_VFS\n 846:\t\tbool \"Debug VFS\"\n 847:\t\tdepends on DEBUG_KERNEL\n 848:\t\thelp\n 849:\t\t Enable this to turn on extended checks in the VFS layer that may impact\n 850:\t\t performance.\n 851:\t\n 852:\t\t If unsure, say N.\n 853:\t\n 854:\tconfig DEBUG_VM_IRQSOFF\n 855:\t\tdef_bool DEBUG_VM \u0026\u0026 !PREEMPT_RT\n 856:\t\n 857:\tconfig DEBUG_VM\n 858:\t\tbool \"Debug VM\"\n 859:\t\tdepends on DEBUG_KERNEL\n"
} |
| 35/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 52403 output: 18 thoughts: 316 Thoughts: **My Configuration Audit** Okay, so I'm digging into these kernel configurations. Right off the bat, I see that enabling `DEBUG_VFS` also enables `VFS_WARN_ON_ONCE`. That's a key detail to remember and should definitely be in our `EnableConfigs` list. It's a critical debugging tool. Now, let's look at what else is important. I need to make sure we have all the pieces for user namespaces and mount namespaces. I already know `USER_NS` is essential. It's necessary for things like `unshare(CLONE_NEWUSER)`, `ns_capable`, and so on. Also, let's see, `FHANDLE` - that seems to be guarding `fs/fhandle.c`. And `FSNOTIFY` – that's controlling the inclusion of `fs/notify/mark.c`. And we already know `DEBUG_VFS` is important too. Alright, let's expand the scope a bit. What other files are impacted or conditionally compiled based on these configurations? I need to check every relevant file here: * `fs/fcntl.c` – always included. Good to know. * `fs/fhandle.c` – This depends on `CONFIG_FHANDLE`. * `fs/mount.h` and `include/linux/fs.h` – just headers. * `fs/namei.c`, `fs/namespace.c`, `fs/nullfs.c`, and `fs/readdir.c` – all always compiled. Okay, let's circle back to `USER_NS`. It’s crucial here. Looking at files like `fs/fhandle.c` and `fs/namespace.c`, I see how fundamental user and mount namespaces are, things like `capable_wrt_mount`, `attach_recursive_mnt`, and `user_ns` are all over the place. Now, let's confirm whether `USER_NS` relies on anything specific. This seems like a core building block, so it shouldn't have too many dependencies, but it's important to be sure. |
| 36/2 | 2026/10/03 03:36 | tool | grepper |
0mArgs:{
"Expression": "config USER_NS"
}Results: {
"Output": "init/Kconfig=1438=config IPC_NS\n--\ninit/Kconfig-1445-\ninit/Kconfig:1446:config USER_NS\ninit/Kconfig-1447-\tbool \"User namespace\"\n"
} |
| 37/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 53272 output: 17 thoughts: 10 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and rendered in the first person: **Diving into Configuration Handles** Alright, time to get to work. Let's start with a quick check on `CONFIG_FHANDLE`. I need to understand its current state. Is it enabled? Disabled? What's the associated logic surrounding it? This variable is crucial for file-system handles, and understanding its configuration is the foundation to this task. Any assumptions about the system's behavior would be irresponsible without double-checking this crucial parameter. I need to refresh my memory on the associated dependencies and implications of its settings before proceeding. Let's make sure our foundation is solid. |
| 38/2 | 2026/10/03 03:36 | tool | grepper |
0mArgs:{
"Expression": "config FHANDLE"
}Results: {
"Output": "init/Kconfig=1779=config SGETMASK_SYSCALL\n--\ninit/Kconfig-1788-\ninit/Kconfig:1789:config FHANDLE\ninit/Kconfig-1790-\tbool \"open by fhandle syscalls\" if EXPERT\n"
} |
| 39/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 53530 output: 18 thoughts: 11 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person: **Kernel Configuration Verification** Alright, time to dig in. The first thing I'm thinking is, let's just make sure the obvious is covered. Let's start with `CONFIG_FSNOTIFY`. Gotta quickly confirm that's enabled and configured as expected, given the nature of what we are working on. I need to be sure any assumptions I'm making about file system notification infrastructure are actually valid within the running kernel configuration. It would be a huge waste of time to troubleshoot a deeper issue when the groundwork isn't in place. Checking this early saves a lot of headaches later. |
| 40/2 | 2026/10/03 03:36 | tool | grepper |
0mArgs:{
"Expression": "config FSNOTIFY"
}Results: {
"Output": "fs/notify/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/notify/Kconfig:2:config FSNOTIFY\nfs/notify/Kconfig-3-\tdef_bool n\n"
} |
| 41/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 53772 output: 32 thoughts: 18 Thoughts: Here's a summary of my thought process, as requested: **Navigating the Kconfig Labyrinth** Okay, so I'm looking into how `FSNOTIFY` gets selected in the kernel configuration. My instinct is to dive straight into `fs/notify/Kconfig`. That's the logical starting point. I need to understand the dependencies and relationships within that subsystem's configuration options. This will help me trace back the conditions under which `FSNOTIFY` is enabled, and potentially identify any areas for optimization or further investigation based on my expertise. Time to get my hands dirty and start digging into the details of the Kconfig file! |
| 42/2 | 2026/10/03 03:36 | tool | read-file |
0mArgs:{
"File": "fs/notify/Kconfig",
"FirstLine": 1,
"LineCount": 40
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tconfig FSNOTIFY\n 3:\t\tdef_bool n\n 4:\t\n 5:\tsource \"fs/notify/dnotify/Kconfig\"\n 6:\tsource \"fs/notify/inotify/Kconfig\"\n 7:\tsource \"fs/notify/fanotify/Kconfig\"\n"
} |
| 43/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 54065 output: 18 thoughts: 42 Thoughts: Here's my thought process, summarized as you requested: **Navigating the Filesystem Notification Landscape** Okay, so I'm looking at filesystem monitoring, and I need to figure out the right API to use. My immediate thought is, when I see something like `INOTIFY_USER` or `FANOTIFY`, it strongly suggests I should be thinking about the `FSNOTIFY` framework. That's the likely core implementation for these features. Given that, I'll drill down on `FANOTIFY` specifically to get a better handle on the kernel configuration options involved. The best place to find that is likely within the kernel source itself, so I'm heading straight for the `fs/notify/fanotify/Kconfig` file. I'm expecting this config file to define the build-time options and dependencies associated with `FANOTIFY`, and that should tell me a lot. This will also potentially link back to `FSNOTIFY`, assuming I can trace the relationships, which will allow me to understand how these features interconnect. |
| 44/2 | 2026/10/03 03:36 | tool | grepper |
0mArgs:{
"Expression": "config FANOTIFY"
}Results: {
"Output": "fs/notify/fanotify/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/notify/fanotify/Kconfig:2:config FANOTIFY\nfs/notify/fanotify/Kconfig-3-\tbool \"Filesystem wide access notification\"\n--\nfs/notify/fanotify/Kconfig-14-\nfs/notify/fanotify/Kconfig:15:config FANOTIFY_ACCESS_PERMISSIONS\nfs/notify/fanotify/Kconfig-16-\tbool \"fanotify permissions checking\"\n"
} |
| 45/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 54492 output: 31 thoughts: 407 Thoughts: **Analyzing FocusSymbols for Targeted Fuzzing** Okay, let's break down how we're going to approach defining our `FocusSymbols`. First things first: we need to be very precise about what we include. I know from experience that we absolutely *must* avoid the common pitfalls – we **cannot** list functions that are ubiquitously called throughout the codebase. Memory allocators, deallocators, trap handlers, basic synchronization primitives – these are off-limits. If we do, we'll end up with a huge, diluted set of "focused" tests, wasting our fuzzing effort. Instead, the core principle here is to **target specific feature logic and entrypoints**. We want functions that directly implement the new or changed logic of this patch series, or API entrypoints for the subsystem we're reviewing. And, of course, the ever-present problem of static inline functions in headers. Since these functions don't have distinct symbol addresses in `vmlinux`, we can't directly target them. If the changes are largely in these inlined helpers, then we need to identify non-static, feature-specific *caller* functions in the `.c` files that exercise them. So, let's examine these functions that were modified or added in this patch series. 1. `fcntl_set_rw_hint` in `fs/fcntl.c`: This one's straightforward, it's a direct handler for `F_SET_RW_HINT` in `fcntl`. It's clearly not ubiquitous; it's only called when `fcntl(..., F_SET_RW_HINT, ...)` is called. That's good; it's definitely a viable candidate. 2. `subtree_unobstructed` / `may_decode_fh` in `fs/fhandle.c`: Here, we've got a wrinkle. `subtree_unobstructed` is static. That likely means it's inlined. We'll have to investigate the callers of `may_decode_fh`. Let's dig into `fs/fhandle.c` to see if `subtree_unobstructed` or `may_decode_fh` or `do_handle_to_path` are non-static entry points, since the goal is to target the functions that *use* that static helper. |
| 46/2 | 2026/10/03 03:36 | tool | grepper |
0mArgs:{
"Expression": "may_decode_fh",
"PathPrefix": "fs/fhandle.c"
}Results: {
"Output": "fs/fhandle.c=308=static bool subtree_unobstructed(const struct path *root)\n--\nfs/fhandle.c-316-\nfs/fhandle.c:317:static inline int may_decode_fh(struct handle_to_path_ctx *ctx,\nfs/fhandle.c-318-\t\t\t\tunsigned int o_flags)\n--\nfs/fhandle.c=364=static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,\n--\nfs/fhandle.c-391-\telse\nfs/fhandle.c:392:\t\tretval = may_decode_fh(\u0026ctx, o_flags);\nfs/fhandle.c-393-\tif (retval)\n"
} |
| 47/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 55628 output: 31 thoughts: 73 Thoughts: Here's my thought process, as requested: **Deconstructing the `sys_open_by_handle_at` System Call** Okay, let's trace this. I need to understand how `sys_open_by_handle_at` works internally. The obvious place to start is `fs/fhandle.c`. Right, I remember that `handle_to_path` is likely a key function here. Let me confirm that. Ah, yes, looking at the code, `handle_to_path` is indeed called by `do_handle_open`. And `do_handle_open` itself is directly called by the system call I'm interested in, `sys_open_by_handle_at`. That confirms the execution path. Now, what about the relationship between `handle_to_path` and `do_handle_to_path`? Are they related, maybe even the same? I'll quickly check the functions defined within `fs/fhandle.c` to clarify their roles and how they interact. This should give me a clear picture of the overall mechanism. |
| 48/2 | 2026/10/03 03:36 | tool | grepper |
0mArgs:{
"Expression": "SYSCALL_DEFINE",
"PathPrefix": "fs/fhandle.c"
}Results: {
"Output": "fs/fhandle.c=18=static long do_sys_name_to_handle(const struct path *path,\n--\nfs/fhandle.c-128- */\nfs/fhandle.c:129:SYSCALL_DEFINE5(name_to_handle_at, int, dfd, const char __user *, name,\nfs/fhandle.c-130-\t\tstruct file_handle __user *, handle, void __user *, mnt_id,\n--\nfs/fhandle.c=441=static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,\n--\nfs/fhandle.c-464- */\nfs/fhandle.c:465:SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,\nfs/fhandle.c-466-\t\tstruct file_handle __user *, handle,\n--\nfs/fhandle.c-482- */\nfs/fhandle.c:483:COMPAT_SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,\nfs/fhandle.c-484-\t\t\t struct file_handle __user *, handle, int, flags)\n"
} |
| 49/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 56277 output: 32 thoughts: 273 Thoughts: **Analyzing the Linux Kernel Namei Code Path** Okay, so I'm diving into this `handle_to_path` issue, and it's leading me into the depths of the filesystem code. I'm focusing on the interaction with `do_handle_open` and `subtree_unobstructed`. My brain immediately jumps to `fs/namei.c`, and that's where things get interesting. I've spotted `step_into_slowpath`, and it's *static* and declared `noinline`! That's a key detail. Because it's `noinline`, I expect it *should* exist as a distinct symbol in `vmlinux`, which I can check. Let me verify this quickly. Ah, good. It's there. That's `static noinline const char *step_into_slowpath(struct nameidata *nd, int flags, struct dentry *dentry)`. Now, the question that's nagging at me is: is `step_into_slowpath` actually ubiquitous? I mean, it seems like a core function in path traversal. Let's see how often it's called. Hmm, it seems like it's primarily called from `step_into` when `flags` have `WALK_FOLLOW | WALK_SLOW` set, or during trailing symlink walks. Okay, wait... `step_into` itself is called *during every* path lookup if the slowpath is triggered! Does this mean `step_into_slowpath` is called everywhere? Hold on... path lookup (namei) is happening practically with every syscall – open, stat, etc. But wait, `step_into_slowpath` is only called for mounts, symlinks, or unhashed dentry! Now, it's making sense. Let me check `step_into` directly to clear up my thinking. |
| 50/2 | 2026/10/03 03:36 | tool | grepper |
0mArgs:{
"Expression": "step_into_slowpath",
"PathPrefix": "fs/namei.c"
}Results: {
"Output": "fs/namei.c=2007=static noinline const char *pick_link(struct nameidata *nd, struct path *link,\n--\nfs/namei.c-2014-\tif (nd-\u003eflags \u0026 LOOKUP_RCU) {\nfs/namei.c:2015:\t\t/* make sure that d_is_symlink from step_into_slowpath() matches the inode */\nfs/namei.c-2016-\t\tif (read_seqcount_retry(\u0026link-\u003edentry-\u003ed_seq, nd-\u003enext_seq))\n--\nfs/namei.c=2096=static bool unlink_may_reveal(struct nameidata *nd, int flags,\n--\nfs/namei.c-2123- */\nfs/namei.c:2124:static noinline const char *step_into_slowpath(struct nameidata *nd, int flags,\nfs/namei.c-2125-\t\t struct dentry *dentry)\n--\nfs/namei.c=2159=static __always_inline const char *step_into(struct nameidata *nd, int flags,\n--\nfs/namei.c-2180-\t}\nfs/namei.c:2181:\treturn step_into_slowpath(nd, flags, dentry);\nfs/namei.c-2182-}\n"
} |
| 51/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 57336 output: 25 thoughts: 483 Thoughts: **Analyzing Potential Interactions Between Filesystem Operations and Namespace Modifications** Okay, let's break this down systematically. I'm focusing on how filesystem operations might interact with namespace changes, specifically considering the `step_into` function and how it relates to `unlink` and mount operations. I see that `step_into` leads to `step_into_slowpath`, and the static function `unlink_may_reveal` is likely inlined there. Good to know. Now, let's move on to the interesting stuff. Diving into `fs/namespace.c`, I'm looking at what functions have changed. `__detach_mounts`, which is non-static, is called during `rmdir` and `unlink` operations when mountpoints are being detached – a clear area of interest. Then there's `has_locked_children`, which has also changed from a static internal function to a non-static one. This change is significant and demands further investigation. I've also noted a few static functions here: `attach_recursive_mnt` – called by several mount-related functions like `graft_tree` and `do_move_mount`, `do_lock_mount` used in mount syscalls, `shrink_submount` and `do_add_mount`. These static functions suggest that the kernel is using them internally to maintain certain mount constraints. The non-static `mark_mounts_for_expiry`, exported with `EXPORT_SYMBOL_GPL`, is especially intriguing. It has `VFS_WARN_ON_ONCE(IS_MNT_LOCKED(mnt));` which screams a potential locking relationship with the VFS. This deserves a closer look. Next, I've glanced at `fs/nullfs.c` and a few functions such as `nullfs_dir_llseek`, `nullfs_dir_readdir`, and others to understand possible interactions. This is a bit of a sidetrack for now, but a quick scan never hurts. Over in `fs/notify/mark.c`, `fsnotify_add_mark_list` is static, called by the locked function `fsnotify_add_mark_locked`. Noted, moving on. Finally, `fs/readdir.c` gives us `iterate_dir`. It's non-static and exported! This function is called for `getdents` and `getdents64` and I can see its significance. Let me check what calls `iterate_dir`. This feels like the right track for looking into potential interactions between namespaces and reads of directory entries. |
| 52/2 | 2026/10/03 03:36 | tool | grepper |
0mArgs:{
"Expression": "iterate_dir",
"PathPrefix": "fs/"
}Results: {
"Output": "fs/btrfs/send.c=978=static int iterate_inode_ref(struct btrfs_root *root, struct btrfs_path *path,\n--\nfs/btrfs/send.c-1075-\nfs/btrfs/send.c:1076:typedef int (*iterate_dir_item_t)(int num, struct btrfs_key *di_key,\nfs/btrfs/send.c-1077-\t\t\t\t const char *name, int name_len,\n--\nfs/btrfs/send.c-1087- */\nfs/btrfs/send.c:1088:static int iterate_dir_item(struct btrfs_root *root, struct btrfs_path *path,\nfs/btrfs/send.c:1089:\t\t\t iterate_dir_item_t iterate, void *ctx)\nfs/btrfs/send.c-1090-{\n--\nfs/btrfs/send.c=4901=static int process_new_xattr(struct send_ctx *sctx)\nfs/btrfs/send.c-4902-{\nfs/btrfs/send.c:4903:\treturn iterate_dir_item(sctx-\u003esend_root, sctx-\u003eleft_path,\nfs/btrfs/send.c-4904-\t\t\t\t__process_new_xattr, sctx);\n--\nfs/btrfs/send.c=4907=static int process_deleted_xattr(struct send_ctx *sctx)\nfs/btrfs/send.c-4908-{\nfs/btrfs/send.c:4909:\treturn iterate_dir_item(sctx-\u003eparent_root, sctx-\u003eright_path,\nfs/btrfs/send.c-4910-\t\t\t\t__process_deleted_xattr, sctx);\n--\nfs/btrfs/send.c=4941=static int find_xattr(struct btrfs_root *root,\n--\nfs/btrfs/send.c-4956-\nfs/btrfs/send.c:4957:\tret = iterate_dir_item(root, path, __find_xattr, \u0026ctx);\nfs/btrfs/send.c-4958-\tif (ret \u003c 0)\n--\nfs/btrfs/send.c=5021=static int process_changed_xattr(struct send_ctx *sctx)\n--\nfs/btrfs/send.c-5024-\nfs/btrfs/send.c:5025:\tret = iterate_dir_item(sctx-\u003esend_root, sctx-\u003eleft_path,\nfs/btrfs/send.c-5026-\t\t\t__process_changed_new_xattr, sctx);\n--\nfs/btrfs/send.c-5029-\nfs/btrfs/send.c:5030:\treturn iterate_dir_item(sctx-\u003eparent_root, sctx-\u003eright_path,\nfs/btrfs/send.c-5031-\t\t\t\t__process_changed_deleted_xattr, sctx);\n--\nfs/btrfs/send.c=5034=static int process_all_new_xattrs(struct send_ctx *sctx)\n--\nfs/btrfs/send.c-5058-\nfs/btrfs/send.c:5059:\t\tret = iterate_dir_item(root, path, __process_new_xattr, sctx);\nfs/btrfs/send.c-5060-\t\tif (ret \u003c 0)\n--\nfs/coda/dir.c=428=static int coda_readdir(struct file *coda_file, struct dir_context *ctx)\n--\nfs/coda/dir.c-436-\nfs/coda/dir.c:437:\tret = iterate_dir(host_file, ctx);\nfs/coda/dir.c-438-\tif (ret != -ENOTDIR)\n--\nfs/ecryptfs/file.c=124=static int ecryptfs_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/ecryptfs/file.c-134-\tlower_file = ecryptfs_file_to_lower(file);\nfs/ecryptfs/file.c:135:\trc = iterate_dir(lower_file, \u0026buf.ctx);\nfs/ecryptfs/file.c-136-\tctx-\u003epos = buf.ctx.pos;\n--\nfs/exportfs/expfs.c=274=static int get_name(const struct path *path, char *name, struct dentry *child)\n--\nfs/exportfs/expfs.c-323-\nfs/exportfs/expfs.c:324:\t\terror = iterate_dir(file, \u0026buffer.ctx);\nfs/exportfs/expfs.c-325-\t\tif (buffer.found) {\n--\nfs/libfs.c=494=static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry)\n--\nfs/libfs.c-501-\nfs/libfs.c:502:static void offset_iterate_dir(struct file *file, struct dir_context *ctx)\nfs/libfs.c-503-{\n--\nfs/libfs.c=554=static int offset_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/libfs.c-562-\tif (ctx-\u003epos != DIR_OFFSET_EOD)\nfs/libfs.c:563:\t\toffset_iterate_dir(file, ctx);\nfs/libfs.c-564-\treturn 0;\n--\nfs/nfsd/nfs4recover.c=216=nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)\n--\nfs/nfsd/nfs4recover.c-236-\nfs/nfsd/nfs4recover.c:237:\tstatus = iterate_dir(nn-\u003erec_file, \u0026ctx.ctx);\nfs/nfsd/nfs4recover.c-238-\n--\nfs/nfsd/vfs.c=2420=static __be32 nfsd_buffered_readdir(struct file *file, struct svc_fh *fhp,\n--\nfs/nfsd/vfs.c-2444-\nfs/nfsd/vfs.c:2445:\t\thost_err = iterate_dir(file, \u0026buf.ctx);\nfs/nfsd/vfs.c-2446-\t\tif (buf.full)\n--\nfs/overlayfs/readdir.c=373=static inline int ovl_dir_read(const struct path *realpath,\n--\nfs/overlayfs/readdir.c-387-\t\trdd-\u003eerr = 0;\nfs/overlayfs/readdir.c:388:\t\terr = iterate_dir(realfile, \u0026rdd-\u003ectx);\nfs/overlayfs/readdir.c-389-\t\tif (err \u003e= 0)\n--\nfs/overlayfs/readdir.c=793=static int ovl_iterate_real(struct file *file, struct dir_context *ctx)\n--\nfs/overlayfs/readdir.c-829-\nfs/overlayfs/readdir.c:830:\terr = iterate_dir(od-\u003erealfile, \u0026rdt.ctx);\nfs/overlayfs/readdir.c-831-\tctx-\u003epos = rdt.ctx.pos;\n--\nfs/overlayfs/readdir.c=897=static int ovl_iterate(struct file *file, struct dir_context *ctx)\n--\nfs/overlayfs/readdir.c-910-\nfs/overlayfs/readdir.c:911:\t\treturn iterate_dir(od-\u003erealfile, ctx);\nfs/overlayfs/readdir.c-912-\t}\n--\nfs/overlayfs/super.c=663=static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,\n--\nfs/overlayfs/super.c-690-\t * Upper should support d_type, else whiteouts are visible. Given\nfs/overlayfs/super.c:691:\t * workdir and upper are on same fs, we can do iterate_dir() on\nfs/overlayfs/super.c-692-\t * workdir. This check requires successful creation of workdir in\n--\nfs/readdir.c=33=int wrap_directory_iterator(struct file *file,\n--\nfs/readdir.c-59-\t * Since we dropped the inode lock, we should do the\nfs/readdir.c:60:\t * DEADDIR test again. See 'iterate_dir()' below.\nfs/readdir.c-61-\t *\n--\nfs/readdir.c=72=EXPORT_SYMBOL(wrap_directory_iterator);\n--\nfs/readdir.c-86-\nfs/readdir.c:87:int iterate_dir(struct file *file, struct dir_context *ctx)\nfs/readdir.c-88-{\n--\nfs/readdir.c-123-}\nfs/readdir.c:124:EXPORT_SYMBOL(iterate_dir);\nfs/readdir.c-125-\n--\nfs/readdir.c=220=SYSCALL_DEFINE3(old_readdir, unsigned int, fd,\n--\nfs/readdir.c-233-\nfs/readdir.c:234:\terror = iterate_dir(fd_file(f), \u0026buf.ctx);\nfs/readdir.c-235-\tif (buf.result)\n--\nfs/readdir.c=309=SYSCALL_DEFINE3(getdents, unsigned int, fd,\n--\nfs/readdir.c-323-\nfs/readdir.c:324:\terror = iterate_dir(fd_file(f), \u0026buf.ctx);\nfs/readdir.c-325-\tif (error \u003e= 0)\n--\nfs/readdir.c=389=SYSCALL_DEFINE3(getdents64, unsigned int, fd,\n--\nfs/readdir.c-403-\nfs/readdir.c:404:\terror = iterate_dir(fd_file(f), \u0026buf.ctx);\nfs/readdir.c-405-\tif (error \u003e= 0)\n--\nfs/readdir.c=467=COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,\n--\nfs/readdir.c-480-\nfs/readdir.c:481:\terror = iterate_dir(fd_file(f), \u0026buf.ctx);\nfs/readdir.c-482-\tif (buf.result)\n--\nfs/readdir.c=549=COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,\n--\nfs/readdir.c-563-\nfs/readdir.c:564:\terror = iterate_dir(fd_file(f), \u0026buf.ctx);\nfs/readdir.c-565-\tif (error \u003e= 0)\n--\nfs/smb/server/smb2pdu.c=6039=int smb2_query_dir(struct ksmbd_work *work)\n--\nfs/smb/server/smb2pdu.c-6164-\td_info.num_scan = 0;\nfs/smb/server/smb2pdu.c:6165:\trc = iterate_dir(dir_fp-\u003efilp, \u0026dir_fp-\u003ereaddir_data.ctx);\nfs/smb/server/smb2pdu.c-6166-\t/*\n--\nfs/smb/server/vfs.c=1252=int ksmbd_vfs_empty_dir(struct ksmbd_file *fp)\n--\nfs/smb/server/vfs.c-1261-\nfs/smb/server/vfs.c:1262:\terr = iterate_dir(fp-\u003efilp, \u0026readdir_data.ctx);\nfs/smb/server/vfs.c-1263-\tif (readdir_data.dirent_count)\n--\nfs/smb/server/vfs.c=1308=static int ksmbd_vfs_lookup_in_dir(const struct path *dir, char *name,\n--\nfs/smb/server/vfs.c-1325-\nfs/smb/server/vfs.c:1326:\tret = iterate_dir(dfilp, \u0026readdir_data.ctx);\nfs/smb/server/vfs.c-1327-\tif (readdir_data.dirent_count \u003e 0)\n"
} |
| 53/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 61607 output: 35 thoughts: 391 Thoughts: **Analyzing Potential Hot-Paths in the Kernel** Okay, so I'm looking at `iterate_dir`. The initial thought is, is this function truly *ubiquitous*? The code's warning against focusing on functions that are called by essentially every program – your allocators, page fault handlers, core sync primitives, things like that. We definitely want to avoid those lifecycles. But `iterate_dir` is only called during directory reading, specifically through `getdents` or `getdents64`. Most syzkaller programs don't hit `getdents` on every single run. But what about `nullfs_dir_readdir`? That's definitely specific to the `nullfs` filesystem. I also see these functions: `nullfs_dir_llseek`, `nullfs_nolock`, `nullfs_nolease`, and `nullfs_fs_fill_super`. Then there are these other potential call sites that are jumping out at me: `__detach_mounts`, `mark_mounts_for_expiry`, `shrink_submount`, `has_locked_children`, `attach_recursive_mnt`, `subtree_unobstructed`, `fcntl_set_rw_hint`, `step_into_slowpath`, `unlink_may_reveal`, and `fsnotify_add_mark_list`. I need to figure out which of these functions are candidates and which are non-candidates. Okay, let's look at `unlink_may_reveal`. Is it a static function? Is it inlined? Let's see... Ah, it's static and called *only* once in `step_into_slowpath`. Good. And looking closer... `step_into_slowpath` is `static noinline const char *step_into_slowpath(...)` So, definitely a non-inlined symbol in `vmlinux`. But the big question now is, is `step_into_slowpath` called on *every* path resolution? I need to check `fs/namei.c`. Let's dig into that code... |
| 54/2 | 2026/10/03 03:36 | tool | read-file |
0mArgs:{
"File": "fs/namei.c",
"FirstLine": 2160,
"LineCount": 35
}Results: {
"Contents": "2160:\t struct dentry *dentry)\n2161:\t{\n2162:\t\t/*\n2163:\t\t * In the common case we are in rcu-walk and traversing over a non-mounted on\n2164:\t\t * directory (as opposed to e.g., a symlink).\n2165:\t\t *\n2166:\t\t * We can handle that and negative entries with the checks below.\n2167:\t\t */\n2168:\t\tif (likely((nd-\u003eflags \u0026 LOOKUP_RCU) \u0026\u0026\n2169:\t\t !d_managed(dentry) \u0026\u0026 !d_is_symlink(dentry))) {\n2170:\t\t\tstruct inode *inode = dentry-\u003ed_inode;\n2171:\t\t\tif (read_seqcount_retry(\u0026dentry-\u003ed_seq, nd-\u003enext_seq))\n2172:\t\t\t\treturn ERR_PTR(-ECHILD);\n2173:\t\t\tif (unlikely(!inode))\n2174:\t\t\t\treturn ERR_PTR(-ENOENT);\n2175:\t\t\tnd-\u003epath.dentry = dentry;\n2176:\t\t\t/* nd-\u003epath.mnt remains unchanged as no mount point was crossed */\n2177:\t\t\tnd-\u003einode = inode;\n2178:\t\t\tnd-\u003eseq = nd-\u003enext_seq;\n2179:\t\t\treturn NULL;\n2180:\t\t}\n2181:\t\treturn step_into_slowpath(nd, flags, dentry);\n2182:\t}\n2183:\t\n2184:\tstatic struct dentry *follow_dotdot_rcu(struct nameidata *nd)\n2185:\t{\n2186:\t\tstruct dentry *parent, *old;\n2187:\t\n2188:\t\tif (path_equal(\u0026nd-\u003epath, \u0026nd-\u003eroot))\n2189:\t\t\tgoto in_root;\n2190:\t\tif (unlikely(nd-\u003epath.dentry == nd-\u003epath.mnt-\u003emnt_root)) {\n2191:\t\t\tstruct path path;\n2192:\t\t\tunsigned seq;\n2193:\t\t\tif (!choose_mountpoint_rcu(real_mount(nd-\u003epath.mnt),\n2194:\t\t\t\t\t\t \u0026nd-\u003eroot, \u0026path, \u0026seq))\n"
} |
| 55/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 63072 output: 32 thoughts: 442 Thoughts: **Analyzing Potential Call Sites for File System Operations** Okay, let's break this down systematically. My immediate focus is on understanding the call paths and identifying potentially interesting locations for further investigation, especially given the context of file lookup behavior and syzkaller interactions. First, the `step_into` function catches my attention. The conditional `step_into_slowpath` invocation based on RCU mode, d_managed, or d_is_symlink suggests that refwalk scenarios or operations that traverse mount points are of particular relevance. The question then becomes, is `step_into_slowpath` overly broad? It's used in refwalk situations, but that only happens when RCU walks fallback, or don't work in the first place. But then, `unlink_may_reveal` is designed for unlinked dentries, during refwalk across mount points. That's a good sign. Next, I'll go through the others: * `fcntl_set_rw_hint`: This seems highly specific to read/write hints, so potentially less relevant in this broad context. * `subtree_unobstructed`: Static function. This is in `fs/fhandle.c`. Let's see if this can be inlined or if we can see the calling function. It's static, and called only once from `may_decode_fh`, which is `static inline`, and called from `handle_to_path`. Thus, `handle_to_path` or `open_by_handle_at` would be the place to look. That's good. * `has_locked_children`: This is not static; it's declared in `fs/mount.h` and defined in `fs/namespace.c`. This could be interesting. * `__detach_mounts`: Also not static and in `fs/namespace.c`. * `attach_recursive_mnt`: Static, same location. * `mark_mounts_for_expiry`: Non-static and EXPORT\_SYMBOL\_GPL'd from `fs/namespace.c`. This is another potential point of interest. * `shrink_submount`: Static, in `fs/namespace.c`. * `nullfs_dir_readdir`, `nullfs_dir_llseek`, `nullfs_nolock`, `nullfs_nolease`: These are specific to `nullfs`, and while potentially useful for understanding interactions, they are likely less general. * `fsnotify_add_mark_list`: This is static, in `fs/notify/mark.c`. It's a good time to check callers of `fsnotify_add_mark_list`. So, in summary, based on the callsites here, I will begin by examining the refwalk and mount traversal paths specifically, and then the following functions: `handle_to_path` or `open_by_handle_at`, `has_locked_children`, `__detach_mounts`, `mark_mounts_for_expiry` and finally the callers of `fsnotify_add_mark_list`. This provides a good starting point for investigation. |
| 56/2 | 2026/10/03 03:36 | tool | grepper |
0mArgs:{
"Expression": "fsnotify_add_mark_list",
"PathPrefix": "fs/notify/"
}Results: {
"Output": "fs/notify/mark.c=866=static struct fsnotify_mark_connector *fsnotify_grab_connector(\n--\nfs/notify/mark.c-892- */\nfs/notify/mark.c:893:static int fsnotify_add_mark_list(struct fsnotify_mark *mark, void *obj,\nfs/notify/mark.c-894-\t\t\t\t unsigned int obj_type, int add_flags)\n--\nfs/notify/mark.c=979=int fsnotify_add_mark_locked(struct fsnotify_mark *mark,\n--\nfs/notify/mark.c-1000-\nfs/notify/mark.c:1001:\tret = fsnotify_add_mark_list(mark, obj, obj_type, add_flags);\nfs/notify/mark.c-1002-\tif (ret)\n"
} |
| 57/2 | 2026/10/03 03:36 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 64452 output: 349 thoughts: 2290 Thoughts: **Analysis of Modified VFS Functions and Configuration for Fuzzing** Alright, let's break this down. My goal is to determine the most effective symbols and configurations for fuzzing the VFS changes. First, `fsnotify_add_mark_locked` calls `fsnotify_add_mark_list`, and the former is called by `fsnotify_add_mark`. Good to know the call hierarchy. I'll need to remember that. Now, a broader view of the modified files and functions. I see changes in `fcntl.c` with `fcntl_set_rw_hint`, `fhandle.c` with `subtree_unobstructed`, `may_decode_fh`, and `handle_to_path`, and `namei.c` with `unlink_may_reveal` and `step_into_slowpath`. `namespace.c` has a lot of activity: `__detach_mounts`, `has_locked_children`, `attach_recursive_mnt`, `do_lock_mount`, `do_add_mount`, `mark_mounts_for_expiry`, `shrink_submount`, and `init_mount_tree`. `mark.c` has `fsnotify_add_mark_list` and `fsnotify_add_mark_locked`. `nullfs.c` deals with `nullfs_dir_llseek`, `nullfs_dir_readdir`, `nullfs_nolock`, `nullfs_nolease`, and `nullfs_fs_fill_super`. Finally, `readdir.c` has `iterate_dir`. My next step is to filter down to good, non-ubiquitous FocusSymbols, I need to know what's called everywhere and what's specific to particular paths. `iterate_dir` is called on almost all getdents, so I'm skipping that. `__detach_mounts`, `mark_mounts_for_expiry`, `shrink_submount`, `attach_recursive_mnt`, `has_locked_children`, `subtree_unobstructed`, `fcntl_set_rw_hint`, and the nullfs specific functions seem more targeted. Then `unlink_may_reveal` and of course, `fsnotify_add_mark_locked`. Now the question is, are they static and inlined? Let me see. I see that `unlink_may_reveal` is static in `namei.c`. It's called in `step_into_slowpath`, however, `step_into_slowpath` is explicitly declared `noinline`. This is good, if `unlink_may_reveal` is inlined, `step_into_slowpath` is still guaranteed to be a distinct symbol, so that's helpful. `subtree_unobstructed` is static inline and called by `may_decode_fh` which is static inline. `handle_to_path` will contain `subtree_unobstructed`, so I'll include both. I can include `fsnotify_add_mark_locked` and `fsnotify_add_mark_list` as they aren't static. `mark_mounts_for_expiry` is non-static and exported. It contains the `VFS_WARN_ON_ONCE` assertion. `has_locked_children` and `__detach_mounts` are non-static as well. `attach_recursive_mnt` and `shrink_submount` are static. The nullfs functions, by virtue of being in a struct of function pointers, cannot be inlined. I will include those as well. `fcntl_set_rw_hint` is static in `fs/fcntl.c`, and called from `do_fcntl`. Next, I need to check the required configuration options. I see that `USER_NS` is required for user namespaces, `FHANDLE` for `fs/fhandle.c`, `FSNOTIFY` for `fs/notify/mark.c`, and `DEBUG_VFS` for the `VFS_WARN_ON_ONCE` assertion. I also need to make sure that nullfs doesn't have any specific configuration dependencies. I see that `nullfs` is unconditionally built. The other files also seem unconditional. `DEBUG_VFS` depends on `DEBUG_KERNEL`, and Syzkaller usually has that set, so `DEBUG_VFS` is fine. Now, let's prepare the arguments for the fuzzing tool. - `WorthFuzzing`: `true` (definitely!) - `Reasoning`: This patch series modifies core VFS logic including mount namespace locking/propagation, unmounting semantics (`__detach_mounts`, `shrink_submount`, `attach_recursive_mnt`), directory readdir locking (`iterate |
| 58/2 | 2026/10/03 03:37 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"DEBUG_VFS",
"FHANDLE",
"FSNOTIFY",
"USER_NS"
],
"FocusSymbols": [
"fcntl_set_rw_hint",
"subtree_unobstructed",
"handle_to_path",
"step_into_slowpath",
"unlink_may_reveal",
"__detach_mounts",
"has_locked_children",
"attach_recursive_mnt",
"mark_mounts_for_expiry",
"shrink_submount",
"nullfs_dir_readdir",
"nullfs_nolock",
"fsnotify_add_mark_locked",
"fsnotify_add_mark_list"
],
"Reasoning": "The patch series modifies core VFS logic across mount namespace locking and propagation (attach_recursive_mnt, has_locked_children), mount detach and expiry handling (__detach_mounts, shrink_submount, and adding a VFS_WARN_ON_ONCE assertion in mark_mounts_for_expiry), refwalk lookup revealing unlinked dentries (unlink_may_reveal in step_into_slowpath), lockless readdir execution for immutable filesystems (iterate_dir with FOP_IMMUTABLE), nullfs directory and file operations, file handle subtree decode checks (subtree_unobstructed in fhandle), fcntl rw_hint checks on immutable inodes, and fsnotify mark validation. All modified paths are reachable via standard system calls and virtualized environments, making this change an ideal candidate for fuzzing.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"DEBUG_VFS",
"FHANDLE",
"FSNOTIFY",
"USER_NS"
],
"FocusSymbols": [
"fcntl_set_rw_hint",
"subtree_unobstructed",
"handle_to_path",
"step_into_slowpath",
"unlink_may_reveal",
"__detach_mounts",
"has_locked_children",
"attach_recursive_mnt",
"mark_mounts_for_expiry",
"shrink_submount",
"nullfs_dir_readdir",
"nullfs_nolock",
"fsnotify_add_mark_locked",
"fsnotify_add_mark_list"
],
"Reasoning": "The patch series modifies core VFS logic across mount namespace locking and propagation (attach_recursive_mnt, has_locked_children), mount detach and expiry handling (__detach_mounts, shrink_submount, and adding a VFS_WARN_ON_ONCE assertion in mark_mounts_for_expiry), refwalk lookup revealing unlinked dentries (unlink_may_reveal in step_into_slowpath), lockless readdir execution for immutable filesystems (iterate_dir with FOP_IMMUTABLE), nullfs directory and file operations, file handle subtree decode checks (subtree_unobstructed in fhandle), fcntl rw_hint checks on immutable inodes, and fsnotify mark validation. All modified paths are reachable via standard system calls and virtualized environments, making this change an ideal candidate for fuzzing.",
"WorthFuzzing": true
} |
| 59/1 | 2026/10/03 03:37 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 60/2 | 2026/10/03 03:37 | agent | kmsan-evaluator |
0mModel:core Args: null Results: {
"KMSANReasoning": "The patch series modifies VFS mount handling, mount propagation locking (MNT_LOCKED), directory iteration locking for immutable filesystems (FOP_IMMUTABLE in nullfs and iterate_dir), fcntl rw-hint checks for immutable inodes, path lookup unlinked-dentry checks (unlink_may_reveal), and fsnotify mark restrictions (FS_DISALLOW_NOTIFY), along with corresponding selftests.\n\nNone of the changes introduce or modify kernel-to-user copy paths with uninitialized padding/fields, nor do they introduce allocations of uninitialized memory, branch on uninitialized variables, or alter buffer bounds. Potential risks introduced by these changes primarily concern reference counting (dentry/mount ref handling), concurrency, locking (inode rwsem, mount_lock), and access control/logic bugs. These categories are caught by standard KASAN, LOCKDEP, and functional fuzzing/testing. Spawning a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit f2c7e28a87ef20978c41877ec1ef9d1356a8d6a0
Author: syz-cluster <triage@syzkaller.com>
Date: Sat Oct 3 03:34:56 2026 +0000
syz-cluster: applied patch under review
diff --git a/fs/fcntl.c b/fs/fcntl.c
index c158f082f1da4..9b71bc9d71d15 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -372,6 +372,9 @@ static long fcntl_set_rw_hint(struct file *file, unsigned long arg)
u64 __user *argp = (u64 __user *)arg;
u64 hint;
+ /* nothing is ever written to it */
+ if (IS_IMMUTABLE(inode))
+ return -EPERM;
if (!inode_owner_or_capable(file_mnt_idmap(file), inode))
return -EPERM;
diff --git a/fs/fhandle.c b/fs/fhandle.c
index f8829231e3d75..d22f2e065677a 100644
--- a/fs/fhandle.c
+++ b/fs/fhandle.c
@@ -298,6 +298,22 @@ static bool capable_wrt_mount(struct mount *mount)
return mnt_ns && ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN);
}
+/*
+ * Does the caller have an unobstructed way to everything below @root? Only
+ * if the mount is mounted, the caller is privileged over its mount namespace
+ * and no locked child covers something below @root->dentry. One answer from
+ * under mount_lock: an umount in between clears ->mnt_ns and takes the
+ * children off the mount, the locked ones too.
+ */
+static bool subtree_unobstructed(const struct path *root)
+{
+ struct mount *mnt = real_mount(root->mnt);
+
+ guard(mount_locked_reader)();
+ return is_mounted(root->mnt) && capable_wrt_mount(mnt) &&
+ !has_locked_children(mnt, root->dentry);
+}
+
static inline int may_decode_fh(struct handle_to_path_ctx *ctx,
unsigned int o_flags)
{
@@ -332,9 +348,7 @@ static inline int may_decode_fh(struct handle_to_path_ctx *ctx,
if (ns_capable(root->mnt->mnt_sb->s_user_ns, CAP_SYS_ADMIN))
ctx->flags = HANDLE_CHECK_PERMS;
- else if (is_mounted(root->mnt) &&
- capable_wrt_mount(real_mount(root->mnt)) &&
- !has_locked_children(real_mount(root->mnt), root->dentry))
+ else if (subtree_unobstructed(root))
ctx->flags = HANDLE_CHECK_PERMS | HANDLE_CHECK_SUBTREE;
else
return -EPERM;
diff --git a/fs/mount.h b/fs/mount.h
index 2223fb141499f..4e68e5cbc2549 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -6,6 +6,7 @@
#include <linux/fs_pin.h>
extern struct file_system_type nullfs_fs_type;
+extern struct vfsmount *knullfs;
extern struct list_head notify_list;
struct mnt_namespace {
diff --git a/fs/namei.c b/fs/namei.c
index 20a6534ea3eff..c87c14ee1a252 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2086,6 +2086,33 @@ static noinline const char *pick_link(struct nameidata *nd, struct path *link,
return NULL;
}
+/*
+ * Be careful in case the dentry is unlinked or renamed. Any mounts
+ * stacked on top of it are going away. We need to make sure that we
+ * don't reveal the underyling dentry during refwalk. In rcuwalk we
+ * catch this via d_seq and another lookup for the name. Give the same
+ * guarantee in refwalk.
+ */
+static bool unlink_may_reveal(struct nameidata *nd, int flags,
+ struct path *path, struct dentry *dentry)
+{
+ /* ".." and LOOKUP_DOWN may land on an unhashed directory */
+ if (flags & WALK_NOFOLLOW)
+ return false;
+ if (nd->flags & LOOKUP_REVAL)
+ return false;
+ /* We crossed onto a mount and the name led us here while it still existed */
+ if (path->mnt != nd->path.mnt)
+ return false;
+ /* only a name on its way out is flagged */
+ if (likely(!cant_mount(dentry)))
+ return false;
+ if (!d_unlinked(dentry))
+ return false;
+ dput(no_free_ptr(path->dentry));
+ return true;
+}
+
/*
* Do we need to follow links? We _really_ want to be able
* to do this check without having to look at inode->i_op,
@@ -2115,6 +2142,8 @@ static noinline const char *step_into_slowpath(struct nameidata *nd, int flags,
if (unlikely(!inode))
return ERR_PTR(-ENOENT);
} else {
+ if (unlikely(unlink_may_reveal(nd, flags, &path, dentry)))
+ return ERR_PTR(-ESTALE);
dput(nd->path.dentry);
if (nd->path.mnt != path.mnt)
mntput(nd->path.mnt);
diff --git a/fs/namespace.c b/fs/namespace.c
index fcf42f192aae9..e1b0ade95b0d8 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -80,6 +80,7 @@ static u64 mnt_id_ctr = MNT_UNIQUE_ID_OFFSET;
static struct hlist_head *mount_hashtable __ro_after_init;
static struct hlist_head *mountpoint_hashtable __ro_after_init;
static struct kmem_cache *mnt_cache __ro_after_init;
+struct vfsmount *knullfs __ro_after_init; /* private nullfs instance */
static DECLARE_RWSEM(namespace_sem);
static HLIST_HEAD(unmounted); /* protected by namespace_sem */
static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */
@@ -1996,6 +1997,9 @@ static int do_umount(struct mount *mnt, int flags)
* detach_mounts allows lazily unmounting those mounts instead of
* leaking them.
*
+ * The dentry is unhashed before the mounts go so that no lookup finds
+ * what they covered. The caller removes it for good afterwards.
+ *
* The caller may hold dentry->d_inode->i_rwsem.
*/
void __detach_mounts(struct dentry *dentry)
@@ -2009,6 +2013,8 @@ void __detach_mounts(struct dentry *dentry)
if (!lookup_mountpoint(dentry, &mp))
return;
+ /* the name goes first, what covered it goes second */
+ d_drop(dentry);
event++;
while (mp.node.next) {
mnt = hlist_entry(mp.node.next, struct mount, mnt_mp_list);
@@ -2348,7 +2354,7 @@ void dissolve_on_fput(struct vfsmount *mnt)
}
/* locks: namespace_shared && pinned(mnt) || mount_locked_reader */
-static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)
+bool has_locked_children(struct mount *mnt, struct dentry *dentry)
{
struct mount *child;
@@ -2362,12 +2368,6 @@ static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)
return false;
}
-bool has_locked_children(struct mount *mnt, struct dentry *dentry)
-{
- guard(mount_locked_reader)();
- return __has_locked_children(mnt, dentry);
-}
-
/* locks: namespace_shared && pinned(mnt) || mount_locked_reader */
static bool __has_children(struct mount *mnt, struct dentry *dentry)
{
@@ -2436,7 +2436,7 @@ struct vfsmount *clone_private_mount(const struct path *path)
if (!ns_capable(old_mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
return ERR_PTR(-EPERM);
- if (__has_locked_children(old_mnt, path->dentry))
+ if (has_locked_children(old_mnt, path->dentry))
return ERR_PTR(-EINVAL);
new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE);
@@ -2599,11 +2599,11 @@ enum mnt_tree_flags_t {
static int attach_recursive_mnt(struct mount *source_mnt,
const struct pinned_mountpoint *dest)
{
- struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
struct mount *dest_mnt = dest->parent;
struct mountpoint *dest_mp = dest->mp;
HLIST_HEAD(tree_list);
struct mnt_namespace *ns = dest_mnt->mnt_ns;
+ struct user_namespace *user_ns = ns->user_ns;
struct pinned_mountpoint root = {};
struct mountpoint *shorter = NULL;
struct mount *child, *p;
@@ -2612,6 +2612,22 @@ static int attach_recursive_mnt(struct mount *source_mnt,
int err = 0;
bool moving = mnt_has_parent(source_mnt);
+ /*
+ * A caller in an unprivileged mount namespaces may trigger an
+ * automount and propagate locked mounts into privileged mount
+ * namespaces. Take ownership from the target mount namespace.
+ * It's equivalent for everything but the automount case.
+ *
+ * Detached trees in anonymous mount namespaces by be handed
+ * over via SCM_RIGHTS or inherited in other ways on purpose
+ * the attaching task's mount namespace is authoritative, not
+ * the creator of the detached tree.
+ */
+ if (is_anon_ns(ns))
+ user_ns = current->nsproxy->mnt_ns->user_ns;
+ else
+ user_ns = ns->user_ns;
+
/*
* Preallocate a mountpoint in case the new mounts need to be
* mounted beneath mounts on the same mountpoint.
@@ -2691,15 +2707,17 @@ static int attach_recursive_mnt(struct mount *source_mnt,
/*
* If @q was locked it was meant to hide
* whatever was under it. Let @child take over
- * that job and lock it, then we can unlock @q.
- * That'll allow another namespace to shed @q
- * and reveal @child. Clearly, that mounter
- * consented to this by not severing the mount
- * relationship. Otherwise, what's the point.
+ * that job and lock it. If @child is the mount
+ * the caller placed we can then unlock @q:
+ * nothing another namespace does removes it
+ * again. A propagated copy goes away when the
+ * mounter of the original unmounts it, so @q
+ * keeps its lock.
*/
if (IS_MNT_LOCKED(q)) {
child->mnt.mnt_flags |= MNT_LOCKED;
- q->mnt.mnt_flags &= ~MNT_LOCKED;
+ if (child == source_mnt)
+ q->mnt.mnt_flags &= ~MNT_LOCKED;
}
mnt_change_mountpoint(r, mp, q);
}
@@ -2796,6 +2814,11 @@ static void do_lock_mount(const struct path *path,
scoped_guard(mount_locked_reader) {
m = where_to_mount(path, &dentry, beneath);
+ /* sticky, so it takes no locks to refuse it */
+ if (unlikely(cant_mount(dentry))) {
+ res->parent = ERR_PTR(-ENOENT);
+ return;
+ }
if (&m->mnt != path->mnt) {
mntget(&m->mnt);
dget(dentry);
@@ -3033,7 +3056,7 @@ static struct mount *__do_loopback(const struct path *old_path,
if (recurse && !old->mnt_ns)
return ERR_PTR(-EINVAL);
- if (!recurse && __has_locked_children(old, old_path->dentry))
+ if (!recurse && has_locked_children(old, old_path->dentry))
return ERR_PTR(-EINVAL);
if (recurse)
@@ -3521,7 +3544,7 @@ static int do_set_group(const struct path *from_path, const struct path *to_path
return -EINVAL;
/* From mount should not have locked children in place of To's root */
- if (__has_locked_children(from, to->mnt.mnt_root))
+ if (has_locked_children(from, to->mnt.mnt_root))
return -EINVAL;
/* Setting sharing groups is only allowed on private mounts */
@@ -3801,7 +3824,7 @@ static int do_add_mount(struct mount *newmnt, const struct pinned_mountpoint *mp
if (!(mnt_flags & MNT_SHRINKABLE))
return -EINVAL;
/* ... and for those we'd better have mountpoint still alive */
- if (!parent->mnt_ns)
+ if (!is_mounted(&parent->mnt))
return -EINVAL;
}
@@ -4011,6 +4034,8 @@ void mark_mounts_for_expiry(struct list_head *mounts)
list_for_each_entry_safe(mnt, next, mounts, mnt_expire) {
if (!is_mounted(&mnt->mnt))
continue;
+ /* lock_mnt_tree() leaves expirable mounts alone */
+ VFS_WARN_ON_ONCE(IS_MNT_LOCKED(mnt));
if (!xchg(&mnt->mnt_expiry_mark, 1) ||
propagate_mount_busy(mnt, 1))
continue;
@@ -4037,7 +4062,8 @@ EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
*/
static bool shrink_submount(struct mount *mnt)
{
- if (propagate_mount_busy(mnt, 1))
+ /* not the kernel's to remove either */
+ if (IS_MNT_LOCKED(mnt) || propagate_mount_busy(mnt, 1))
return false;
touch_mnt_namespace(mnt->mnt_ns);
umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);
@@ -6315,7 +6341,7 @@ static void __init init_mount_tree(void)
*
* (1) nullfs with mount id 1
* (2) mutable rootfs with mount id 2
- * (3) private nullfs for kthreads (SB_KERNMOUNT)
+ * (3) private nullfs for kthreads (SB_KERNMOUNT), kept in knullfs
*
* with (2) mounted on top of (1). The init_task's root and pwd
* are pointed at (3) so all kthreads start isolated in nullfs.
@@ -6350,11 +6376,15 @@ static void __init init_mount_tree(void)
init_mnt_ns.nr_mounts++;
}
- nullfs_mnt = kern_mount(&nullfs_fs_type);
- if (IS_ERR(nullfs_mnt))
+ knullfs = kern_mount(&nullfs_fs_type);
+ if (IS_ERR(knullfs))
panic("VFS: Failed to create private nullfs instance");
- root.mnt = nullfs_mnt;
- root.dentry = nullfs_mnt->mnt_root;
+ /* nothing is ever mounted on the root of a kernel thread */
+ dont_mount(knullfs->mnt_root);
+ /* and nothing is ever written through it */
+ knullfs->mnt_flags |= MNT_READONLY;
+ root.mnt = knullfs;
+ root.dentry = knullfs->mnt_root;
init_task.nsproxy->mnt_ns = &init_mnt_ns;
get_mnt_ns(&init_mnt_ns);
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index b2640d836a712..d17628580a570 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -903,6 +903,10 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, void *obj,
if (WARN_ON(!fsnotify_valid_obj_type(obj_type)))
return -EINVAL;
+ /* the filesystem doesn't want its objects watched */
+ if (sb && (sb->s_type->fs_flags & FS_DISALLOW_NOTIFY))
+ return -EINVAL;
+
/*
* Attach the sb info before attaching a connector to any object on sb.
* The sb info will remain attached as long as sb lives.
diff --git a/fs/nullfs.c b/fs/nullfs.c
index e06352c7b2ccf..bfc04bca39407 100644
--- a/fs/nullfs.c
+++ b/fs/nullfs.c
@@ -10,6 +10,43 @@ static const struct super_operations nullfs_super_operations = {
.statfs = simple_statfs,
};
+static loff_t nullfs_dir_llseek(struct file *file, loff_t offset, int whence)
+{
+ /* an empty directory has two entries . and .. at offsets 0 and 1 */
+ return generic_file_llseek_size(file, offset, whence, 2, 2);
+}
+
+static int nullfs_dir_readdir(struct file *file, struct dir_context *ctx)
+{
+ dir_emit_dots(file, ctx);
+ return 0;
+}
+
+/* the one inode of nullfs is shared by every holder, so no locks on it */
+static int nullfs_nolock(struct file *file, int cmd, struct file_lock *fl)
+{
+ return -ENOLCK;
+}
+
+/* and no leases or delegations */
+static int nullfs_nolease(struct file *file, int arg, struct file_lease **flp,
+ void **priv)
+{
+ return -EINVAL;
+}
+
+/* what libfs gives an empty directory, plus the refusal of file locks */
+static const struct file_operations nullfs_dir_operations = {
+ .llseek = nullfs_dir_llseek,
+ .read = generic_read_dir,
+ .iterate_shared = nullfs_dir_readdir,
+ .fsync = noop_fsync,
+ .lock = nullfs_nolock,
+ .flock = nullfs_nolock,
+ .setlease = nullfs_nolease,
+ .fop_flags = FOP_IMMUTABLE,
+};
+
static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)
{
struct inode *inode;
@@ -30,10 +67,11 @@ static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)
/* nullfs is permanently empty... */
make_empty_dir_inode(inode);
+ inode->i_fop = &nullfs_dir_operations;
simple_inode_init_ts(inode);
inode->i_ino = 1;
- /* ... and immutable. */
- inode->i_flags |= S_IMMUTABLE;
+ /* ... and immutable, reading it leaves no trace either. */
+ inode->i_flags |= S_IMMUTABLE | S_NOATIME;
s->s_root = d_make_root(inode);
if (!s->s_root)
@@ -61,6 +99,7 @@ static int nullfs_init_fs_context(struct fs_context *fc)
struct file_system_type nullfs_fs_type = {
.name = "nullfs",
+ .fs_flags = FS_DISALLOW_NOTIFY,
.init_fs_context = nullfs_init_fs_context,
.kill_sb = kill_anon_super,
};
diff --git a/fs/readdir.c b/fs/readdir.c
index 76bb1ae3a4504..f2288841337ad 100644
--- a/fs/readdir.c
+++ b/fs/readdir.c
@@ -87,6 +87,8 @@ EXPORT_SYMBOL(wrap_directory_iterator);
int iterate_dir(struct file *file, struct dir_context *ctx)
{
struct inode *inode = file_inode(file);
+ /* never an entry, never removed: nothing for the lock to keep still */
+ bool locked = !(file->f_op->fop_flags & FOP_IMMUTABLE);
int res = -ENOTDIR;
if (!file->f_op->iterate_shared)
@@ -100,9 +102,11 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
if (res)
goto out;
- res = down_read_killable(&inode->i_rwsem);
- if (res)
- goto out;
+ if (locked) {
+ res = down_read_killable(&inode->i_rwsem);
+ if (res)
+ goto out;
+ }
res = -ENOENT;
if (!IS_DEADDIR(inode)) {
@@ -112,7 +116,8 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
fsnotify_access(file);
file_accessed(file);
}
- inode_unlock_shared(inode);
+ if (locked)
+ inode_unlock_shared(inode);
out:
return res;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index f9d1e05e8ae68..deb411e866617 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1978,6 +1978,8 @@ struct file_operations {
#define FOP_ASYNC_LOCK ((__force fop_flags_t)(1 << 6))
/* File system supports uncached read/write buffered IO */
#define FOP_DONTCACHE ((__force fop_flags_t)(1 << 7))
+/* Never changes and is never removed, readdir of a directory takes no lock */
+#define FOP_IMMUTABLE ((__force fop_flags_t)(1 << 8))
/* Wrap a directory iterator that needs exclusive inode access */
int wrap_directory_iterator(struct file *, struct dir_context *,
@@ -2296,6 +2298,7 @@ struct file_system_type {
#define FS_POWER_FREEZE 256 /* Always freeze on suspend/hibernate */
#define FS_USERNS_MOUNT_RESTRICTED 512 /* Restrict mount in userns if not already visible */
#define FS_USERNS_DELEGATABLE 1024 /* Can be mounted inside userns from outside */
+#define FS_DISALLOW_NOTIFY 2048 /* No fsnotify marks on its objects */
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
int (*init_fs_context)(struct fs_context *);
const struct fs_parameter_spec *parameters;
diff --git a/tools/testing/selftests/filesystems/.gitignore b/tools/testing/selftests/filesystems/.gitignore
index 9eb185fb2f9dd..62f7b1c466497 100644
--- a/tools/testing/selftests/filesystems/.gitignore
+++ b/tools/testing/selftests/filesystems/.gitignore
@@ -7,3 +7,4 @@ anon_inode_test
kernfs_test
idmapped_tmpfile
ustat_test
+rw_hint_test
diff --git a/tools/testing/selftests/filesystems/Makefile b/tools/testing/selftests/filesystems/Makefile
index 03be337c1f351..93e2cc9123b04 100644
--- a/tools/testing/selftests/filesystems/Makefile
+++ b/tools/testing/selftests/filesystems/Makefile
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
CFLAGS += $(KHDR_INCLUDES)
-TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test
+TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test rw_hint_test
TEST_GEN_PROGS += idmapped_tmpfile
TEST_GEN_PROGS_EXTENDED := dnotify_test
diff --git a/tools/testing/selftests/filesystems/empty_mntns/.gitignore b/tools/testing/selftests/filesystems/empty_mntns/.gitignore
index 32125b3eaa801..27bcbcaeb1d19 100644
--- a/tools/testing/selftests/filesystems/empty_mntns/.gitignore
+++ b/tools/testing/selftests/filesystems/empty_mntns/.gitignore
@@ -3,3 +3,5 @@ clone3_empty_mntns_test
empty_mntns_test
overmount_chroot_test
internal_sb_reconfigure_test
+nullfs_atime_test
+root_readdir_test
diff --git a/tools/testing/selftests/filesystems/empty_mntns/Makefile b/tools/testing/selftests/filesystems/empty_mntns/Makefile
index b64818b962ca5..22af2164c54e9 100644
--- a/tools/testing/selftests/filesystems/empty_mntns/Makefile
+++ b/tools/testing/selftests/filesystems/empty_mntns/Makefile
@@ -4,7 +4,9 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
LDLIBS += -lcap
TEST_GEN_PROGS := empty_mntns_test overmount_chroot_test clone3_empty_mntns_test
-TEST_GEN_PROGS += internal_sb_reconfigure_test
+TEST_GEN_PROGS += internal_sb_reconfigure_test nullfs_atime_test root_readdir_test
+
+LOCAL_HDRS += ../readdir_hold.h
include ../../lib.mk
@@ -12,3 +14,4 @@ $(OUTPUT)/empty_mntns_test: ../utils.c
$(OUTPUT)/overmount_chroot_test: ../utils.c
$(OUTPUT)/clone3_empty_mntns_test: ../utils.c
$(OUTPUT)/internal_sb_reconfigure_test: ../utils.c
+$(OUTPUT)/root_readdir_test: LDLIBS += -pthread
diff --git a/tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c b/tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c
new file mode 100644
index 0000000000000..51e34f3c4f541
--- /dev/null
+++ b/tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * The root of every empty mount namespace is the same nullfs inode. A read
+ * of it by one user must not change the access time another user sees.
+ */
+#define _GNU_SOURCE
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
+#include "../../kselftest_harness.h"
+
+#ifndef UNSHARE_EMPTY_MNTNS
+#define UNSHARE_EMPTY_MNTNS 0x00100000
+#endif
+
+enum {
+ CHILD_OK,
+ CHILD_UNSUPPORTED,
+ CHILD_SETUP,
+ CHILD_CHANGED,
+};
+
+static int wait_byte(int fd)
+{
+ char c;
+
+ return read(fd, &c, 1) == 1 ? 0 : -1;
+}
+
+static int send_byte(int fd)
+{
+ return write(fd, "x", 1) == 1 ? 0 : -1;
+}
+
+static int empty_mntns(void)
+{
+ if (!unshare(UNSHARE_EMPTY_MNTNS))
+ return 0;
+ return errno == EINVAL ? CHILD_UNSUPPORTED : CHILD_SETUP;
+}
+
+/* the watcher: stats its root before and after the reader read its own */
+static int watcher(int to_reader, int from_reader)
+{
+ struct stat before, after;
+ int ret;
+
+ ret = empty_mntns();
+ if (ret)
+ return ret;
+ if (stat("/", &before))
+ return CHILD_SETUP;
+ if (send_byte(to_reader) || wait_byte(from_reader))
+ return CHILD_SETUP;
+ if (stat("/", &after))
+ return CHILD_SETUP;
+ if (before.st_atim.tv_sec != after.st_atim.tv_sec ||
+ before.st_atim.tv_nsec != after.st_atim.tv_nsec)
+ return CHILD_CHANGED;
+ return CHILD_OK;
+}
+
+/* the reader: lists its own root, which is the same inode */
+static int reader(int to_watcher, int from_watcher)
+{
+ struct dirent *de;
+ DIR *d;
+ int ret;
+
+ ret = empty_mntns();
+ if (ret)
+ return ret;
+ if (wait_byte(from_watcher))
+ return CHILD_SETUP;
+ d = opendir("/");
+ if (!d)
+ return CHILD_SETUP;
+ while ((de = readdir(d)))
+ ;
+ closedir(d);
+ return send_byte(to_watcher) ? CHILD_SETUP : CHILD_OK;
+}
+
+static int wait_child(pid_t pid)
+{
+ int status;
+
+ if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status))
+ return -1;
+ return WEXITSTATUS(status);
+}
+
+TEST(empty_mntns_root_atime)
+{
+ int to_reader[2], to_watcher[2], w, r;
+ pid_t watcher_pid, reader_pid;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+ ASSERT_EQ(pipe(to_reader), 0);
+ ASSERT_EQ(pipe(to_watcher), 0);
+
+ watcher_pid = fork();
+ ASSERT_GE(watcher_pid, 0);
+ if (watcher_pid == 0)
+ _exit(watcher(to_reader[1], to_watcher[0]));
+ reader_pid = fork();
+ ASSERT_GE(reader_pid, 0);
+ if (reader_pid == 0)
+ _exit(reader(to_watcher[1], to_reader[0]));
+
+ r = wait_child(reader_pid);
+ w = wait_child(watcher_pid);
+ if (r == CHILD_UNSUPPORTED || w == CHILD_UNSUPPORTED)
+ SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
+ EXPECT_EQ(r, CHILD_OK);
+ EXPECT_EQ(w, CHILD_OK)
+ TH_LOG("the access time of the root changed while this namespace did nothing");
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c b/tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c
new file mode 100644
index 0000000000000..0ff5442470270
--- /dev/null
+++ b/tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Reading the root of an empty mount namespace holds nothing that anybody
+ * else waits for: the directory never has an entry, so a readdir stuck in
+ * the page fault of its buffer stalls neither a create nor a lookup in it.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "../../kselftest_harness.h"
+#include "../readdir_hold.h"
+#include "empty_mntns.h"
+
+TEST(readdir_blocks_nobody)
+{
+ struct readdir_hold hold;
+ bool stalled;
+ int dfd;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+ if (readdir_hold_init(&hold))
+ SKIP(return, "test requires userfaultfd");
+ if (unshare(UNSHARE_EMPTY_MNTNS)) {
+ readdir_hold_destroy(&hold);
+ if (errno == EINVAL)
+ SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
+ ASSERT_TRUE(false)
+ TH_LOG("unshare(UNSHARE_EMPTY_MNTNS): %m");
+ }
+ dfd = open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(dfd, 0);
+ ASSERT_EQ(readdir_hold_check(&hold, dfd, &stalled), 0);
+ /* the lookup came back while the readdir was stuck in its fault */
+ EXPECT_FALSE(stalled);
+ close(dfd);
+ readdir_hold_destroy(&hold);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/overlayfs/.gitignore b/tools/testing/selftests/filesystems/overlayfs/.gitignore
index 077f7a1281687..b343cc430051d 100644
--- a/tools/testing/selftests/filesystems/overlayfs/.gitignore
+++ b/tools/testing/selftests/filesystems/overlayfs/.gitignore
@@ -2,3 +2,4 @@
dev_in_maps
set_layers_via_fds
idmapped_mounts
+automount_in_layer
diff --git a/tools/testing/selftests/filesystems/overlayfs/Makefile b/tools/testing/selftests/filesystems/overlayfs/Makefile
index b3185f684add6..382a59bda5e70 100644
--- a/tools/testing/selftests/filesystems/overlayfs/Makefile
+++ b/tools/testing/selftests/filesystems/overlayfs/Makefile
@@ -9,6 +9,7 @@ LOCAL_HDRS += ../wrappers.h log.h
TEST_GEN_PROGS := dev_in_maps
TEST_GEN_PROGS += set_layers_via_fds
TEST_GEN_PROGS += idmapped_mounts
+TEST_GEN_PROGS += automount_in_layer
include ../../lib.mk
diff --git a/tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c b/tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c
new file mode 100644
index 0000000000000..0476c4582bdfc
--- /dev/null
+++ b/tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c
@@ -0,0 +1,174 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * A layer of an overlay is a private clone of the mount it was given and
+ * belongs to no mount namespace. fanotify hands out descriptors on it. An
+ * automount triggered through one has no namespace to go into: the open has
+ * to fail, not oops with namespace_sem held.
+ */
+#define _GNU_SOURCE
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/magic.h>
+#include <sys/fanotify.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/vfs.h>
+
+#include "../../kselftest_harness.h"
+
+#define DIR_LEN 64
+#define PATH_LEN 192
+
+static bool have_fs(const char *name)
+{
+ char line[128];
+ bool found = false;
+ FILE *f;
+
+ f = fopen("/proc/filesystems", "re");
+ if (!f)
+ return false;
+ while (fgets(line, sizeof(line), f)) {
+ char *nl = strchr(line, '\n');
+ char *tab = strchr(line, '\t');
+
+ if (nl)
+ *nl = 0;
+ if (tab && !strcmp(tab + 1, name))
+ found = true;
+ }
+ fclose(f);
+ return found;
+}
+
+static int mnt_id_of(int fd)
+{
+ char path[64], buf[4096], *p;
+ ssize_t n;
+ int info;
+
+ snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd);
+ info = open(path, O_RDONLY | O_CLOEXEC);
+ if (info < 0)
+ return -1;
+ n = read(info, buf, sizeof(buf) - 1);
+ close(info);
+ if (n <= 0)
+ return -1;
+ buf[n] = 0;
+ p = strstr(buf, "mnt_id:");
+ return p ? atoi(p + strlen("mnt_id:")) : -1;
+}
+
+static bool on_debugfs(int fd)
+{
+ struct statfs sf;
+
+ return !fstatfs(fd, &sf) && sf.f_type == DEBUGFS_MAGIC;
+}
+
+FIXTURE(layer) {
+ char base[DIR_LEN];
+ int fan;
+ int evfd; /* on the layer clone of the lower debugfs */
+};
+
+FIXTURE_SETUP(layer)
+{
+ char lower[PATH_LEN], other[PATH_LEN], ovl[PATH_LEN], opts[2 * PATH_LEN + 16];
+ struct fanotify_event_metadata *ev;
+ struct pollfd pfd;
+ char buf[4096];
+ int lfd, lower_id;
+ ssize_t n;
+ DIR *d;
+
+ self->fan = -1;
+ self->evfd = -1;
+ if (geteuid())
+ SKIP(return, "test requires root");
+ if (!have_fs("debugfs") || !have_fs("tracefs"))
+ SKIP(return, "test requires debugfs with the tracefs automount");
+ if (!have_fs("overlay"))
+ SKIP(return, "test requires overlayfs");
+
+ snprintf(self->base, sizeof(self->base), "/tmp/layer.XXXXXX");
+ ASSERT_NE(mkdtemp(self->base), NULL);
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+ ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, "mode=0755"), 0);
+ snprintf(lower, sizeof(lower), "%s/lower", self->base);
+ snprintf(other, sizeof(other), "%s/other", self->base);
+ snprintf(ovl, sizeof(ovl), "%s/ovl", self->base);
+ ASSERT_EQ(mkdir(lower, 0755), 0);
+ ASSERT_EQ(mkdir(other, 0755), 0);
+ ASSERT_EQ(mkdir(ovl, 0755), 0);
+ ASSERT_EQ(mount("debugfs", lower, "debugfs", 0, NULL), 0);
+ snprintf(opts, sizeof(opts), "lowerdir=%s:%s", lower, other);
+ ASSERT_EQ(mount("overlay", ovl, "overlay", MS_RDONLY, opts), 0);
+
+ self->fan = fanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK | FAN_CLOEXEC,
+ O_RDONLY | O_CLOEXEC);
+ ASSERT_GE(self->fan, 0);
+ ASSERT_EQ(fanotify_mark(self->fan, FAN_MARK_ADD | FAN_MARK_FILESYSTEM,
+ FAN_OPEN | FAN_ONDIR, AT_FDCWD, lower), 0);
+ lfd = open(lower, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(lfd, 0);
+ lower_id = mnt_id_of(lfd);
+ close(lfd);
+
+ /* the overlay opens its lower directory through the layer clone */
+ d = opendir(ovl);
+ ASSERT_NE(d, NULL);
+ closedir(d);
+ pfd.fd = self->fan;
+ pfd.events = POLLIN;
+ ASSERT_EQ(poll(&pfd, 1, 5000), 1);
+ n = read(self->fan, buf, sizeof(buf));
+ ASSERT_GT(n, 0);
+ for (ev = (void *)buf; FAN_EVENT_OK(ev, n); ev = FAN_EVENT_NEXT(ev, n)) {
+ if (ev->fd < 0)
+ continue;
+ if (self->evfd < 0 && on_debugfs(ev->fd) &&
+ mnt_id_of(ev->fd) != lower_id)
+ self->evfd = ev->fd;
+ else
+ close(ev->fd);
+ }
+ ASSERT_GE(self->evfd, 0)
+ TH_LOG("no event on the layer clone");
+}
+
+FIXTURE_TEARDOWN(layer)
+{
+ if (self->evfd >= 0)
+ close(self->evfd);
+ if (self->fan >= 0)
+ close(self->fan);
+ umount2(self->base, MNT_DETACH);
+ rmdir(self->base);
+}
+
+TEST_F(layer, automount_below_the_clone_is_refused)
+{
+ struct stat st;
+ int fd;
+
+ /* the automount point is there */
+ ASSERT_EQ(fstatat(self->evfd, "tracing", &st, AT_NO_AUTOMOUNT), 0);
+ /* the clone is in no namespace, so the automount has nowhere to go */
+ fd = openat(self->evfd, "tracing", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ EXPECT_LT(fd, 0);
+ EXPECT_EQ(errno, EINVAL);
+ if (fd >= 0)
+ close(fd);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/readdir_hold.h b/tools/testing/selftests/filesystems/readdir_hold.h
new file mode 100644
index 0000000000000..57eee1bef4700
--- /dev/null
+++ b/tools/testing/selftests/filesystems/readdir_hold.h
@@ -0,0 +1,224 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Hold a readdir of a directory in the page fault of its buffer and see
+ * whether a create and a lookup in that directory wait for it. For a
+ * directory that is permanently empty they must not.
+ */
+#ifndef __SELFTESTS_READDIR_HOLD_H
+#define __SELFTESTS_READDIR_HOLD_H
+
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/userfaultfd.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+
+#define HOLD_FAULT_MS 5000 /* for the reader to reach the fault */
+#define HOLD_QUEUE_MS 2000 /* for the create to queue up behind it */
+#define HOLD_LOOKUP_MS 5000 /* for the lookup to come back */
+
+struct readdir_hold {
+ int uffd;
+ int taskdir; /* /proc/self/task, from before any namespace change */
+ long page_size;
+ char *page; /* faults until released */
+ int dfd;
+ pid_t creator_tid;
+ int created;
+ int done[2]; /* the finder writes a byte when it is back */
+};
+
+/*
+ * The fault happens in the kernel, so the userfaultfd needs CAP_SYS_PTRACE
+ * in the initial user namespace or vm.unprivileged_userfaultfd. Call this
+ * before entering a user namespace.
+ */
+static inline int readdir_hold_init(struct readdir_hold *h)
+{
+ struct uffdio_api api = { .api = UFFD_API };
+
+ h->page = MAP_FAILED;
+ h->page_size = sysconf(_SC_PAGESIZE);
+ h->taskdir = open("/proc/self/task", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ h->uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
+ if (h->uffd < 0 || h->taskdir < 0 || ioctl(h->uffd, UFFDIO_API, &api)) {
+ if (h->uffd >= 0)
+ close(h->uffd);
+ if (h->taskdir >= 0)
+ close(h->taskdir);
+ h->uffd = h->taskdir = -1;
+ return -1;
+ }
+ return 0;
+}
+
+static inline void readdir_hold_destroy(struct readdir_hold *h)
+{
+ if (h->uffd >= 0)
+ close(h->uffd);
+ if (h->taskdir >= 0)
+ close(h->taskdir);
+ h->uffd = h->taskdir = -1;
+}
+
+static inline void *readdir_hold_reader(void *arg)
+{
+ struct readdir_hold *h = arg;
+
+ /* the first byte written to the buffer faults until released */
+ syscall(__NR_getdents64, h->dfd, h->page, h->page_size);
+ return NULL;
+}
+
+static inline void *readdir_hold_creator(void *arg)
+{
+ struct readdir_hold *h = arg;
+
+ h->creator_tid = syscall(__NR_gettid);
+ /* takes the directory lock exclusive before it fails */
+ mkdirat(h->dfd, "x", 0755);
+ __atomic_store_n(&h->created, 1, __ATOMIC_RELEASE);
+ return NULL;
+}
+
+static inline void *readdir_hold_finder(void *arg)
+{
+ struct readdir_hold *h = arg;
+ int fd;
+
+ /* a lookup that misses the dcache takes the lock shared */
+ fd = openat(h->dfd, "no_such_name", O_RDONLY | O_CLOEXEC);
+ if (fd >= 0)
+ close(fd);
+ if (write(h->done[1], "x", 1) != 1)
+ perror("readdir_hold: finder");
+ return NULL;
+}
+
+/* the creator is back, or waits in the kernel for the lock */
+static inline bool readdir_hold_creator_settled(struct readdir_hold *h)
+{
+ char path[32], buf[256], *p;
+ ssize_t n;
+ int fd;
+
+ if (__atomic_load_n(&h->created, __ATOMIC_ACQUIRE))
+ return true;
+ if (!h->creator_tid)
+ return false;
+ snprintf(path, sizeof(path), "%d/stat", h->creator_tid);
+ fd = openat(h->taskdir, path, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return false;
+ n = read(fd, buf, sizeof(buf) - 1);
+ close(fd);
+ if (n <= 0)
+ return false;
+ buf[n] = 0;
+ /* "pid (comm) state ..." */
+ p = strrchr(buf, ')');
+ return p && p[1] == ' ' && p[2] == 'D';
+}
+
+static inline bool readdir_hold_faulted(struct readdir_hold *h)
+{
+ struct pollfd pfd = { .fd = h->uffd, .events = POLLIN };
+ struct uffd_msg msg;
+
+ if (poll(&pfd, 1, HOLD_FAULT_MS) != 1)
+ return false;
+ if (read(h->uffd, &msg, sizeof(msg)) != sizeof(msg))
+ return false;
+ return msg.event == UFFD_EVENT_PAGEFAULT;
+}
+
+/* let the reader go on */
+static inline void readdir_hold_release(struct readdir_hold *h)
+{
+ struct uffdio_copy cp = {
+ .dst = (unsigned long)h->page,
+ .len = h->page_size,
+ };
+ void *zero;
+
+ zero = calloc(1, h->page_size);
+ if (!zero)
+ return;
+ cp.src = (unsigned long)zero;
+ if (ioctl(h->uffd, UFFDIO_COPY, &cp) && errno != EEXIST)
+ perror("readdir_hold: UFFDIO_COPY");
+ free(zero);
+}
+
+/*
+ * A readdir of @dfd that sticks in the fault of its buffer, then a create
+ * and a lookup in @dfd. Whether the lookup came back while the readdir was
+ * still stuck goes to @stalled. Returns -1 when that could not be found
+ * out.
+ */
+static inline int readdir_hold_check(struct readdir_hold *h, int dfd,
+ bool *stalled)
+{
+ pthread_t reader, creator, finder;
+ struct uffdio_register reg = {};
+ struct pollfd pfd;
+ int ret = -1, i;
+
+ h->dfd = dfd;
+ h->created = 0;
+ h->creator_tid = 0;
+ h->page = mmap(NULL, h->page_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (h->page == MAP_FAILED)
+ return -1;
+ reg.range.start = (unsigned long)h->page;
+ reg.range.len = h->page_size;
+ reg.mode = UFFDIO_REGISTER_MODE_MISSING;
+ if (ioctl(h->uffd, UFFDIO_REGISTER, ®) || pipe2(h->done, O_CLOEXEC))
+ goto out_page;
+
+ if (pthread_create(&reader, NULL, readdir_hold_reader, h))
+ goto out_pipe;
+ if (!readdir_hold_faulted(h))
+ goto out_reader;
+ if (pthread_create(&creator, NULL, readdir_hold_creator, h))
+ goto out_reader;
+ for (i = 0; i < HOLD_QUEUE_MS / 10 && !readdir_hold_creator_settled(h); i++)
+ usleep(10000);
+ if (pthread_create(&finder, NULL, readdir_hold_finder, h))
+ goto out_creator;
+
+ pfd.fd = h->done[0];
+ pfd.events = POLLIN;
+ *stalled = poll(&pfd, 1, HOLD_LOOKUP_MS) != 1;
+ ret = 0;
+
+ readdir_hold_release(h);
+ pthread_join(finder, NULL);
+out_creator:
+ if (ret)
+ readdir_hold_release(h);
+ pthread_join(creator, NULL);
+out_reader:
+ if (ret)
+ readdir_hold_release(h);
+ pthread_join(reader, NULL);
+out_pipe:
+ close(h->done[0]);
+ close(h->done[1]);
+out_page:
+ munmap(h->page, h->page_size);
+ h->page = MAP_FAILED;
+ return ret;
+}
+
+#endif /* __SELFTESTS_READDIR_HOLD_H */
diff --git a/tools/testing/selftests/filesystems/rw_hint_test.c b/tools/testing/selftests/filesystems/rw_hint_test.c
new file mode 100644
index 0000000000000..d1930f82f63b5
--- /dev/null
+++ b/tools/testing/selftests/filesystems/rw_hint_test.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * F_SET_RW_HINT is refused on an immutable inode. Nothing is ever written
+ * to it and it may be shared with everybody, like a namespace file or the
+ * root of an empty mount namespace.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
+#include "../kselftest_harness.h"
+
+/* <linux/fs.h> and <linux/fcntl.h> don't mix with the libc headers */
+#ifndef FS_IOC_GETFLAGS
+#define FS_IOC_GETFLAGS _IOR('f', 1, long)
+#define FS_IOC_SETFLAGS _IOW('f', 2, long)
+#endif
+#ifndef FS_IMMUTABLE_FL
+#define FS_IMMUTABLE_FL 0x00000010
+#endif
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+#ifndef F_GET_RW_HINT
+#define F_GET_RW_HINT (F_LINUX_SPECIFIC_BASE + 11)
+#define F_SET_RW_HINT (F_LINUX_SPECIFIC_BASE + 12)
+#endif
+#ifndef RWH_WRITE_LIFE_SHORT
+#define RWH_WRITE_LIFE_SHORT 2
+#endif
+#ifndef UNSHARE_EMPTY_MNTNS
+#define UNSHARE_EMPTY_MNTNS 0x00100000
+#endif
+
+static int set_hint(int fd, uint64_t hint)
+{
+ return fcntl(fd, F_SET_RW_HINT, &hint);
+}
+
+static long get_hint(int fd)
+{
+ uint64_t hint;
+
+ if (fcntl(fd, F_GET_RW_HINT, &hint))
+ return -1;
+ return hint;
+}
+
+TEST(immutable_file)
+{
+ char path[] = "/tmp/rw_hint.XXXXXX";
+ int fd, flags;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+
+ fd = mkstemp(path);
+ ASSERT_GE(fd, 0);
+ unlink(path);
+ ASSERT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0);
+ EXPECT_EQ(get_hint(fd), RWH_WRITE_LIFE_SHORT);
+
+ if (ioctl(fd, FS_IOC_GETFLAGS, &flags)) {
+ close(fd);
+ SKIP(return, "no file attributes on this filesystem");
+ }
+ flags |= FS_IMMUTABLE_FL;
+ ASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, &flags), 0);
+ EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1);
+ EXPECT_EQ(errno, EPERM);
+ flags &= ~FS_IMMUTABLE_FL;
+ ASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, &flags), 0);
+ EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0);
+ close(fd);
+}
+
+TEST(namespace_file)
+{
+ int fd;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+
+ fd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1);
+ EXPECT_EQ(errno, EPERM);
+ close(fd);
+}
+
+TEST(empty_mntns_root)
+{
+ int status;
+ pid_t pid;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ int fd;
+
+ if (unshare(UNSHARE_EMPTY_MNTNS))
+ _exit(errno == EINVAL ? 100 : 1);
+ fd = open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ if (fd < 0)
+ _exit(2);
+ if (set_hint(fd, RWH_WRITE_LIFE_SHORT) == 0)
+ _exit(3);
+ _exit(errno == EPERM ? 0 : 4);
+ }
+ ASSERT_EQ(waitpid(pid, &status, 0), pid);
+ ASSERT_TRUE(WIFEXITED(status));
+ if (WEXITSTATUS(status) == 100)
+ SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
+ EXPECT_EQ(WEXITSTATUS(status), 0);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/umount_propagation/Makefile b/tools/testing/selftests/filesystems/umount_propagation/Makefile
index eb85612abf8d1..31f783a92b231 100644
--- a/tools/testing/selftests/filesystems/umount_propagation/Makefile
+++ b/tools/testing/selftests/filesystems/umount_propagation/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
-TEST_GEN_PROGS := umount_propagation_test shrink_submounts_test
+TEST_GEN_PROGS := umount_propagation_test shrink_submounts_test locked_mount_test
CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
diff --git a/tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c b/tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c
new file mode 100644
index 0000000000000..0799b2ba545d7
--- /dev/null
+++ b/tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c
@@ -0,0 +1,432 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * MNT_LOCKED keeps the owner of a user namespace from revealing what a
+ * mount covers. The lock has to be set on the copy in that namespace and
+ * only there, it has to survive the expiry of a mount placed beneath the
+ * locked one, and it has to survive the propagated umount of such a copy.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mount.h>
+#include <sys/prctl.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/wait.h>
+
+#include "../../kselftest_harness.h"
+
+#ifndef MOVE_MOUNT_F_EMPTY_PATH
+#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004
+#endif
+#ifndef MOVE_MOUNT_BENEATH
+#define MOVE_MOUNT_BENEATH 0x00000200
+#endif
+
+#define DIR_LEN 64
+#define PATH_LEN 192
+#define FLAGS (MS_NOSUID | MS_NODEV | MS_NOEXEC)
+
+/* exit codes of the children, each test says what they mean */
+enum {
+ CHILD_OK,
+ CHILD_SETUP,
+ CHILD_STEP1,
+ CHILD_STEP2,
+ CHILD_STEP3,
+ CHILD_STEP4,
+};
+
+static int write_file(const char *path, const char *s)
+{
+ ssize_t n = -1;
+ int fd;
+
+ fd = open(path, O_WRONLY | O_CLOEXEC);
+ if (fd >= 0) {
+ n = write(fd, s, strlen(s));
+ close(fd);
+ }
+ return n == (ssize_t)strlen(s) ? 0 : -1;
+}
+
+static int create_file(const char *path, const char *s)
+{
+ ssize_t n = -1;
+ int fd;
+
+ fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
+ if (fd >= 0) {
+ n = write(fd, s, strlen(s));
+ close(fd);
+ }
+ return n == (ssize_t)strlen(s) ? 0 : -1;
+}
+
+/* Root in a new user namespace with a copy of the mount namespace. */
+static int enter_userns(void)
+{
+ uid_t uid = getuid();
+ gid_t gid = getgid();
+ char map[32];
+
+ prctl(PR_SET_DUMPABLE, 1);
+ if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
+ return -1;
+ if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
+ return -1;
+ snprintf(map, sizeof(map), "0 %d 1", uid);
+ if (write_file("/proc/self/uid_map", map))
+ return -1;
+ snprintf(map, sizeof(map), "0 %d 1", gid);
+ if (write_file("/proc/self/gid_map", map))
+ return -1;
+ return setgid(0) || setuid(0) ? -1 : 0;
+}
+
+static int wait_child(pid_t pid)
+{
+ int status;
+
+ if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status))
+ return -1;
+ return WEXITSTATUS(status);
+}
+
+static int wait_byte(int fd)
+{
+ char c;
+
+ return read(fd, &c, 1) == 1 ? 0 : -1;
+}
+
+static int send_byte(int fd)
+{
+ return write(fd, "x", 1) == 1 ? 0 : -1;
+}
+
+/* A read of @path fails: the file is covered. */
+static bool covered(const char *path)
+{
+ int fd = open(path, O_RDONLY | O_CLOEXEC);
+
+ if (fd >= 0)
+ close(fd);
+ return fd < 0;
+}
+
+FIXTURE(locked_mount) {
+ char base[DIR_LEN];
+ bool tracing; /* debugfs with the tracefs automount is there */
+};
+
+FIXTURE_SETUP(locked_mount)
+{
+ char p[PATH_LEN];
+ struct stat st;
+
+ if (geteuid())
+ SKIP(return, "test requires root");
+
+ snprintf(self->base, sizeof(self->base), "/tmp/locked_mount.XXXXXX");
+ ASSERT_NE(mkdtemp(self->base), NULL);
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+ ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, "mode=0755"), 0);
+
+ /* an automount that a user can name: the tracefs below debugfs */
+ snprintf(p, sizeof(p), "%s/dbg", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ self->tracing = !mount("debugfs", p, "debugfs", FLAGS, NULL);
+ if (self->tracing) {
+ /* the cases trigger it themselves */
+ snprintf(p, sizeof(p), "%s/dbg/tracing", self->base);
+ self->tracing = !fstatat(AT_FDCWD, p, &st, AT_NO_AUTOMOUNT) &&
+ S_ISDIR(st.st_mode);
+ }
+}
+
+FIXTURE_TEARDOWN(locked_mount)
+{
+ umount2(self->base, MNT_DETACH);
+ rmdir(self->base);
+}
+
+/*
+ * The child keeps a directory descriptor on the host's debugfs mount, moves
+ * to a user namespace of its own and triggers the automount through the
+ * descriptor. The mount goes below the host's mount and propagates into the
+ * child's copy. The child's copy has to be locked, the host's not.
+ */
+static int automount_child(const char *base, int dfd, int to_host, int from_host)
+{
+ char p[PATH_LEN];
+ struct stat st;
+
+ if (enter_userns())
+ return CHILD_SETUP;
+ if (fstatat(dfd, "tracing/.", &st, 0))
+ return CHILD_STEP1;
+ if (send_byte(to_host) || wait_byte(from_host))
+ return CHILD_SETUP;
+ /* the flags of the copy are locked: EPERM */
+ snprintf(p, sizeof(p), "%s/dbg/tracing", base);
+ if (!mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL) || errno != EPERM)
+ return CHILD_STEP2;
+ return CHILD_OK;
+}
+
+TEST_F(locked_mount, automount_locked_in_the_triggering_namespace)
+{
+ int to_host[2], from_host[2], dfd, ret;
+ char p[PATH_LEN];
+ pid_t pid;
+
+ if (!self->tracing)
+ SKIP(return, "test requires debugfs with the tracefs automount");
+
+ snprintf(p, sizeof(p), "%s/dbg", self->base);
+ ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0);
+ dfd = open(p, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(dfd, 0);
+ ASSERT_EQ(pipe(to_host), 0);
+ ASSERT_EQ(pipe(from_host), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0)
+ _exit(automount_child(self->base, dfd, to_host[1], from_host[0]));
+ close(dfd);
+ ASSERT_EQ(wait_byte(to_host[0]), 0);
+
+ /* the host's own mount isn't locked: the flags can go */
+ snprintf(p, sizeof(p), "%s/dbg/tracing", self->base);
+ EXPECT_EQ(mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL), 0);
+
+ ASSERT_EQ(send_byte(from_host[1]), 0);
+ ret = wait_child(pid);
+ TH_LOG("child exit code %d", ret);
+ EXPECT_EQ(ret, CHILD_OK);
+}
+
+/*
+ * A copy of a tree with a locked cover. The child puts a shrinkable mount
+ * beneath the cover, which hands the lock down, unmounts the cover and then
+ * asks for the umount of an unlocked ancestor. That expires the shrinkable
+ * mount on a kernel that doesn't look at the lock, and the covered
+ * directory is bare.
+ */
+static int expiry_child(const char *base)
+{
+ char srv[PATH_LEN], shr[PATH_LEN], x[PATH_LEN], c[PATH_LEN];
+ char hidden[PATH_LEN], secret[PATH_LEN];
+
+ snprintf(srv, sizeof(srv), "%s/srv", base);
+ snprintf(shr, sizeof(shr), "%s/shr", base);
+ snprintf(x, sizeof(x), "%s/x", base);
+ snprintf(c, sizeof(c), "%s/c", base);
+ snprintf(hidden, sizeof(hidden), "%s/x/hidden", base);
+ snprintf(secret, sizeof(secret), "%s/x/hidden/secret", base);
+
+ if (enter_userns())
+ return CHILD_SETUP;
+ if (mount(srv, x, NULL, MS_BIND | MS_REC, NULL) ||
+ mount(shr, c, NULL, MS_BIND, NULL))
+ return CHILD_SETUP;
+ /* the cover is locked */
+ if (!umount2(hidden, 0) || errno != EINVAL)
+ return CHILD_STEP1;
+ if (syscall(__NR_move_mount, AT_FDCWD, c, AT_FDCWD, hidden, MOVE_MOUNT_BENEATH))
+ return CHILD_STEP2;
+ /* the lock moved down, the cover may go */
+ if (umount2(hidden, 0))
+ return CHILD_STEP3;
+ /* the holder of the lock may not, in any way */
+ if (!umount2(hidden, 0) || errno != EINVAL)
+ return CHILD_STEP4;
+ if (chdir(x))
+ return CHILD_SETUP;
+ umount2(x, 0);
+ return covered(secret) ? CHILD_OK : CHILD_STEP4;
+}
+
+TEST_F(locked_mount, expiry_leaves_a_locked_mount_alone)
+{
+ char p[PATH_LEN], q[PATH_LEN];
+ pid_t pid;
+ int ret;
+
+ if (!self->tracing)
+ SKIP(return, "test requires debugfs with the tracefs automount");
+
+ snprintf(p, sizeof(p), "%s/dbg/tracing", self->base);
+ snprintf(q, sizeof(q), "%s/shr", self->base);
+ ASSERT_EQ(mkdir(q, 0755), 0);
+ /* a bind of an automount is shrinkable as well */
+ ASSERT_EQ(mount(p, q, NULL, MS_BIND, NULL), 0);
+ snprintf(p, sizeof(p), "%s/srv", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
+ snprintf(p, sizeof(p), "%s/srv/hidden", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ snprintf(p, sizeof(p), "%s/srv/hidden/secret", self->base);
+ ASSERT_EQ(create_file(p, "covered-by-root\n"), 0);
+ snprintf(p, sizeof(p), "%s/srv/hidden", self->base);
+ ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
+ snprintf(p, sizeof(p), "%s/x", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ snprintf(p, sizeof(p), "%s/c", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0)
+ _exit(expiry_child(self->base));
+ ret = wait_child(pid);
+ TH_LOG("child exit code %d", ret);
+ EXPECT_EQ(ret, CHILD_OK);
+}
+
+/*
+ * The copy of the mount tree that a user namespace gets at its creation has
+ * the automounts in it locked unless they are on an expiry list. A bind of
+ * such a tree inside the namespace copies the lock to the automount but not
+ * to the root of the bind, so the child may ask for the umount of that root.
+ * That must not expire the locked automount below it: the root is busy, the
+ * umount fails and the automount has to be there afterwards.
+ */
+static int copied_tree_child(const char *base)
+{
+ char dbg[PATH_LEN], x[PATH_LEN], tracing[PATH_LEN];
+ struct stat root, st;
+
+ snprintf(dbg, sizeof(dbg), "%s/dbg", base);
+ snprintf(x, sizeof(x), "%s/x", base);
+ snprintf(tracing, sizeof(tracing), "%s/x/tracing", base);
+
+ if (enter_userns())
+ return CHILD_SETUP;
+ if (mount(dbg, x, NULL, MS_BIND | MS_REC, NULL))
+ return CHILD_SETUP;
+ /* the copy of the automount carries the lock */
+ if (!umount2(tracing, 0) || errno != EINVAL)
+ return CHILD_STEP1;
+ /* the root of the bind doesn't; keep it busy */
+ if (chdir(x))
+ return CHILD_SETUP;
+ if (!umount2(x, 0) || errno != EBUSY)
+ return CHILD_STEP2;
+ /* the automount below it must not have gone */
+ if (stat(x, &root) || fstatat(AT_FDCWD, tracing, &st, AT_NO_AUTOMOUNT))
+ return CHILD_SETUP;
+ return st.st_dev != root.st_dev ? CHILD_OK : CHILD_STEP3;
+}
+
+TEST_F(locked_mount, umount_of_a_bind_leaves_a_locked_automount_alone)
+{
+ char p[PATH_LEN];
+ struct stat st;
+ pid_t pid;
+ int ret;
+
+ if (!self->tracing)
+ SKIP(return, "test requires debugfs with the tracefs automount");
+
+ /* the copy the child gets has to contain the automount */
+ snprintf(p, sizeof(p), "%s/dbg/tracing/.", self->base);
+ ASSERT_EQ(stat(p, &st), 0);
+ snprintf(p, sizeof(p), "%s/x", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0)
+ _exit(copied_tree_child(self->base));
+ ret = wait_child(pid);
+ TH_LOG("child exit code %d", ret);
+ EXPECT_EQ(ret, CHILD_OK);
+}
+
+/*
+ * Z is a user namespace with a copy of a tree in which P/d is covered by a
+ * locked mount. The host mounts X on P/d, which propagates beneath Z's
+ * cover, and unmounts it again. Z's cover has to be locked afterwards as
+ * it was before.
+ */
+static int propagation_child(const char *base, int to_host, int from_host)
+{
+ char d[PATH_LEN], secret[PATH_LEN];
+
+ snprintf(d, sizeof(d), "%s/P/d", base);
+ snprintf(secret, sizeof(secret), "%s/P/d/secret", base);
+
+ if (enter_userns())
+ return CHILD_SETUP;
+ /* the cover is locked */
+ if (!umount2(d, 0) || errno != EINVAL)
+ return CHILD_STEP1;
+ if (send_byte(to_host) || wait_byte(from_host))
+ return CHILD_SETUP;
+ /* X came and went beneath it: still locked */
+ if (!umount2(d, 0) || errno != EINVAL)
+ return CHILD_STEP2;
+ return covered(secret) ? CHILD_OK : CHILD_STEP3;
+}
+
+TEST_F(locked_mount, propagated_copy_keeps_the_cover_locked)
+{
+ int to_host[2], from_host[2], ret;
+ char p[PATH_LEN];
+ pid_t pid;
+
+ snprintf(p, sizeof(p), "%s/P", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
+ ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0);
+ snprintf(p, sizeof(p), "%s/P/d", self->base);
+ ASSERT_EQ(mkdir(p, 0755), 0);
+ snprintf(p, sizeof(p), "%s/P/d/secret", self->base);
+ ASSERT_EQ(create_file(p, "covered-by-root\n"), 0);
+ ASSERT_EQ(pipe(to_host), 0);
+ ASSERT_EQ(pipe(from_host), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ /* M: a manager's namespace that covers P/d for Z */
+ pid_t z;
+
+ if (unshare(CLONE_NEWNS))
+ _exit(CHILD_SETUP);
+ snprintf(p, sizeof(p), "%s/P", self->base);
+ if (mount(NULL, p, NULL, MS_SLAVE, NULL))
+ _exit(CHILD_SETUP);
+ snprintf(p, sizeof(p), "%s/P/d", self->base);
+ if (mount("tmpfs", p, "tmpfs", 0, "mode=0755"))
+ _exit(CHILD_SETUP);
+ z = fork();
+ if (z < 0)
+ _exit(CHILD_SETUP);
+ if (z == 0)
+ _exit(propagation_child(self->base, to_host[1], from_host[0]));
+ _exit(wait_child(z));
+ }
+ ASSERT_EQ(wait_byte(to_host[0]), 0);
+
+ /* the host mounts on P/d and unmounts again; both propagate */
+ snprintf(p, sizeof(p), "%s/P/d", self->base);
+ ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
+ ASSERT_EQ(umount2(p, 0), 0);
+
+ ASSERT_EQ(send_byte(from_host[1]), 0);
+ ret = wait_child(pid);
+ TH_LOG("child exit code %d", ret);
+ EXPECT_EQ(ret, CHILD_OK);
+}
+
+TEST_HARNESS_MAIN
|
| 61/3 | 2026/10/03 03:37 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23508 output: 19 thoughts: 1502 Thoughts: **KMSAN Fuzzing Evaluation** Alright, let's break this down. The user wants me to assess the need for a KMSAN fuzzing session based on this patch. I'm going to carefully consider each change to see if it introduces any potential risks related to uninitialized memory being exposed to user space. Firstly, the patch modifies a number of files. There's a check in `fs/fcntl.c` that prevents `F_SET_RW_HINT` on immutable inodes, which seems straightforward and unlikely to cause a KMSAN issue. Then, `fs/fhandle.c` adds a function `subtree_unobstructed` which appears to handle mount-related checks, using a reader lock and capable-mount checks. This function's usage in `may_decode_fh` warrants a close look, but the RAII guard makes it less likely to be an immediate KMSAN candidate. Next up, the patch touches a bunch of mount-related code in `fs/mount.h` and `fs/namespace.c`. There are tweaks around locked mounts, anonymous namespaces, child mount locking and unlocking, and some `knullfs` initialization. The changes around `MNT_LOCKED` and the introduction of `knullfs` seem interesting, and I'll need to pay close attention to any data structures or pointers that are introduced or modified related to those. Specifically, the added `VFS_WARN_ON_ONCE` in `mark_mounts_for_expiry` and the checks using `IS_MNT_LOCKED` in `shrink_submount` and `init_mount_tree` may be worth examining, as well as the changes around `has_locked_children`. I also need to assess whether the use of the `knullfs` filesystem could introduce any new vulnerabilities, particularly if user space can interact with it. The `fs/namei.c` change introduces a `unlink_may_reveal` function, used in `step_into_slowpath`. This looks like a race condition protection for name resolution. I will need to be very careful here, as race condition mitigations are often sources of memory corruption issues. It's checking for unlinked directories and mount points. The interaction between this function and the path traversal logic is where a bug could rear its head. I will need to understand the exact conditions under which this `unlink_may_reveal` function returns true. In `fs/notify/mark.c`, the patch adds a check to see if a filesystem disallows notifications. This doesn't seem like a KMSAN risk. Now the `fs/nullfs.c` changes are worth significant scrutiny. This patch adds `nullfs_dir_operations`, modifies the readdir implementation by adding `dir_emit_dots(file, ctx)`, and sets `FS_DISALLOW_NOTIFY` flag. The critical piece here is `dir_emit_dots` and how it interacts with the readdir functionality. The fact that the directory operations are marked immutable is interesting, but not alarming. The `nullfs_dir_readdir` change is the key thing, because KMSAN is usually about uninitialized memory being read. The readdir's interaction with the immutable flag might be a concern here, so I'll need to confirm what `dir_emit_dots` does in this context, because of this potentially unusual combination. Finally, `fs/readdir.c` now uses a lock around readdir if `FOP_IMMUTABLE` is not set. This also is a spot to carefully inspect. The addition of `FOP_IMMUTABLE`, which relates to locking/unlocking, are important. The addition of the lock/unlock around readdir is interesting. So, the biggest KMSAN risk here, as it stands, seems to be the changes in the `nullfs` filesystem, particularly the interactions between the readdir implementation, `dir_emit_dots`, the immutable flag, and how that interacts with the added lock and the possibility of data being returned to user space in the `nullfs` case. Let's delve deep into the `dir_emit_dots` function in the kernel. |
| 62/3 | 2026/10/03 03:37 | tool | grepper |
0mArgs:{
"Expression": "dir_emit_dots"
}Results: {
"Output": "fs/affs/dir.c=78=affs_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/affs/dir.c-96-\t\tdata-\u003eino = 0;\nfs/affs/dir.c:97:\t\tif (!dir_emit_dots(file, ctx))\nfs/affs/dir.c-98-\t\t\treturn 0;\n--\nfs/afs/dynroot.c=330=static int afs_dynroot_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/afs/dynroot.c-334-\nfs/afs/dynroot.c:335:\tif (!dir_emit_dots(file, ctx))\nfs/afs/dynroot.c-336-\t\treturn 0;\n--\nfs/btrfs/btrfs_inode.h=34=struct btrfs_delayed_node;\n--\nfs/btrfs/btrfs_inode.h-38- * to start at 2 since '.' and '..' have f_pos of 0 and 1 respectively, so\nfs/btrfs/btrfs_inode.h:39: * everybody else has to start at 2 (see btrfs_real_readdir() and dir_emit_dots()).\nfs/btrfs/btrfs_inode.h-40- */\n--\nfs/btrfs/inode.c=6310=static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/btrfs/inode.c-6329-\nfs/btrfs/inode.c:6330:\tif (!dir_emit_dots(file, ctx))\nfs/btrfs/inode.c-6331-\t\treturn 0;\n--\nfs/coda/dir.c=353=static int coda_venus_readdir(struct file *coda_file, struct dir_context *ctx)\n--\nfs/coda/dir.c-372-\nfs/coda/dir.c:373:\tif (!dir_emit_dots(coda_file, ctx))\nfs/coda/dir.c-374-\t\tgoto out;\n--\nfs/configfs/dir.c=1639=static int configfs_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/configfs/dir.c-1647-\nfs/configfs/dir.c:1648:\tif (!dir_emit_dots(file, ctx))\nfs/configfs/dir.c-1649-\t\treturn 0;\n--\nfs/exfat/dir.c=196=static int exfat_iterate(struct file *file, struct dir_context *ctx)\n--\nfs/exfat/dir.c-210-\tcpos = ctx-\u003epos;\nfs/exfat/dir.c:211:\tif (!dir_emit_dots(file, ctx))\nfs/exfat/dir.c-212-\t\tgoto out;\n--\nfs/fat/dir.c=592=static int __fat_readdir(struct inode *inode, struct file *file,\n--\nfs/fat/dir.c-614-\tif (inode-\u003ei_ino == MSDOS_ROOT_INO) {\nfs/fat/dir.c:615:\t\tif (!dir_emit_dots(file, ctx))\nfs/fat/dir.c-616-\t\t\tgoto out;\n--\nfs/jffs2/dir.c=125=static int jffs2_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/jffs2/dir.c-133-\nfs/jffs2/dir.c:134:\tif (!dir_emit_dots(file, ctx))\nfs/jffs2/dir.c-135-\t\treturn 0;\n--\nfs/kernfs/dir.c=1970=static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/kernfs/dir.c-1977-\nfs/kernfs/dir.c:1978:\tif (!dir_emit_dots(file, ctx))\nfs/kernfs/dir.c-1979-\t\treturn 0;\n--\nfs/libfs.c=189=int dcache_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/libfs.c-195-\nfs/libfs.c:196:\tif (!dir_emit_dots(file, ctx))\nfs/libfs.c-197-\t\treturn 0;\n--\nfs/libfs.c=554=static int offset_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/libfs.c-559-\nfs/libfs.c:560:\tif (!dir_emit_dots(file, ctx))\nfs/libfs.c-561-\t\treturn 0;\n--\nfs/libfs.c=1753=static int empty_dir_readdir(struct file *file, struct dir_context *ctx)\nfs/libfs.c-1754-{\nfs/libfs.c:1755:\tdir_emit_dots(file, ctx);\nfs/libfs.c-1756-\treturn 0;\n--\nfs/ntfs/dir.c=718=static int ntfs_readdir(struct file *file, struct dir_context *actor)\n--\nfs/ntfs/dir.c-760-\t/* Emulate . and .. for all directories. */\nfs/ntfs/dir.c:761:\tif (!dir_emit_dots(file, actor))\nfs/ntfs/dir.c-762-\t\treturn 0;\n--\nfs/ntfs3/dir.c=442=static int ntfs_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/ntfs3/dir.c-511-\nfs/ntfs3/dir.c:512:\tif (!dir_emit_dots(file, ctx))\nfs/ntfs3/dir.c-513-\t\treturn 0;\n--\nfs/nullfs.c=19=static int nullfs_dir_readdir(struct file *file, struct dir_context *ctx)\nfs/nullfs.c-20-{\nfs/nullfs.c:21:\tdir_emit_dots(file, ctx);\nfs/nullfs.c-22-\treturn 0;\n--\nfs/omfs/dir.c=408=static int omfs_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/omfs/dir.c-419-\tif (ctx-\u003epos \u003c 1 \u003c\u003c 20) {\nfs/omfs/dir.c:420:\t\tif (!dir_emit_dots(file, ctx))\nfs/omfs/dir.c-421-\t\t\treturn 0;\n--\nfs/proc/base.c=2376=proc_map_files_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/proc/base.c-2394-\tret = 0;\nfs/proc/base.c:2395:\tif (!dir_emit_dots(file, ctx))\nfs/proc/base.c-2396-\t\tgoto out_put_task;\n--\nfs/proc/base.c=2711=static int proc_pident_readdir(struct file *file, struct dir_context *ctx,\n--\nfs/proc/base.c-2719-\nfs/proc/base.c:2720:\tif (!dir_emit_dots(file, ctx))\nfs/proc/base.c-2721-\t\tgoto out;\n--\nfs/proc/base.c=3897=static int proc_task_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/proc/base.c-3906-\nfs/proc/base.c:3907:\tif (!dir_emit_dots(file, ctx))\nfs/proc/base.c-3908-\t\treturn 0;\n--\nfs/proc/fd.c=243=static int proc_readfd_common(struct file *file, struct dir_context *ctx,\n--\nfs/proc/fd.c-251-\nfs/proc/fd.c:252:\tif (!dir_emit_dots(file, ctx))\nfs/proc/fd.c-253-\t\tgoto out;\n--\nfs/proc/generic.c=289=int proc_readdir_de(struct file *file, struct dir_context *ctx,\n--\nfs/proc/generic.c-293-\nfs/proc/generic.c:294:\tif (!dir_emit_dots(file, ctx))\nfs/proc/generic.c-295-\t\treturn 0;\n--\nfs/proc/namespaces.c=131=static int proc_ns_dir_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/proc/namespaces.c-138-\nfs/proc/namespaces.c:139:\tif (!dir_emit_dots(file, ctx))\nfs/proc/namespaces.c-140-\t\tgoto out;\n--\nfs/proc/proc_sysctl.c=762=static int proc_sys_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/proc/proc_sysctl.c-774-\nfs/proc/proc_sysctl.c:775:\tif (!dir_emit_dots(file, ctx))\nfs/proc/proc_sysctl.c-776-\t\tgoto out;\n--\nfs/smb/client/readdir.c=1055=int cifs_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/smb/client/readdir.c-1110-\tif (cfid-\u003edirents.is_valid) {\nfs/smb/client/readdir.c:1111:\t\tif (!dir_emit_dots(file, ctx)) {\nfs/smb/client/readdir.c-1112-\t\t\tmutex_unlock(\u0026cfid-\u003edirents.de_mutex);\n--\nfs/smb/client/readdir.c-1139-\nfs/smb/client/readdir.c:1140:\tif (!dir_emit_dots(file, ctx))\nfs/smb/client/readdir.c-1141-\t\tgoto rddir2_exit;\n--\nfs/tracefs/event_inode.c=579=static int eventfs_iterate(struct file *file, struct dir_context *ctx)\n--\nfs/tracefs/event_inode.c-591-\nfs/tracefs/event_inode.c:592:\tif (!dir_emit_dots(file, ctx))\nfs/tracefs/event_inode.c-593-\t\treturn 0;\n--\nfs/ubifs/dir.c=580=static int ubifs_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/ubifs/dir.c-633-\t\tubifs_assert(c, !data-\u003edent);\nfs/ubifs/dir.c:634:\t\tif (!dir_emit_dots(file, ctx)) {\nfs/ubifs/dir.c-635-\t\t\tif (encrypted)\n--\nfs/zonefs/super.c=752=static int zonefs_readdir_root(struct file *file, struct dir_context *ctx)\n--\nfs/zonefs/super.c-762-\nfs/zonefs/super.c:763:\tif (!dir_emit_dots(file, ctx))\nfs/zonefs/super.c-764-\t\treturn 0;\n--\nfs/zonefs/super.c=787=static int zonefs_readdir_zgroup(struct file *file,\n--\nfs/zonefs/super.c-807-\nfs/zonefs/super.c:808:\tif (!dir_emit_dots(file, ctx))\nfs/zonefs/super.c-809-\t\treturn 0;\n--\ninclude/linux/fs.h=3617=static inline bool dir_emit_dotdot(struct file *file, struct dir_context *ctx)\n--\ninclude/linux/fs.h-3621-}\ninclude/linux/fs.h:3622:static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx)\ninclude/linux/fs.h-3623-{\n"
} |
| 63/3 | 2026/10/03 03:37 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29073 output: 35 thoughts: 59 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing Redundancy in Directory Reading Functions** Alright, my internal radar just pinged. I've noticed a code pattern; `nullfs_dir_readdir` is *exactly* the same as `empty_dir_readdir` in `fs/libfs.c` at line 1753. That's a classic code smell – potential redundancy, dead code, or, at the very least, a missed opportunity for abstraction. My initial thought is, why is this? Is `nullfs` supposed to behave like an empty directory, or is this a copy-paste error? Let's dive into `fs/libfs.c` and take a look at the implementation of `empty_dir_readdir`. I need to understand its behavior and any preconditions it might assume. Is it just returning an empty entry, or is there more to it? I'll be looking for things like error handling, any implicit assumptions about the file system structure, and the overall context in which it's used. This similarity has me curious, so I need to dig in and determine if this duplication is intentional or a point of technical debt. |
| 64/3 | 2026/10/03 03:37 | tool | read-file |
0mArgs:{
"File": "fs/libfs.c",
"FirstLine": 1750,
"LineCount": 20
}Results: {
"Contents": "1750:\t\treturn generic_file_llseek_size(file, offset, whence, 2, 2);\n1751:\t}\n1752:\t\n1753:\tstatic int empty_dir_readdir(struct file *file, struct dir_context *ctx)\n1754:\t{\n1755:\t\tdir_emit_dots(file, ctx);\n1756:\t\treturn 0;\n1757:\t}\n1758:\t\n1759:\tstatic const struct file_operations empty_dir_operations = {\n1760:\t\t.llseek\t\t= empty_dir_llseek,\n1761:\t\t.read\t\t= generic_read_dir,\n1762:\t\t.iterate_shared\t= empty_dir_readdir,\n1763:\t\t.fsync\t\t= noop_fsync,\n1764:\t};\n1765:\t\n1766:\t\n1767:\tvoid make_empty_dir_inode(struct inode *inode)\n1768:\t{\n1769:\t\tset_nlink(inode, 2);\n"
} |
| 65/3 | 2026/10/03 03:37 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29721 output: 35 thoughts: 1038 Thoughts: **Analyzing the Impact of the Nullfs Immutable Directory Optimization** Alright, let's break down this code change related to the `nullfs` and its immutable directory behavior. My initial thought is to ensure the inode initialization and concurrent access are handled correctly, especially with the `FOP_IMMUTABLE` flag. Previously, `make_empty_dir_inode(inode)` was called on the `nullfs` inode, which sets `inode->i_fop` to `&empty_dir_operations`. The subsequent modification in `nullfs.c` then overrides this by assigning `inode->i_fop` to `&nullfs_dir_operations`, introducing specific operations like `lock`, `flock`, and `setlease` that return error codes. Critically, it also sets `fop_flags = FOP_IMMUTABLE`. The core concern here is the potential for bypassing initialization or leading to uninitialized memory access because of the `FOP_IMMUTABLE`. The `iterate_dir` function within `readdir.c` is the key. Its logic essentially checks if a file's operations include `FOP_IMMUTABLE`. If it does, then the code skips taking the `inode->i_rwsem` read lock, effectively optimizing for directories that never change. This is perfectly valid, since immutable directories would never require the concurrency protection. I need to confirm if the other changes create any issues. Let's look at each of those: 1. `fcntl_set_rw_hint`: This simply returns `-EPERM` if the inode is immutable. No risks of uninitialized memory. 2. `fs/fhandle.c`: `subtree_unobstructed`: This wraps checks under a reader lock. No potential issues. 3. `fs/namespace.c`: These changes encompass a variety of updates within the namespace code. Most of these additions seem like normal lock or refactoring operations, checks, or guard statements. The `init_mount_tree` addition to set up `knullfs` also seems unproblematic. 4. `fs/namei.c`: `unlink_may_reveal`: I'll examine line 2142 to confirm, but the code appears to add checks to prevent revealing an underlying dentry if unlinked, returning `-ESTALE` to signal that the handle is no longer valid. `dput(no_free_ptr(path->dentry));` looks correct. Based on this analysis, the optimization appears safe. Skipping the read lock is reasonable for immutable directories, and the other changes don't seem to introduce initialization or memory access problems. |
| 66/3 | 2026/10/03 03:37 | tool | read-file |
0mArgs:{
"File": "fs/namei.c",
"FirstLine": 2130,
"LineCount": 35
}Results: {
"Contents": "2130:\t\n2131:\t\terr = handle_mounts(nd, dentry, \u0026path);\n2132:\t\tif (unlikely(err \u003c 0))\n2133:\t\t\treturn ERR_PTR(err);\n2134:\t\tinode = path.dentry-\u003ed_inode;\n2135:\t\tif (likely(!d_is_symlink(path.dentry)) ||\n2136:\t\t ((flags \u0026 WALK_TRAILING) \u0026\u0026 !(nd-\u003eflags \u0026 LOOKUP_FOLLOW)) ||\n2137:\t\t (flags \u0026 WALK_NOFOLLOW)) {\n2138:\t\t\t/* not a symlink or should not follow */\n2139:\t\t\tif (nd-\u003eflags \u0026 LOOKUP_RCU) {\n2140:\t\t\t\tif (read_seqcount_retry(\u0026path.dentry-\u003ed_seq, nd-\u003enext_seq))\n2141:\t\t\t\t\treturn ERR_PTR(-ECHILD);\n2142:\t\t\t\tif (unlikely(!inode))\n2143:\t\t\t\t\treturn ERR_PTR(-ENOENT);\n2144:\t\t\t} else {\n2145:\t\t\t\tif (unlikely(unlink_may_reveal(nd, flags, \u0026path, dentry)))\n2146:\t\t\t\t\treturn ERR_PTR(-ESTALE);\n2147:\t\t\t\tdput(nd-\u003epath.dentry);\n2148:\t\t\t\tif (nd-\u003epath.mnt != path.mnt)\n2149:\t\t\t\t\tmntput(nd-\u003epath.mnt);\n2150:\t\t\t}\n2151:\t\t\tnd-\u003epath = path;\n2152:\t\t\tnd-\u003einode = inode;\n2153:\t\t\tnd-\u003eseq = nd-\u003enext_seq;\n2154:\t\t\treturn NULL;\n2155:\t\t}\n2156:\t\treturn pick_link(nd, \u0026path, inode, flags);\n2157:\t}\n2158:\t\n2159:\tstatic __always_inline const char *step_into(struct nameidata *nd, int flags,\n2160:\t struct dentry *dentry)\n2161:\t{\n2162:\t\t/*\n2163:\t\t * In the common case we are in rcu-walk and traversing over a non-mounted on\n2164:\t\t * directory (as opposed to e.g., a symlink).\n"
} |
| 67/3 | 2026/10/03 03:37 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31947 output: 227 thoughts: 1523 Thoughts: **KMSAN Assessment: No Need for Dedicated Testing** Alright, let's break this down. In the `step_into_slowpath` function, the `unlink_may_reveal` function potentially drops `path.dentry` and returns `-ESTALE`. The `path.mnt` is safe because it was checked earlier, and no extra reference was taken. I revisited `unlink_may_reveal` and confirmed it's working as expected: If it returns true, we `dput` the `path->dentry` and get `-ESTALE`. I also reviewed the `fs/notify/mark.c` change, which introduces a check that returns `-EINVAL`. The selftests all seem standard. Now, the main focus: KMSAN. We're talking about uninitialized memory reads and potential kernel-to-user leaks. The general rule is: if KASAN, LOCKDEP, or standard bug detectors can catch an issue, we *don't* need KMSAN. We only need KMSAN if there are *unique* risks of uninitialized memory. So, let's analyze this patch. First, did we introduce any new kernel structures copied to userspace? No. The patch modifies VFS mount handling, filesystem attributes, directory operations, locking, fsnotify, and includes corresponding selftests. No new data is going to user-space. Second, are there any conditionals based on uninitialized variables? Nope. All relevant variables (`mnt`, `inode`, `dentry`, `path`, etc.) are either kernel objects or properly initialized local variables. Third, are there any buffer bounds checks or length modifications that could expose uninitialized memory? No. `nullfs_dir_llseek` uses `generic_file_llseek_size` with offsets that seem safe. Fourth, are there any info-leaks to userspace? No new data is copied. We're just dealing with "." and ".." in directory emission. The kinds of issues we could see here are concurrency/race conditions, reference counting issues, denial-of-service/deadlocks, logic bugs, permission checks, or mount escapes. But, none of these point to uninitialized memory. These are all KCSAN, LOCKDEP, and KASAN issues, respectively, and will be detected by the usual suspects. KASAN/LOCKDEP and syzkaller will provide the appropriate coverage here. Therefore, `NeedsKMSAN` is clearly false. Here's a summary for the sake of completeness. This patch touches VFS mount handling, mount propagation locking, nullfs directory operations, immutable inode handling, `unlink_may_reveal`, fsnotify, and corresponding selftests. There are no new allocations or data transfers to user-space that need additional initialization. All of the conditionals use initialized kernel objects. Any regressions in this series relate to locking or reference counting, which KASAN/LOCKDEP/syzkaller will cover. There is nothing in this series that would suggest a memory hazard unique to KMSAN. So, `NeedsKMSAN = false`. Done. Let's call `set-results`. |
| 68/3 | 2026/10/03 03:37 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series modifies VFS mount handling, mount propagation locking (MNT_LOCKED), directory iteration locking for immutable filesystems (FOP_IMMUTABLE in nullfs and iterate_dir), fcntl rw-hint checks for immutable inodes, path lookup unlinked-dentry checks (unlink_may_reveal), and fsnotify mark restrictions (FS_DISALLOW_NOTIFY), along with corresponding selftests.\n\nNone of the changes introduce or modify kernel-to-user copy paths with uninitialized padding/fields, nor do they introduce allocations of uninitialized memory, branch on uninitialized variables, or alter buffer bounds. Potential risks introduced by these changes primarily concern reference counting (dentry/mount ref handling), concurrency, locking (inode rwsem, mount_lock), and access control/logic bugs. These categories are caught by standard KASAN, LOCKDEP, and functional fuzzing/testing. Spawning a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series modifies VFS mount handling, mount propagation locking (MNT_LOCKED), directory iteration locking for immutable filesystems (FOP_IMMUTABLE in nullfs and iterate_dir), fcntl rw-hint checks for immutable inodes, path lookup unlinked-dentry checks (unlink_may_reveal), and fsnotify mark restrictions (FS_DISALLOW_NOTIFY), along with corresponding selftests.\n\nNone of the changes introduce or modify kernel-to-user copy paths with uninitialized padding/fields, nor do they introduce allocations of uninitialized memory, branch on uninitialized variables, or alter buffer bounds. Potential risks introduced by these changes primarily concern reference counting (dentry/mount ref handling), concurrency, locking (inode rwsem, mount_lock), and access control/logic bugs. These categories are caught by standard KASAN, LOCKDEP, and functional fuzzing/testing. Spawning a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|