From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF57F2628C; Mon, 23 Jun 2025 21:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713810; cv=none; b=b4Tda1PrLk/kehG1XaBCTv/8Fzys8nJM+Ub/vkQe4VBTQG7EO5kbgE2PGeuNV6cLva2KZu09QzWhtargIQQdkH+Gs5/6Lllkdr1qrtZulZ8cCBUPASs4NJ1hZWQR6zFpMBGVWX9PkVl5Go+itcC/yGBcBkmVRYzQ5i0Lts37Vas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713810; c=relaxed/simple; bh=HOrS7F7Azy1zM6nA6iFI0Xl0fMxbPE9P9ulc3Rm3sNE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LQPbMLd5u8rE20bi+X+XE6dbjZT/TSaMBsQ0eUi7HMkuLatxsISNDlggxkGm8brVzp+CdO6ba5+E3EEA5UxGanwAco8Di9+Sb9KtT1tVqdHft3vS6gC9/rGq5laW4RJJVHFMn7XEp9ZQ/BEzPtrmCf//ve9WTC6KxqgS4ehGHtI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BnAzhdrR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="BnAzhdrR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56755C4CEED; Mon, 23 Jun 2025 21:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750713810; bh=HOrS7F7Azy1zM6nA6iFI0Xl0fMxbPE9P9ulc3Rm3sNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BnAzhdrR/ti3cYFnw4Lpgqha3NvDb9n4Igd3JXuGV7wWS1aZxz9Bm2vDVgnxzYtmn XxQq61qgze8nTGmDk3pu4RMSkoRtd6WHNRo5lwDldKRRyKr32CQZo2WDVhTbPfkEDZ k16czTH7z69PBiLhRGOXU9jVfi013MItEG6wXF7M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Li Lingfeng , Anna Schumaker , Sasha Levin Subject: [PATCH 6.1 148/508] nfs: clear SB_RDONLY before getting superblock Date: Mon, 23 Jun 2025 15:03:13 +0200 Message-ID: <20250623130648.924946859@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130645.255320792@linuxfoundation.org> References: <20250623130645.255320792@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Li Lingfeng [ 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 Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/super.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 3dffeb1d17b9c..a4679cd75f70a 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c @@ -1273,8 +1273,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) -- 2.39.5