Skip to content

Commit 6f03c69

Browse files
LiBaokun96tytso
authored andcommitted
libext2fs: fix orphan file size > kernel limit with large blocksize
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>
1 parent 0b2752c commit 6f03c69

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/ext2fs/ext2fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,8 @@ errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
18191819
errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
18201820

18211821
/* orphan.c */
1822+
#define EXT4_MAX_ORPHAN_FILE_SIZE 8 << 20
1823+
#define EXT4_DEFAULT_ORPHAN_FILE_SIZE 2 << 20
18221824
extern errcode_t ext2fs_create_orphan_file(ext2_filsys fs, blk_t num_blocks);
18231825
extern errcode_t ext2fs_truncate_orphan_file(ext2_filsys fs);
18241826
extern e2_blkcnt_t ext2fs_default_orphan_file_blocks(ext2_filsys fs);

lib/ext2fs/orphan.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ errcode_t ext2fs_create_orphan_file(ext2_filsys fs, blk_t num_blocks)
164164
memset(zerobuf, 0, fs->blocksize);
165165
ob_tail = ext2fs_orphan_block_tail(fs, buf);
166166
ob_tail->ob_magic = ext2fs_cpu_to_le32(EXT4_ORPHAN_BLOCK_MAGIC);
167+
if (num_blocks * fs->blocksize > EXT4_MAX_ORPHAN_FILE_SIZE)
168+
num_blocks = EXT4_MAX_ORPHAN_FILE_SIZE / fs->blocksize;
167169
oi.num_blocks = num_blocks;
168170
oi.alloc_blocks = 0;
169171
oi.last_blk = 0;
@@ -216,18 +218,18 @@ errcode_t ext2fs_create_orphan_file(ext2_filsys fs, blk_t num_blocks)
216218

217219
/*
218220
* Find reasonable size for orphan file. We choose orphan file size to be
219-
* between 32 and 512 filesystem blocks and not more than 1/4096 of the
220-
* filesystem unless it is really small.
221+
* between 32 filesystem blocks and EXT4_DEFAULT_ORPHAN_FILE_SIZE, and not
222+
* more than 1/fs->blocksize of the filesystem unless it is really small.
221223
*/
222224
e2_blkcnt_t ext2fs_default_orphan_file_blocks(ext2_filsys fs)
223225
{
224226
__u64 num_blocks = ext2fs_blocks_count(fs->super);
225-
e2_blkcnt_t blks = 512;
227+
e2_blkcnt_t blks = EXT4_DEFAULT_ORPHAN_FILE_SIZE / fs->blocksize;
226228

227229
if (num_blocks < 128 * 1024)
228230
blks = 32;
229-
else if (num_blocks < 2 * 1024 * 1024)
230-
blks = num_blocks / 4096;
231+
else if (num_blocks < EXT4_DEFAULT_ORPHAN_FILE_SIZE)
232+
blks = num_blocks / fs->blocksize;
231233
return (blks + EXT2FS_CLUSTER_MASK(fs)) & ~EXT2FS_CLUSTER_MASK(fs);
232234
}
233235

0 commit comments

Comments
 (0)