Skip to contentSkip to conversation

ext4: Fix maximum orphan file size check

PATCH Applied Jan Kara 6 participants 6 messages Oct 2 – Nov 19

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 ext4: Fix maximum orphan file size check

Mikulas reported that e2fsprogs 1.47.4 with 1k fs blocksize by default creates orphan file of the size the kernel rejects. This is because that version of e2fsprogs creates 2MB file by default regardless of the block size and with 1k blocks that's more than the limit of 512 fs blocks. Fix the check to make kernel accept any file upto those 2MB regardless of the number of blocks.

Fixes 7c11c56eb32e ("ext4: align max orphan file size with e2fsprogs limit")
---
 fs/ext4/orphan.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ext4/orphan.c +7 -1
index b4675aa7ea96..7394d04e0fd9 100644
@@ -576,6 +576,7 @@ int ext4_init_orphan_info(struct super_block *sb)
 	int inodes_per_ob = ext4_inodes_per_orphan_block(sb);
 	struct ext4_orphan_block_tail *ot;
 	ino_t orphan_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_orphan_file_inum);
+	loff_t max_size;
 
 	if (!ext4_has_feature_orphan_file(sb))
 		return 0;
@@ -589,8 +590,13 @@ int ext4_init_orphan_info(struct super_block *sb)
 	 * This is just an artificial limit to prevent corrupted fs from
 	 * consuming absurd amounts of memory when pinning blocks of orphan
 	 * file in memory.
+	 *
+	 * e2fsprogs 1.47.4 produces 2MB orphan files by default regardless
+	 * of the number of blocks so that's where the second limit comes from.
 	 */
-	if (inode->i_size > (EXT4_MAX_ORPHAN_FILE_BLOCKS << inode->i_blkbits)) {
+	max_size = max(EXT4_MAX_ORPHAN_FILE_BLOCKS << inode->i_blkbits,
+		       2 << 20);
+	if (inode->i_size > max_size) {
 		ext4_msg(sb, KERN_ERR, "orphan file too big: %llu",
 			 (unsigned long long)inode->i_size);
 		ret = -EFSCORRUPTED;
Signature · 1 line
2.51.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Mikulas reported that e2fsprogs 1.47.4 with 1k fs blocksize by default creates orphan file of the size the kernel rejects. This is because that version of e2fsprogs creates 2MB file by default regardless of the block size and with 1k blocks that's more than the limit of 512 fs blocks. Fix the check to make kernel accept any file upto those 2MB regardless of the number of blocks.

Quoted 5 lines
Fixes 7c11c56eb32e ("ext4: align max orphan file size with e2fsprogs limit")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Tested-by Reviewed-by on v1 1/1
#2 lore raw
In reply to Jan Kara
Quoted 7 lines · Jan Kara

Mikulas reported that e2fsprogs 1.47.4 with 1k fs blocksize by default creates orphan file of the size the kernel rejects. This is because that version of e2fsprogs creates 2MB file by default regardless of the block size and with 1k blocks that's more than the limit of 512 fs blocks. Fix the check to make kernel accept any file upto those 2MB regardless of the number of blocks.

Quoted 5 lines
Fixes 7c11c56eb32e ("ext4: align max orphan file size with e2fsprogs limit")

Mikulas

Quoted 34 lines
---
 fs/ext4/orphan.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ext4/orphan.c +7 -1
index b4675aa7ea96..7394d04e0fd9 100644
@@ -576,6 +576,7 @@ int ext4_init_orphan_info(struct super_block *sb)
 	int inodes_per_ob = ext4_inodes_per_orphan_block(sb);
 	struct ext4_orphan_block_tail *ot;
 	ino_t orphan_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_orphan_file_inum);
+	loff_t max_size;
 
 	if (!ext4_has_feature_orphan_file(sb))
 		return 0;
@@ -589,8 +590,13 @@ int ext4_init_orphan_info(struct super_block *sb)
 	 * This is just an artificial limit to prevent corrupted fs from
 	 * consuming absurd amounts of memory when pinning blocks of orphan
 	 * file in memory.
+	 *
+	 * e2fsprogs 1.47.4 produces 2MB orphan files by default regardless
+	 * of the number of blocks so that's where the second limit comes from.
 	 */
-	if (inode->i_size > (EXT4_MAX_ORPHAN_FILE_BLOCKS << inode->i_blkbits)) {
+	max_size = max(EXT4_MAX_ORPHAN_FILE_BLOCKS << inode->i_blkbits,
+		       2 << 20);
+	if (inode->i_size > max_size) {
 		ext4_msg(sb, KERN_ERR, "orphan file too big: %llu",
 			 (unsigned long long)inode->i_size);
 		ret = -EFSCORRUPTED;
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Jan Kara
Quoted 7 lines · Jan Kara

Mikulas reported that e2fsprogs 1.47.4 with 1k fs blocksize by default creates orphan file of the size the kernel rejects. This is because that version of e2fsprogs creates 2MB file by default regardless of the block size and with 1k blocks that's more than the limit of 512 fs blocks. Fix the check to make kernel accept any file upto those 2MB regardless of the number of blocks.

Quoted 5 lines
Fixes 7c11c56eb32e ("ext4: align max orphan file size with e2fsprogs limit")

Thanks for fixing this.

The problem is only triggered by images created with the problematic
e2fsprogs: 1k-block filesystems between 512MiB and 2GiB, and 2k-block filesystems between 2GiB and 4GiB.

A more thorough fix would be to rebuild the orphan file with tune2fs. However, some instances may not get the chance to do that. So I think it's good to keep the kernel compatible with both versions of e2fsprogs. Feel free to add:

Quoted 31 lines
---
 fs/ext4/orphan.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ext4/orphan.c +7 -1
index b4675aa7ea96..7394d04e0fd9 100644
@@ -576,6 +576,7 @@ int ext4_init_orphan_info(struct super_block *sb)
 	int inodes_per_ob = ext4_inodes_per_orphan_block(sb);
 	struct ext4_orphan_block_tail *ot;
 	ino_t orphan_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_orphan_file_inum);
+	loff_t max_size;
 
 	if (!ext4_has_feature_orphan_file(sb))
 		return 0;
@@ -589,8 +590,13 @@ int ext4_init_orphan_info(struct super_block *sb)
 	 * This is just an artificial limit to prevent corrupted fs from
 	 * consuming absurd amounts of memory when pinning blocks of orphan
 	 * file in memory.
+	 *
+	 * e2fsprogs 1.47.4 produces 2MB orphan files by default regardless
+	 * of the number of blocks so that's where the second limit comes from.
 	 */
-	if (inode->i_size > (EXT4_MAX_ORPHAN_FILE_BLOCKS << inode->i_blkbits)) {
+	max_size = max(EXT4_MAX_ORPHAN_FILE_BLOCKS << inode->i_blkbits,
+		       2 << 20);
+	if (inode->i_size > max_size) {
 		ext4_msg(sb, KERN_ERR, "orphan file too big: %llu",
 			 (unsigned long long)inode->i_size);
 		ret = -EFSCORRUPTED;
Reviewed-by on v1 1/1
#4 lore raw
In reply to Jan Kara
Quoted 7 lines · Jan Kara

Mikulas reported that e2fsprogs 1.47.4 with 1k fs blocksize by default creates orphan file of the size the kernel rejects. This is because that version of e2fsprogs creates 2MB file by default regardless of the block size and with 1k blocks that's more than the limit of 512 fs blocks. Fix the check to make kernel accept any file upto those 2MB regardless of the number of blocks.

Quoted 5 lines
Fixes 7c11c56eb32e ("ext4: align max orphan file size with e2fsprogs limit")

Looks good to me.

Quoted 31 lines
---
 fs/ext4/orphan.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ext4/orphan.c +7 -1
index b4675aa7ea96..7394d04e0fd9 100644
@@ -576,6 +576,7 @@ int ext4_init_orphan_info(struct super_block *sb)
 	int inodes_per_ob = ext4_inodes_per_orphan_block(sb);
 	struct ext4_orphan_block_tail *ot;
 	ino_t orphan_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_orphan_file_inum);
+	loff_t max_size;
 
 	if (!ext4_has_feature_orphan_file(sb))
 		return 0;
@@ -589,8 +590,13 @@ int ext4_init_orphan_info(struct super_block *sb)
 	 * This is just an artificial limit to prevent corrupted fs from
 	 * consuming absurd amounts of memory when pinning blocks of orphan
 	 * file in memory.
+	 *
+	 * e2fsprogs 1.47.4 produces 2MB orphan files by default regardless
+	 * of the number of blocks so that's where the second limit comes from.
 	 */
-	if (inode->i_size > (EXT4_MAX_ORPHAN_FILE_BLOCKS << inode->i_blkbits)) {
+	max_size = max(EXT4_MAX_ORPHAN_FILE_BLOCKS << inode->i_blkbits,
+		       2 << 20);
+	if (inode->i_size > max_size) {
 		ext4_msg(sb, KERN_ERR, "orphan file too big: %llu",
 			 (unsigned long long)inode->i_size);
 		ret = -EFSCORRUPTED;
maintainer Applied
#5 lore raw
In reply to Jan Kara
Quoted 8 lines · Jan Kara

Mikulas reported that e2fsprogs 1.47.4 with 1k fs blocksize by default creates orphan file of the size the kernel rejects. This is because that version of e2fsprogs creates 2MB file by default regardless of the block size and with 1k blocks that's more than the limit of 512 fs blocks. Fix the check to make kernel accept any file upto those 2MB regardless of the number of blocks.

[...]

Applied, thanks!

[1/1] ext4: Fix maximum orphan file size check

      commit: fce77179ac1007f88850f86f72b4ca58d566b113

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>