[lvc-project] [PATCH 2/2] ocfs2: validate cl_bpc in allocator inodes to prevent divide-by-zero
Joseph Qi
joseph.qi at linux.alibaba.com
Thu Oct 30 06:38:22 MSK 2025
On 2025/10/30 11:30, Deepanshu Kartikey wrote:
> Hi Joseph, Heming, and Dmitry,
>
> Investigation complete. Here are the full test results:
>
> **Test Setup:**
> - Kernel: Custom build with cl_bpc validation patch
> - Filesystems: Created with mkfs.ocfs2 -b [512|1024|2048|4096] -M
> local --fs-features=metaecc
>
> **Results:**
>
> 512-byte blocks (4KB cluster):
> inode=20: cl_bpc=8, expected=8 (cluster_bits=12, block_bits=9) : PASS
> inode=23: cl_bpc=1, expected=8 (cluster_bits=12, block_bits=9) :FAIL
I've also seen this. From debugfs.ocfs2, inode 23 is global_bitmap:
[root at localhost ~]# debugfs.ocfs2 /dev/vdc
debugfs.ocfs2 1.8.7
debugfs: ls //
18 16 1 2 .
18 16 2 2 ..
19 24 10 1 bad_blocks
20 32 18 1 global_inode_alloc
21 20 8 1 slot_map
22 24 9 1 heartbeat
23 28 13 1 global_bitmap
24 28 15 2 orphan_dir:0000
25 32 17 1 extent_alloc:0000
26 28 16 1 inode_alloc:0000
27 24 12 1 journal:0000
28 28 16 1 local_alloc:0000
29 148 17 1 truncate_log:0000
And this can be verified in mkfs:
if (rec->cluster_bitmap) {
...
di->id2.i_chain.cl_bpc = 1;
...
}
So this check conflicts with global bitmap.
Joseph
> → Validation detects corruption
>
> 1024-byte blocks (4KB cluster):
> inode=12: cl_bpc=4, expected=4 (cluster_bits=12, block_bits=10) :PASS
> inode=15: cl_bpc=1, expected=4 (cluster_bits=12, block_bits=10) :FAIL
> → Validation detects corruption
>
> 2048-byte blocks (4KB cluster):
> inode=10: cl_bpc=2, expected=2 (cluster_bits=12, block_bits=11) : PASS
> inode=13: cl_bpc=1, expected=2 (cluster_bits=12, block_bits=11): FAIL
> → Validation detects corruption
>
> 4096-byte blocks (4KB cluster):
> inode=8: cl_bpc=1, expected=1 (cluster_bits=12, block_bits=12) : PASS
> inode=11: cl_bpc=1, expected=1 (cluster_bits=12, block_bits=12) :PASS
> → All inodes correct, mount succeeds
>
> **Analysis:**
>
> 1. The validation calculates expected cl_bpc as:
> expected_bpc = 1 << (cluster_size_bits - block_size_bits)
>
> This matches the mkfs.ocfs2 source code you referenced:
> di->id2.i_chain.cl_bpc = s->cluster_size / s->blocksize
>
> 2. For non-4K block sizes, some allocator inodes (20, 12, 10, 8) have
> correct cl_bpc values, while others (23, 15, 13) consistently have
> cl_bpc=1.
>
> 3. For 4K blocks, all allocator inodes have the correct value (1).
>
> The improved error message now includes:
> "Inode %llu has corrupted cl_bpc: ondisk=%u expected=%u
> (cluster_size_bits=%u block_size_bits=%u)"
>
> Please advise on next steps.
>
> Thanks,
> Deepanshu
More information about the lvc-project
mailing list