Re: fs/erofs/zmap.c:394 z_erofs_get_extent_compressedlen() warn: should '1 << lclusterbits' be a 64 bit type?

From: Gao Xiang
Date: Wed Mar 09 2022 - 06:15:49 EST


Hi Dan,

On Wed, Mar 09, 2022 at 01:27:08PM +0300, Dan Carpenter wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 92f90cc9fe0e7a984ea3d4bf3d120e30ba8a2118
> commit: cec6e93beadfd145758af2c0854fcc2abb8170cb erofs: support parsing big pcluster compress indexes
> config: i386-randconfig-m021-20220307 (https://download.01.org/0day-ci/archive/20220309/202203091002.lJVzsX6e-lkp@xxxxxxxxx/config)
> compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
>
> smatch warnings:
> fs/erofs/zmap.c:394 z_erofs_get_extent_compressedlen() warn: should '1 << lclusterbits' be a 64 bit type?
> fs/erofs/zmap.c:423 z_erofs_get_extent_compressedlen() warn: should 'm->compressedlcs << lclusterbits' be a 64 bit type?
>
> vim +394 fs/erofs/zmap.c
>
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 381 static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 382 unsigned int initial_lcn)
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 383 {
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 384 struct erofs_inode *const vi = EROFS_I(m->inode);
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 385 struct erofs_map_blocks *const map = m->map;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 386 const unsigned int lclusterbits = vi->z_logical_clusterbits;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 387 unsigned long lcn;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 388 int err;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 389
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 390 DBG_BUGON(m->type != Z_EROFS_VLE_CLUSTER_TYPE_PLAIN &&
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 391 m->type != Z_EROFS_VLE_CLUSTER_TYPE_HEAD);
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 392 if (!(map->m_flags & EROFS_MAP_ZIPPED) ||
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 393 !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1)) {
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 @394 map->m_plen = 1 << lclusterbits;
>
> 1ULL << lclusterbits?

Thanks for the report!

In practice, m_plen won't be larger than 1MiB due to on-disk constraint
for compression mode, so we're always safe here. m_plen only can be
larger than 4GiB for non-compression mode.

Yet we could update this on the static analysis side, I will submit a
patch later.

>
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 395 return 0;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 396 }
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 397
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 398 lcn = m->lcn + 1;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 399 if (m->compressedlcs)
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 400 goto out;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 401 if (lcn == initial_lcn)
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 402 goto err_bonus_cblkcnt;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 403
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 404 err = z_erofs_load_cluster_from_disk(m, lcn);
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 405 if (err)
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 406 return err;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 407
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 408 switch (m->type) {
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 409 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 410 if (m->delta[0] != 1)
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 411 goto err_bonus_cblkcnt;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 412 if (m->compressedlcs)
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 413 break;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 414 fallthrough;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 415 default:
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 416 erofs_err(m->inode->i_sb,
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 417 "cannot found CBLKCNT @ lcn %lu of nid %llu",
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 418 lcn, vi->nid);
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 419 DBG_BUGON(1);
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 420 return -EFSCORRUPTED;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 421 }
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 422 out:
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 @423 map->m_plen = m->compressedlcs << lclusterbits;
>
> Same thing here.

Ditto.

Thanks,
Gao Xiang

>
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 424 return 0;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 425 err_bonus_cblkcnt:
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 426 erofs_err(m->inode->i_sb,
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 427 "bogus CBLKCNT @ lcn %lu of nid %llu",
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 428 lcn, vi->nid);
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 429 DBG_BUGON(1);
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 430 return -EFSCORRUPTED;
> cec6e93beadfd1 fs/erofs/zmap.c Gao Xiang 2021-04-07 431 }
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx
>