[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 05:33:54 MSK 2025



On 2025/10/30 10:11, Deepanshu Kartikey wrote:
> Hi Heming,
> 
> Thank you for the detailed explanation! I understand the issue now.
> 
> cl_bpc stores "bits per cluster" (the log2 of cluster size in bytes),
> not "blocks per cluster".
> 
> The bug in the validation code is: u16 bpc = 1 <<
> (OCFS2_SB(sb)->s_clustersize_bits - sb->s_blocksize_bits);
> 
> This calculates "blocks per cluster" (e.g., 4 for 4KB clusters with
> 1KB blocks), but cl_bpc on disk stores "bits" (e.g., 12 for 4KB
> clusters).
> 
> The correct validation should be: if (le16_to_cpu(cl->cl_bpc) !=
> OCFS2_SB(sb)->s_clustersize_bits)
> 

This is not correct. In mkfs:

if (rec->flags & OCFS2_CHAIN_FL) {
	......
	di->id2.i_chain.cl_bpc = s->cluster_size / s->blocksize;
	...
}

So could you please do more investigation?

Joseph





More information about the lvc-project mailing list