Skip to contentSkip to conversation

ext2: don't mount filesystems with compat features we know only ext4 supports

PATCH In review Darrick J. Wong 3 participants 6 messages Sep 28, 2015 – Oct 8, 2015 ext2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext2: don't mount filesystems with compat features we know only ext4 supports

The ext2 mount code never checks the compat features against the ones it knows about. This is correct behavior since compat features are supposed to be rw-compatible with old drivers; however, for certain configurations (journalled rootfs) we probably want the ext4 driver to load, not ext2.

---
 fs/ext2/ext2.h  |    6 +++++-
 fs/ext2/super.c |   13 ++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)
fs/ext2/ext2.h +5 -1
index 8d15feb..ce508b1 100644
@@ -547,7 +547,11 @@ struct ext2_super_block {
 #define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
 #define EXT2_FEATURE_INCOMPAT_ANY		0xffffffff
 
-#define EXT2_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
+#define EXT2_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC| \
+					 EXT2_FEATURE_COMPAT_IMAGIC_INODES| \
+					 EXT2_FEATURE_COMPAT_EXT_ATTR| \
+					 EXT2_FEATURE_COMPAT_RESIZE_INO| \
+					 EXT2_FEATURE_COMPAT_DIR_INDEX)
 #define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
 					 EXT2_FEATURE_INCOMPAT_META_BG)
 #define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
fs/ext2/super.c +10 -0
index 900e19c..4efb018 100644
@@ -896,6 +896,16 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 	 * previously didn't change the revision level when setting the flags,
 	 * so there is a chance incompat flags are set on a rev 0 filesystem.
 	 */
+#ifdef CONFIG_EXT4_FS
+	/* Journalled FS should mount with ext4 if it's available */
+	features = EXT2_HAS_COMPAT_FEATURE(sb, ~EXT2_FEATURE_COMPAT_SUPP);
+	if (features) {
+		ext2_msg(sb, KERN_ERR,	"error: won't mount because of "
+		       "unsupported optional features (%x); try ext4",
+			le32_to_cpu(features));
+		goto failed_mount;
+	}
+#endif
 	features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP);
 	if (features) {
 		ext2_msg(sb, KERN_ERR,	"error: couldn't mount because of "
#1 lore raw
Quoted 8 lines · Darrick J. Wong

The ext2 mount code never checks the compat features against the ones it knows about. This is correct behavior since compat features are supposed to be rw-compatible with old drivers; however, for certain configurations (journalled rootfs) we probably want the ext4 driver to load, not ext2.

Isn't this a bit too harsh? I agree we should at least warn (and that's probably regardless of EXT4 config option) but just refusing mount looks too much to me...

Honza

Quoted 44 lines
---
 fs/ext2/ext2.h  |    6 +++++-
 fs/ext2/super.c |   13 ++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)
fs/ext2/ext2.h +5 -1
index 8d15feb..ce508b1 100644
@@ -547,7 +547,11 @@ struct ext2_super_block {
 #define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
 #define EXT2_FEATURE_INCOMPAT_ANY		0xffffffff
 
-#define EXT2_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
+#define EXT2_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC| \
+					 EXT2_FEATURE_COMPAT_IMAGIC_INODES| \
+					 EXT2_FEATURE_COMPAT_EXT_ATTR| \
+					 EXT2_FEATURE_COMPAT_RESIZE_INO| \
+					 EXT2_FEATURE_COMPAT_DIR_INDEX)
 #define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
 					 EXT2_FEATURE_INCOMPAT_META_BG)
 #define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
fs/ext2/super.c +10 -0
index 900e19c..4efb018 100644
@@ -896,6 +896,16 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 	 * previously didn't change the revision level when setting the flags,
 	 * so there is a chance incompat flags are set on a rev 0 filesystem.
 	 */
+#ifdef CONFIG_EXT4_FS
+	/* Journalled FS should mount with ext4 if it's available */
+	features = EXT2_HAS_COMPAT_FEATURE(sb, ~EXT2_FEATURE_COMPAT_SUPP);
+	if (features) {
+		ext2_msg(sb, KERN_ERR,	"error: won't mount because of "
+		       "unsupported optional features (%x); try ext4",
+			le32_to_cpu(features));
+		goto failed_mount;
+	}
+#endif
 	features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP);
 	if (features) {
 		ext2_msg(sb, KERN_ERR,	"error: couldn't mount because of "
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 7 lines · Jan Kara
Quoted 6 lines · Darrick J. Wong

The ext2 mount code never checks the compat features against the ones it knows about. This is correct behavior since compat features are supposed to be rw-compatible with old drivers; however, for certain configurations (journalled rootfs) we probably want the ext4 driver to load, not ext2.

Quoted 6 lines
Quoted 2 lines

Isn't this a bit too harsh? I agree we should at least warn (and that's probably regardless of EXT4 config option) but just refusing mount looks too much to me...

I admit that refusing the mount might be a bit much; the goal here was merely to make it so that if the FS has a journal and ext4 was turned on, hopefully ext2 rejects the mount and ext4 will probe it next.

<shrug>

--D

Quoted 54 lines

Honza

Quoted 44 lines
---
 fs/ext2/ext2.h  |    6 +++++-
 fs/ext2/super.c |   13 ++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)
fs/ext2/ext2.h +5 -1
index 8d15feb..ce508b1 100644
@@ -547,7 +547,11 @@ struct ext2_super_block {
 #define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
 #define EXT2_FEATURE_INCOMPAT_ANY		0xffffffff
 
-#define EXT2_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
+#define EXT2_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC| \
+					 EXT2_FEATURE_COMPAT_IMAGIC_INODES| \
+					 EXT2_FEATURE_COMPAT_EXT_ATTR| \
+					 EXT2_FEATURE_COMPAT_RESIZE_INO| \
+					 EXT2_FEATURE_COMPAT_DIR_INDEX)
 #define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
 					 EXT2_FEATURE_INCOMPAT_META_BG)
 #define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
fs/ext2/super.c +10 -0
index 900e19c..4efb018 100644
@@ -896,6 +896,16 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 	 * previously didn't change the revision level when setting the flags,
 	 * so there is a chance incompat flags are set on a rev 0 filesystem.
 	 */
+#ifdef CONFIG_EXT4_FS
+	/* Journalled FS should mount with ext4 if it's available */
+	features = EXT2_HAS_COMPAT_FEATURE(sb, ~EXT2_FEATURE_COMPAT_SUPP);
+	if (features) {
+		ext2_msg(sb, KERN_ERR,	"error: won't mount because of "
+		       "unsupported optional features (%x); try ext4",
+			le32_to_cpu(features));
+		goto failed_mount;
+	}
+#endif
 	features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP);
 	if (features) {
 		ext2_msg(sb, KERN_ERR,	"error: couldn't mount because of "
Signature · 6 lines
Jan Kara <[email protected]>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 11 lines · Darrick J. Wong
Quoted 10 lines · Jan Kara
Quoted 8 lines · Darrick J. Wong

The ext2 mount code never checks the compat features against the ones it knows about. This is correct behavior since compat features are supposed to be rw-compatible with old drivers; however, for certain configurations (journalled rootfs) we probably want the ext4 driver to load, not ext2.

Quoted 7 lines
Quoted 3 lines

Isn't this a bit too harsh? I agree we should at least warn (and that's probably regardless of EXT4 config option) but just refusing mount looks too much to me...

I admit that refusing the mount might be a bit much; the goal here was merely to make it so that if the FS has a journal and ext4 was turned on, hopefully ext2 rejects the mount and ext4 will probe it next.

IMO it's worse to have the ext2 module is *incorrectly* mounting ext3 filesystems and users silently losing the protection of journalling. Perhaps we should simply make ext4 probe before ext2 probes anything. Anything that is not explicitly an ext4 or ext3 filesystem can then be left to the ext2 module (if EXT4 is not configured to also handle ext2).

But, really, I don't care enough about this to spend any more time on it - my systems are working again so it's up the the EXT maintainers to decide what to do with the problem...

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
Acked-by
#4 lore raw
In reply to Darrick J. Wong
Quoted 15 lines · Darrick J. Wong
Quoted 7 lines · Jan Kara
Quoted 6 lines · Darrick J. Wong

The ext2 mount code never checks the compat features against the ones it knows about. This is correct behavior since compat features are supposed to be rw-compatible with old drivers; however, for certain configurations (journalled rootfs) we probably want the ext4 driver to load, not ext2.

Quoted 6 lines
Quoted 2 lines

Isn't this a bit too harsh? I agree we should at least warn (and that's probably regardless of EXT4 config option) but just refusing mount looks too much to me...

Quoted 5 lines

I admit that refusing the mount might be a bit much; the goal here was merely to make it so that if the FS has a journal and ext4 was turned on, hopefully ext2 rejects the mount and ext4 will probe it next.

<shrug>

OK, after some more thought about this I agree that your solution is probably the best. I'd say it's exceedingly rare that someone would like to mount ext3 filesystem using ext2 driver when he has ext4 available. Definitely more rare than someone wanting to mount clean ext3 filesystem and unexpectedly using ext2 driver for that. So my:

Ted, can you please pick up the patch? Thanks!

Honza

Quoted 55 lines
Quoted 36 lines
Quoted 36 lines
---
 fs/ext2/ext2.h  |    6 +++++-
 fs/ext2/super.c |   13 ++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)
fs/ext2/ext2.h +5 -1
index 8d15feb..ce508b1 100644
@@ -547,7 +547,11 @@ struct ext2_super_block {
 #define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
 #define EXT2_FEATURE_INCOMPAT_ANY		0xffffffff
 
-#define EXT2_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
+#define EXT2_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC| \
+					 EXT2_FEATURE_COMPAT_IMAGIC_INODES| \
+					 EXT2_FEATURE_COMPAT_EXT_ATTR| \
+					 EXT2_FEATURE_COMPAT_RESIZE_INO| \
+					 EXT2_FEATURE_COMPAT_DIR_INDEX)
 #define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
 					 EXT2_FEATURE_INCOMPAT_META_BG)
 #define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
fs/ext2/super.c +6 -0
index 900e19c..4efb018 100644
@@ -896,6 +896,16 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 	 * previously didn't change the revision level when setting the flags,
 	 * so there is a chance incompat flags are set on a rev 0 filesystem.
 	 */
+#ifdef CONFIG_EXT4_FS
+	/* Journalled FS should mount with ext4 if it's available */
+	features = EXT2_HAS_COMPAT_FEATURE(sb, ~EXT2_FEATURE_COMPAT_SUPP);
+	if (features) {
+		ext2_msg(sb, KERN_ERR,	"error: won't mount because of "
+		       "unsupported optional features (%x); try ext4",
Quoted 15 lines
Quoted 8 lines
fs/ext2/super.c +4 -0
+			le32_to_cpu(features));
+		goto failed_mount;
+	}
+#endif
 	features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP);
 	if (features) {
 		ext2_msg(sb, KERN_ERR,	"error: couldn't mount because of "
Signature · 6 lines
Jan Kara <[email protected]>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#5 lore raw
Quoted 20 lines · Jan Kara
Quoted 19 lines · Darrick J. Wong
Quoted 7 lines · Jan Kara
Quoted 6 lines · Darrick J. Wong

The ext2 mount code never checks the compat features against the ones it knows about. This is correct behavior since compat features are supposed to be rw-compatible with old drivers; however, for certain configurations (journalled rootfs) we probably want the ext4 driver to load, not ext2.

Quoted 6 lines
Quoted 2 lines

Isn't this a bit too harsh? I agree we should at least warn (and that's probably regardless of EXT4 config option) but just refusing mount looks too much to me...

I admit that refusing the mount might be a bit much; the goal here was merely to make it so that if the FS has a journal and ext4 was turned on, hopefully ext2 rejects the mount and ext4 will probe it next.

Quoted 7 lines
Quoted 1 line

<shrug>

OK, after some more thought about this I agree that your solution is probably the best. I'd say it's exceedingly rare that someone would like to mount ext3 filesystem using ext2 driver when he has ext4 available. Definitely more rare than someone wanting to mount clean ext3 filesystem and unexpectedly using ext2 driver for that. So my:

Now that I've thought about it more, I don't think that it's a good idea to forever forbid mounting ext3 on ext2.ko. I'll send a patch to change the default probing order along with an advisory to specify rootfstype= if you compile both ext4 and ext2 and want specifically ext2 to drive.

That said, I still think that it's rare that anyone would really want to mount ext3 with ext2.ko other than perhaps as a desperate last resort to get data off the filesystem. Perhaps this patch will turn into something requiring readonly mounting if ext4 was built and has_journal is on... after changing the default probe order.

--D

Quoted 64 lines

Ted, can you please pick up the patch? Thanks!

Honza

Quoted 55 lines
Quoted 36 lines
Quoted 36 lines
---
 fs/ext2/ext2.h  |    6 +++++-
 fs/ext2/super.c |   13 ++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)
fs/ext2/ext2.h +5 -1
index 8d15feb..ce508b1 100644
@@ -547,7 +547,11 @@ struct ext2_super_block {
 #define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
 #define EXT2_FEATURE_INCOMPAT_ANY		0xffffffff
 
-#define EXT2_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
+#define EXT2_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC| \
+					 EXT2_FEATURE_COMPAT_IMAGIC_INODES| \
+					 EXT2_FEATURE_COMPAT_EXT_ATTR| \
+					 EXT2_FEATURE_COMPAT_RESIZE_INO| \
+					 EXT2_FEATURE_COMPAT_DIR_INDEX)
 #define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
 					 EXT2_FEATURE_INCOMPAT_META_BG)
 #define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
fs/ext2/super.c +6 -0
index 900e19c..4efb018 100644
@@ -896,6 +896,16 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
 	 * previously didn't change the revision level when setting the flags,
 	 * so there is a chance incompat flags are set on a rev 0 filesystem.
 	 */
+#ifdef CONFIG_EXT4_FS
+	/* Journalled FS should mount with ext4 if it's available */
+	features = EXT2_HAS_COMPAT_FEATURE(sb, ~EXT2_FEATURE_COMPAT_SUPP);
+	if (features) {
+		ext2_msg(sb, KERN_ERR,	"error: won't mount because of "
+		       "unsupported optional features (%x); try ext4",
Quoted 15 lines
Quoted 8 lines
fs/ext2/super.c +4 -0
+			le32_to_cpu(features));
+		goto failed_mount;
+	}
+#endif
 	features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP);
 	if (features) {
 		ext2_msg(sb, KERN_ERR,	"error: couldn't mount because of "
Signature · 6 lines
Jan Kara <[email protected]>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR