]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: fix orphan file size > kernel limit with large blocksize
authorBaokun Li <libaokun1@huawei.com>
Wed, 12 Nov 2025 12:21:57 +0000 (20:21 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 9 Dec 2025 13:36:54 +0000 (08:36 -0500)
Kernel commit 0a6ce20c1564 ("ext4: verify orphan file size is not too big")
limits the maximum supported orphan file size to 8 << 20.

However, in e2fsprogs, the orphan file size is set to 32–512 filesystem
blocks when creating a filesystem.

With 64k block size, formatting an ext4 fs >32G gives an orphan file bigger
than the kernel allows, so mount prints an error and fails:

    EXT4-fs (vdb): orphan file too big: 8650752
    EXT4-fs (vdb): mount failed

Therefore, synchronize the kernel change to e2fsprogs to avoid creating
orphan files larger than the kernel limit.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
Message-ID: <20251112122157.1990595-1-libaokun@huaweicloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ext2fs.h
lib/ext2fs/orphan.c

index bb2170b78d630823a00bc1f58b74bcdf30336199..d9df007c499f16228c14fe18c65646cac16f79d5 100644 (file)
@@ -1819,6 +1819,8 @@ errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
 
 /* orphan.c */
+#define EXT4_MAX_ORPHAN_FILE_SIZE      8 << 20
+#define EXT4_DEFAULT_ORPHAN_FILE_SIZE  2 << 20
 extern errcode_t ext2fs_create_orphan_file(ext2_filsys fs, blk_t num_blocks);
 extern errcode_t ext2fs_truncate_orphan_file(ext2_filsys fs);
 extern e2_blkcnt_t ext2fs_default_orphan_file_blocks(ext2_filsys fs);
index 14ac35694a39cbcff37ee62beee23fb391abb797..40b1c5c728ef164f5f9b898a9e7ba99222b65905 100644 (file)
@@ -164,6 +164,8 @@ errcode_t ext2fs_create_orphan_file(ext2_filsys fs, blk_t num_blocks)
        memset(zerobuf, 0, fs->blocksize);
        ob_tail = ext2fs_orphan_block_tail(fs, buf);
        ob_tail->ob_magic = ext2fs_cpu_to_le32(EXT4_ORPHAN_BLOCK_MAGIC);
+       if (num_blocks * fs->blocksize > EXT4_MAX_ORPHAN_FILE_SIZE)
+               num_blocks = EXT4_MAX_ORPHAN_FILE_SIZE / fs->blocksize;
        oi.num_blocks = num_blocks;
        oi.alloc_blocks = 0;
        oi.last_blk = 0;
@@ -216,18 +218,18 @@ out:
 
 /*
  * Find reasonable size for orphan file. We choose orphan file size to be
- * between 32 and 512 filesystem blocks and not more than 1/4096 of the
- * filesystem unless it is really small.
+ * between 32 filesystem blocks and EXT4_DEFAULT_ORPHAN_FILE_SIZE, and not
+ * more than 1/fs->blocksize of the filesystem unless it is really small.
  */
 e2_blkcnt_t ext2fs_default_orphan_file_blocks(ext2_filsys fs)
 {
        __u64 num_blocks = ext2fs_blocks_count(fs->super);
-       e2_blkcnt_t blks = 512;
+       e2_blkcnt_t blks = EXT4_DEFAULT_ORPHAN_FILE_SIZE / fs->blocksize;
 
        if (num_blocks < 128 * 1024)
                blks = 32;
-       else if (num_blocks < 2 * 1024 * 1024)
-               blks = num_blocks / 4096;
+       else if (num_blocks < EXT4_DEFAULT_ORPHAN_FILE_SIZE)
+               blks = num_blocks / fs->blocksize;
        return (blks + EXT2FS_CLUSTER_MASK(fs)) & ~EXT2FS_CLUSTER_MASK(fs);
 }