fs/xfs/xfs_zone_gc.c:322 xfs_zone_gc_data_alloc() error: buffer overflow 'data->scratch' 2 <= s32max
PATCH 51/57 fs/xfs/xfs_zone_gc.c:322 xfs_zone_gc_data_alloc() error: buffer overflow 'data->scratch' 2 <= s32max
tree: git://git.infradead.org/users/hch/xfs xfs-zoned-rebase head: ccc2db4d79624bc274d9879eb76670cad04efeff commit: e334accc28179d073922768f2deec41758403cf0 [51/57] xfs: support zoned RT devices config: x86_64-randconfig-161-20240914 (https://download.01.org/0day-ci/archive/20240915/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:fs/xfs/xfs_zone_gc.c:322 xfs_zone_gc_data_alloc() error: buffer overflow 'data->scratch' 2 <= s32max
vim +322 fs/xfs/xfs_zone_gc.c
e334accc28179d Christoph Hellwig 2024-09-10 291 static struct xfs_zone_gc_data *
e334accc28179d Christoph Hellwig 2024-09-10 292 xfs_zone_gc_data_alloc(
e334accc28179d Christoph Hellwig 2024-09-10 293 struct xfs_mount *mp)
e334accc28179d Christoph Hellwig 2024-09-10 294 {
e334accc28179d Christoph Hellwig 2024-09-10 295 struct xfs_zone_gc_data *data;
e334accc28179d Christoph Hellwig 2024-09-10 296 int i;
e334accc28179d Christoph Hellwig 2024-09-10 297
e334accc28179d Christoph Hellwig 2024-09-10 298 data = kzalloc(sizeof(*data), GFP_KERNEL);
e334accc28179d Christoph Hellwig 2024-09-10 299 if (!data)
e334accc28179d Christoph Hellwig 2024-09-10 300 return NULL;
e334accc28179d Christoph Hellwig 2024-09-10 301
e334accc28179d Christoph Hellwig 2024-09-10 302 /*
e334accc28179d Christoph Hellwig 2024-09-10 303 * We actually only need a single bio_vec. It would be nice to have
e334accc28179d Christoph Hellwig 2024-09-10 304 * a flag that only allocates the inline bvecs and not the separate
e334accc28179d Christoph Hellwig 2024-09-10 305 * bvec pool.
e334accc28179d Christoph Hellwig 2024-09-10 306 */
e334accc28179d Christoph Hellwig 2024-09-10 307 if (bioset_init(&data->bio_set, 4, offsetof(struct xfs_gc_bio, bio),
e334accc28179d Christoph Hellwig 2024-09-10 308 BIOSET_NEED_BVECS))
e334accc28179d Christoph Hellwig 2024-09-10 309 goto out_free_data;
e334accc28179d Christoph Hellwig 2024-09-10 310 for (i = 0; i < XFS_ZONE_GC_NR_SCRATCH; i++) {
e334accc28179d Christoph Hellwig 2024-09-10 311 data->scratch[i].folio =
e334accc28179d Christoph Hellwig 2024-09-10 312 folio_alloc(GFP_KERNEL, get_order(XFS_GC_CHUNK_SIZE));
e334accc28179d Christoph Hellwig 2024-09-10 313 if (!data->scratch[i].folio)
e334accc28179d Christoph Hellwig 2024-09-10 314 goto out_free_scratch;
e334accc28179d Christoph Hellwig 2024-09-10 315 }
e334accc28179d Christoph Hellwig 2024-09-10 316 spin_lock_init(&data->list_lock);
e334accc28179d Christoph Hellwig 2024-09-10 317 data->mp = mp;
e334accc28179d Christoph Hellwig 2024-09-10 318 return data;
e334accc28179d Christoph Hellwig 2024-09-10 319
e334accc28179d Christoph Hellwig 2024-09-10 320 out_free_scratch:
e334accc28179d Christoph Hellwig 2024-09-10 321 while (--i > 0)The warning is garbage, but this should be ">= 0" instead of "> 0".
e334accc28179d Christoph Hellwig 2024-09-10 @322 folio_put(data->scratch[i].folio); e334accc28179d Christoph Hellwig 2024-09-10 323 bioset_exit(&data->bio_set); e334accc28179d Christoph Hellwig 2024-09-10 324 out_free_data: e334accc28179d Christoph Hellwig 2024-09-10 325 kfree(data); e334accc28179d Christoph Hellwig 2024-09-10 326 return NULL; e334accc28179d Christoph Hellwig 2024-09-10 327 }
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki