mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chung-Chiang Cheng <cccheng@synology.com>
To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: shepjeng@gmail.com, kernel@cccheng.net,
	Chung-Chiang Cheng <cccheng@synology.com>,
	Johnny Chang <johnnyc@synology.com>
Subject: [PATCH] btrfs: refuse to remount read-write with unsupported compat-ro features
Date: Fri,  2 Dec 2022 00:07:24 +0800	[thread overview]
Message-ID: <20221201160724.2593341-1-cccheng@synology.com> (raw)

btrfs with unsupported compat-ro features can only be mounted as
read-only, but we can make it read-write indirectly through remount.
Just add the missing check to refuse it.

  mount -o ro /dev/vdb /mnt
  mount -o remount,rw /mnt

Reported-by: Johnny Chang <johnnyc@synology.com>
Signed-off-by: Chung-Chiang Cheng <cccheng@synology.com>
---
 fs/btrfs/super.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 5942b9384088..45836a426499 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1991,6 +1991,8 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
 	unsigned old_flags = sb->s_flags;
 	unsigned long old_opts = fs_info->mount_opt;
 	unsigned long old_compress_type = fs_info->compress_type;
+	u64 compat_ro = btrfs_super_compat_ro_flags(fs_info->super_copy);
+	u64 compat_ro_unsupp = compat_ro & ~BTRFS_FEATURE_COMPAT_RO_SUPP;
 	u64 old_max_inline = fs_info->max_inline;
 	u32 old_thread_pool_size = fs_info->thread_pool_size;
 	u32 old_metadata_ratio = fs_info->metadata_ratio;
@@ -2107,6 +2109,13 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
 		if (ret)
 			goto restore;
 	} else {
+		if (compat_ro_unsupp) {
+			btrfs_err(fs_info,
+				"cannot remount read-write because of unknown compat_ro features (0x%llx)",
+				compat_ro);
+			ret = -EINVAL;
+			goto restore;
+		}
 		if (BTRFS_FS_ERROR(fs_info)) {
 			btrfs_err(fs_info,
 				"Remounting read-write after error is not allowed");
-- 
2.34.1


             reply	other threads:[~2022-12-01 16:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 16:07 Chung-Chiang Cheng [this message]
2022-12-05 10:44 ` Filipe Manana
2022-12-06  2:42   ` Chung-Chiang Cheng
2022-12-06 11:14     ` Filipe Manana
2022-12-20 19:53       ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221201160724.2593341-1-cccheng@synology.com \
    --to=cccheng@synology.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=johnnyc@synology.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel@cccheng.net \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shepjeng@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®