]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nfs: clear SB_RDONLY before getting superblock
authorLi Lingfeng <lilingfeng3@huawei.com>
Tue, 4 Mar 2025 13:05:32 +0000 (21:05 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:05:16 +0000 (11:05 +0100)
[ Upstream commit 8cd9b785943c57a136536250da80ba1eb6f8eb18 ]

As described in the link, commit 52cb7f8f1778 ("nfs: ignore SB_RDONLY when
mounting nfs") removed the check for the ro flag when determining whether
to share the superblock, which caused issues when mounting different
subdirectories under the same export directory via NFSv3. However, this
change did not affect NFSv4.

For NFSv3:
1) A single superblock is created for the initial mount.
2) When mounted read-only, this superblock carries the SB_RDONLY flag.
3) Before commit 52cb7f8f1778 ("nfs: ignore SB_RDONLY when mounting nfs"):
Subsequent rw mounts would not share the existing ro superblock due to
flag mismatch, creating a new superblock without SB_RDONLY.
After the commit:
  The SB_RDONLY flag is ignored during superblock comparison, and this leads
  to sharing the existing superblock even for rw mounts.
  Ultimately results in write operations being rejected at the VFS layer.

For NFSv4:
1) Multiple superblocks are created and the last one will be kept.
2) The actually used superblock for ro mounts doesn't carry SB_RDONLY flag.
Therefore, commit 52cb7f8f1778 doesn't affect NFSv4 mounts.

Clear SB_RDONLY before getting superblock when NFS_MOUNT_UNSHARED is not
set to fix it.

Fixes: 52cb7f8f1778 ("nfs: ignore SB_RDONLY when mounting nfs")
Closes: https://lore.kernel.org/all/12d7ea53-1202-4e21-a7ef-431c94758ce5@app.fastmail.com/T/
Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/super.c

index f91cb1267b44ec0a9e44e53bc90c2270e89a2846..aa11a6dcf6ce717c6c7ea5ddfabe5e05087bd6b8 100644 (file)
@@ -1269,8 +1269,17 @@ int nfs_get_tree_common(struct fs_context *fc)
        if (IS_ERR(server))
                return PTR_ERR(server);
 
+       /*
+        * When NFS_MOUNT_UNSHARED is not set, NFS forces the sharing of a
+        * superblock among each filesystem that mounts sub-directories
+        * belonging to a single exported root path.
+        * To prevent interference between different filesystems, the
+        * SB_RDONLY flag should be removed from the superblock.
+        */
        if (server->flags & NFS_MOUNT_UNSHARED)
                compare_super = NULL;
+       else
+               fc->sb_flags &= ~SB_RDONLY;
 
        /* -o noac implies -o sync */
        if (server->flags & NFS_MOUNT_NOAC)