* [f2fs-dev] [PATCH] f2fs: prevent mounting devices with unsupported features
@ 2021-04-05 8:40 Park Ju Hyung
2021-04-06 3:39 ` Chao Yu
0 siblings, 1 reply; 3+ messages in thread
From: Park Ju Hyung @ 2021-04-05 8:40 UTC (permalink / raw)
To: linux-f2fs-devel
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.
Cc: stable@vger.kernel.org
Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
---
fs/f2fs/f2fs.h | 11 +++++++++++
fs/f2fs/super.c | 10 ++++++++++
2 files changed, 21 insertions(+)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e2d302ae3a46..12d274492d6f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -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)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 82592b19b4e0..91d77985cf9b 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -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,
--
2.31.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [f2fs-dev] [PATCH] f2fs: prevent mounting devices with unsupported features
@ 2021-04-05 8:43 Park Ju Hyung
0 siblings, 0 replies; 3+ messages in thread
From: Park Ju Hyung @ 2021-04-05 8:43 UTC (permalink / raw)
To: linux-f2fs-devel
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.
Cc: stable@vger.kernel.org
Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
---
fs/f2fs/f2fs.h | 11 +++++++++++
fs/f2fs/super.c | 10 ++++++++++
2 files changed, 21 insertions(+)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e2d302ae3a46..12d274492d6f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -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)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 82592b19b4e0..4a2fe29b0740 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -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");
+ 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,
--
2.31.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: prevent mounting devices with unsupported features
2021-04-05 8:40 Park Ju Hyung
@ 2021-04-06 3:39 ` Chao Yu
0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2021-04-06 3:39 UTC (permalink / raw)
To: Park Ju Hyung, linux-f2fs-devel
Hi Ju Hyung,
On 2021/4/5 16:40, Park Ju Hyung wrote:
> 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,
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
> ---
> fs/f2fs/f2fs.h | 11 +++++++++++
> fs/f2fs/super.c | 10 ++++++++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index e2d302ae3a46..12d274492d6f 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -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)
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 82592b19b4e0..91d77985cf9b 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -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,
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-06 3:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-05 8:43 [f2fs-dev] [PATCH] f2fs: prevent mounting devices with unsupported features Park Ju Hyung
-- strict thread matches above, loose matches on Subject: below --
2021-04-05 8:40 Park Ju Hyung
2021-04-06 3:39 ` Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).