Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NFS: Automounted filesystems should inherit ro,noexec,nodev,sync flags

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>

+6 -4
+6
fs/nfs/namespace.c
··· 149 149 struct vfsmount *mnt = ERR_PTR(-ENOMEM); 150 150 struct nfs_server *server = NFS_SB(path->dentry->d_sb); 151 151 struct nfs_client *client = server->nfs_client; 152 + unsigned long s_flags = path->dentry->d_sb->s_flags; 152 153 int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout); 153 154 int ret; 154 155 ··· 174 173 put_net(fc->net_ns); 175 174 fc->net_ns = get_net(client->cl_net); 176 175 } 176 + 177 + /* Inherit the flags covered by NFS_SB_MASK */ 178 + fc->sb_flags_mask |= NFS_SB_MASK; 179 + fc->sb_flags &= ~NFS_SB_MASK; 180 + fc->sb_flags |= s_flags & NFS_SB_MASK; 177 181 178 182 /* for submounts we want the same server; referrals will reassign */ 179 183 memcpy(&ctx->nfs_server._address, &client->cl_addr, client->cl_addrlen);
-4
fs/nfs/super.c
··· 1315 1315 if (server->flags & NFS_MOUNT_NOAC) 1316 1316 fc->sb_flags |= SB_SYNCHRONOUS; 1317 1317 1318 - if (ctx->clone_data.sb) 1319 - if (ctx->clone_data.sb->s_flags & SB_SYNCHRONOUS) 1320 - fc->sb_flags |= SB_SYNCHRONOUS; 1321 - 1322 1318 /* Get a superblock - note that we may end up sharing one that already exists */ 1323 1319 fc->s_fs_info = server; 1324 1320 s = sget_fc(fc, compare_super, nfs_set_super);