Skip to content

Commit 8675c69

Browse files
author
Trond Myklebust
committed
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: f2aedb7 ("NFS: Add fs_context support.") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent d4a26d3 commit 8675c69

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

fs/nfs/namespace.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct vfsmount *nfs_d_automount(struct path *path)
149149
struct vfsmount *mnt = ERR_PTR(-ENOMEM);
150150
struct nfs_server *server = NFS_SB(path->dentry->d_sb);
151151
struct nfs_client *client = server->nfs_client;
152+
unsigned long s_flags = path->dentry->d_sb->s_flags;
152153
int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout);
153154
int ret;
154155

@@ -174,6 +175,11 @@ struct vfsmount *nfs_d_automount(struct path *path)
174175
fc->net_ns = get_net(client->cl_net);
175176
}
176177

178+
/* Inherit the flags covered by NFS_SB_MASK */
179+
fc->sb_flags_mask |= NFS_SB_MASK;
180+
fc->sb_flags &= ~NFS_SB_MASK;
181+
fc->sb_flags |= s_flags & NFS_SB_MASK;
182+
177183
/* for submounts we want the same server; referrals will reassign */
178184
memcpy(&ctx->nfs_server._address, &client->cl_addr, client->cl_addrlen);
179185
ctx->nfs_server.addrlen = client->cl_addrlen;

fs/nfs/super.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,10 +1315,6 @@ int nfs_get_tree_common(struct fs_context *fc)
13151315
if (server->flags & NFS_MOUNT_NOAC)
13161316
fc->sb_flags |= SB_SYNCHRONOUS;
13171317

1318-
if (ctx->clone_data.sb)
1319-
if (ctx->clone_data.sb->s_flags & SB_SYNCHRONOUS)
1320-
fc->sb_flags |= SB_SYNCHRONOUS;
1321-
13221318
/* Get a superblock - note that we may end up sharing one that already exists */
13231319
fc->s_fs_info = server;
13241320
s = sget_fc(fc, compare_super, nfs_set_super);

0 commit comments

Comments
 (0)