]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
NFS: Automounted filesystems should inherit ro,noexec,nodev,sync flags
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Fri, 28 Nov 2025 19:22:44 +0000 (14:22 -0500)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Sat, 29 Nov 2025 22:22:48 +0000 (17:22 -0500)
When a filesystem is being automounted, it needs to preserve the
user-set superblock mount options, such as the "ro" flag.

Reported-by: Li Lingfeng <lilingfeng3@huawei.com>
Link: https://lore.kernel.org/all/20240604112636.236517-3-lilingfeng@huaweicloud.com/
Fixes: f2aedb713c28 ("NFS: Add fs_context support.")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/namespace.c
fs/nfs/super.c

index 5a4d193da1a98b8f0261b6ecf367156f2063aa6b..dca055676c4f317de067af6c721314cbf935c52d 100644 (file)
@@ -149,6 +149,7 @@ struct vfsmount *nfs_d_automount(struct path *path)
        struct vfsmount *mnt = ERR_PTR(-ENOMEM);
        struct nfs_server *server = NFS_SB(path->dentry->d_sb);
        struct nfs_client *client = server->nfs_client;
+       unsigned long s_flags = path->dentry->d_sb->s_flags;
        int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout);
        int ret;
 
@@ -174,6 +175,11 @@ struct vfsmount *nfs_d_automount(struct path *path)
                fc->net_ns = get_net(client->cl_net);
        }
 
+       /* Inherit the flags covered by NFS_SB_MASK */
+       fc->sb_flags_mask |= NFS_SB_MASK;
+       fc->sb_flags &= ~NFS_SB_MASK;
+       fc->sb_flags |= s_flags & NFS_SB_MASK;
+
        /* for submounts we want the same server; referrals will reassign */
        memcpy(&ctx->nfs_server._address, &client->cl_addr, client->cl_addrlen);
        ctx->nfs_server.addrlen = client->cl_addrlen;
index 9b9464e70a7f0062381ecaa98e280b555efe8649..66413133b43e3f527c2399b7e6223d8785051638 100644 (file)
@@ -1315,10 +1315,6 @@ int nfs_get_tree_common(struct fs_context *fc)
        if (server->flags & NFS_MOUNT_NOAC)
                fc->sb_flags |= SB_SYNCHRONOUS;
 
-       if (ctx->clone_data.sb)
-               if (ctx->clone_data.sb->s_flags & SB_SYNCHRONOUS)
-                       fc->sb_flags |= SB_SYNCHRONOUS;
-
        /* Get a superblock - note that we may end up sharing one that already exists */
        fc->s_fs_info = server;
        s = sget_fc(fc, compare_super, nfs_set_super);