Skip to contentSkip to conversation

f2fs: prevent mounting devices with unsupported features

PATCH In review Park Ju Hyung 2 participants 2 messages Apr 5, 2021 – Apr 6, 2021 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: prevent mounting devices with unsupported features

Mounting f2fs devices with future options leads to unwanted behaviors incurring errors and data destruction.

Implement a long overdue safeguard to prevent mounting devices with unsupported features.

This can be further extended to allow read-only mounts on certain incompatible features, but that doesn't seem necessary for now with how f2fs features has been added.

---
 fs/f2fs/f2fs.h  | 11 +++++++++++
 fs/f2fs/super.c | 10 ++++++++++
 2 files changed, 21 insertions(+)
fs/f2fs/f2fs.h +11 -0
index e2d302ae3a46..12d274492d6f 100644
@@ -153,6 +153,9 @@ struct f2fs_mount_info {
 	unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];	/* extensions */
 };
 
+/*
+ * All features listed here should be appended to F2FS_SUPPORTED_FEATURES
+ */
 #define F2FS_FEATURE_ENCRYPT		0x0001
 #define F2FS_FEATURE_BLKZONED		0x0002
 #define F2FS_FEATURE_ATOMIC_WRITE	0x0004
@@ -168,6 +171,14 @@ struct f2fs_mount_info {
 #define F2FS_FEATURE_CASEFOLD		0x1000
 #define F2FS_FEATURE_COMPRESSION	0x2000
 
+/* Currently supported features by this version of f2fs */
+#define F2FS_SUPPORTED_FEATURES \
+	(F2FS_FEATURE_ENCRYPT | F2FS_FEATURE_BLKZONED | F2FS_FEATURE_ATOMIC_WRITE | \
+	 F2FS_FEATURE_EXTRA_ATTR | F2FS_FEATURE_PRJQUOTA | F2FS_FEATURE_INODE_CHKSUM | \
+	 F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | F2FS_FEATURE_QUOTA_INO | F2FS_FEATURE_INODE_CRTIME | \
+	 F2FS_FEATURE_LOST_FOUND | F2FS_FEATURE_VERITY | F2FS_FEATURE_SB_CHKSUM | \
+	 F2FS_FEATURE_CASEFOLD | F2FS_FEATURE_COMPRESSION)
+
 #define __F2FS_HAS_FEATURE(raw_super, mask)				\
 	((raw_super->feature & cpu_to_le32(mask)) != 0)
 #define F2FS_HAS_FEATURE(sbi, mask)	__F2FS_HAS_FEATURE(sbi->raw_super, mask)
fs/f2fs/super.c +10 -0
index 82592b19b4e0..91d77985cf9b 100644
@@ -3610,6 +3610,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 	int recovery, i, valid_super_block;
 	struct curseg_info *seg_i;
 	int retry_cnt = 1;
+	__le32 unsupported;
 
 try_onemore:
 	err = -EINVAL;
@@ -3647,6 +3648,15 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 	sb->s_fs_info = sbi;
 	sbi->raw_super = raw_super;
 
+	/* check supported features */
+	unsupported = raw_super->feature & ~F2FS_SUPPORTED_FEATURES;
+	if (unsupported) {
+		f2fs_err(sbi, "unsupported features: 0x%x\n", unsupported);
+		f2fs_err(sbi, "please update your kernel or adjust the mkfs.f2fs option\n", unsupported);
+		err = -EOPNOTSUPP;
+		goto free_sb_buf;
+	}
+
 	/* precompute checksum seed for metadata */
 	if (f2fs_sb_has_inode_chksum(sbi))
 		sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid,
Signature · 8 lines
2.31.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

Hi Ju Hyung,

Quoted 9 lines · Park Ju Hyung

Mounting f2fs devices with future options leads to unwanted behaviors incurring errors and data destruction.

Implement a long overdue safeguard to prevent mounting devices with unsupported features.

This can be further extended to allow read-only mounts on certain incompatible features, but that doesn't seem necessary for now with how f2fs features has been added.

Thanks for the patch!

I have a RFC patch for this issue, but the patch doesn't being merged, IIRC, Jaegeuk and I have divergence on implementation details, maybe we could continue the discussion and work right now. :)

https://lkml.org/lkml/2019/7/29/623

Thanks,

Quoted 56 lines
---
  fs/f2fs/f2fs.h  | 11 +++++++++++
  fs/f2fs/super.c | 10 ++++++++++
  2 files changed, 21 insertions(+)
fs/f2fs/f2fs.h +11 -0
index e2d302ae3a46..12d274492d6f 100644
@@ -153,6 +153,9 @@ struct f2fs_mount_info {
  	unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];	/* extensions */
  };
 
+/*
+ * All features listed here should be appended to F2FS_SUPPORTED_FEATURES
+ */
  #define F2FS_FEATURE_ENCRYPT		0x0001
  #define F2FS_FEATURE_BLKZONED		0x0002
  #define F2FS_FEATURE_ATOMIC_WRITE	0x0004
@@ -168,6 +171,14 @@ struct f2fs_mount_info {
  #define F2FS_FEATURE_CASEFOLD		0x1000
  #define F2FS_FEATURE_COMPRESSION	0x2000
 
+/* Currently supported features by this version of f2fs */
+#define F2FS_SUPPORTED_FEATURES \
+	(F2FS_FEATURE_ENCRYPT | F2FS_FEATURE_BLKZONED | F2FS_FEATURE_ATOMIC_WRITE | \
+	 F2FS_FEATURE_EXTRA_ATTR | F2FS_FEATURE_PRJQUOTA | F2FS_FEATURE_INODE_CHKSUM | \
+	 F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | F2FS_FEATURE_QUOTA_INO | F2FS_FEATURE_INODE_CRTIME | \
+	 F2FS_FEATURE_LOST_FOUND | F2FS_FEATURE_VERITY | F2FS_FEATURE_SB_CHKSUM | \
+	 F2FS_FEATURE_CASEFOLD | F2FS_FEATURE_COMPRESSION)
+
  #define __F2FS_HAS_FEATURE(raw_super, mask)				\
  	((raw_super->feature & cpu_to_le32(mask)) != 0)
  #define F2FS_HAS_FEATURE(sbi, mask)	__F2FS_HAS_FEATURE(sbi->raw_super, mask)
fs/f2fs/super.c +3 -0
index 82592b19b4e0..91d77985cf9b 100644
@@ -3610,6 +3610,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
  	int recovery, i, valid_super_block;
  	struct curseg_info *seg_i;
  	int retry_cnt = 1;
+	__le32 unsupported;
 
  try_onemore:
  	err = -EINVAL;
@@ -3647,6 +3648,15 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
  	sb->s_fs_info = sbi;
  	sbi->raw_super = raw_super;
 
+	/* check supported features */
+	unsupported = raw_super->feature & ~F2FS_SUPPORTED_FEATURES;

fs/f2fs/super.c static int f2fs_fill_super(struct super_block *sb, void *data, int silent) · line 3662

Quoted 10 lines
fs/f2fs/super.c +7 -0
+	if (unsupported) {
+		f2fs_err(sbi, "unsupported features: 0x%x\n", unsupported);
+		f2fs_err(sbi, "please update your kernel or adjust the mkfs.f2fs option\n", unsupported);
+		err = -EOPNOTSUPP;
+		goto free_sb_buf;
+	}
+
  	/* precompute checksum seed for metadata */
  	if (f2fs_sb_has_inode_chksum(sbi))
  		sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel