Re: [PATCH] fix array index out of bound exception

kernel test robot
2021-08-11T17:23:55Z

[-- Attachment #1: Type: text/plain, Size: 6789 bytes --]

Hi SULAIMAN",

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.14-rc5 next-20210811]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/F-A-SULAIMAN/fix-array-index-out-of-bound-exception/20210811-211453
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 761c6d7ec820f123b931e7b8ef7ec7c8564e450f
config: x86_64-randconfig-s022-20210810 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.3-348-gf0e6938b-dirty
# https://github.com/0day-ci/linux/commit/3c70bc4978e0cb74c7ba5189c093ecccf4564925
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review F-A-SULAIMAN/fix-array-index-out-of-bound-exception/20210811-211453
git checkout 3c70bc4978e0cb74c7ba5189c093ecccf4564925
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/udf/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

In file included from include/linux/byteorder/little_endian.h:5,
from arch/x86/include/uapi/asm/byteorder.h:5,
from include/asm-generic/bitops/le.h:7,
from arch/x86/include/asm/bitops.h:395,
from include/linux/bitops.h:32,
from include/linux/kernel.h:12,
from include/linux/list.h:9,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from fs/udf/udfdecl.h:10,
from fs/udf/super.c:41:
fs/udf/super.c: In function 'udf_count_free':
>> include/uapi/linux/byteorder/little_endian.h:34:42: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
34 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
| ^
include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
89 | #define le32_to_cpu __le32_to_cpu
| ^~~~~~~~~~~~~
fs/udf/super.c:2524:12: note: in expansion of macro 'le32_to_cpu'
2524 | accum = le32_to_cpu(
| ^~~~~~~~~~~

sparse warnings: (new ones prefixed by >>)
>> fs/udf/super.c:2524:33: sparse: sparse: cast to restricted __le32
>> fs/udf/super.c:2524:33: sparse: sparse: non size-preserving pointer to integer cast

vim +2524 fs/udf/super.c

^1da177e4c3f41 Linus Torvalds 2005-04-16 2499
cb00ea3528eb3c Cyrill Gorcunov 2007-07-19 2500 static unsigned int udf_count_free(struct super_block *sb)
^1da177e4c3f41 Linus Torvalds 2005-04-16 2501 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 2502 unsigned int accum = 0;
a4a8b99ec819ca Jan Kara 2020-01-07 2503 struct udf_sb_info *sbi = UDF_SB(sb);
6c79e987d629cb Marcin Slusarz 2008-02-08 2504 struct udf_part_map *map;
a4a8b99ec819ca Jan Kara 2020-01-07 2505 unsigned int part = sbi->s_partition;
a4a8b99ec819ca Jan Kara 2020-01-07 2506 int ptype = sbi->s_partmaps[part].s_partition_type;
a4a8b99ec819ca Jan Kara 2020-01-07 2507
a4a8b99ec819ca Jan Kara 2020-01-07 2508 if (ptype == UDF_METADATA_MAP25) {
a4a8b99ec819ca Jan Kara 2020-01-07 2509 part = sbi->s_partmaps[part].s_type_specific.s_metadata.
a4a8b99ec819ca Jan Kara 2020-01-07 2510 s_phys_partition_ref;
a4a8b99ec819ca Jan Kara 2020-01-07 2511 } else if (ptype == UDF_VIRTUAL_MAP15 || ptype == UDF_VIRTUAL_MAP20) {
a4a8b99ec819ca Jan Kara 2020-01-07 2512 /*
a4a8b99ec819ca Jan Kara 2020-01-07 2513 * Filesystems with VAT are append-only and we cannot write to
a4a8b99ec819ca Jan Kara 2020-01-07 2514 * them. Let's just report 0 here.
a4a8b99ec819ca Jan Kara 2020-01-07 2515 */
a4a8b99ec819ca Jan Kara 2020-01-07 2516 return 0;
a4a8b99ec819ca Jan Kara 2020-01-07 2517 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 2518
6c79e987d629cb Marcin Slusarz 2008-02-08 2519 if (sbi->s_lvid_bh) {
4b11111aba6c80 Marcin Slusarz 2008-02-08 2520 struct logicalVolIntegrityDesc *lvid =
4b11111aba6c80 Marcin Slusarz 2008-02-08 2521 (struct logicalVolIntegrityDesc *)
4b11111aba6c80 Marcin Slusarz 2008-02-08 2522 sbi->s_lvid_bh->b_data;
a4a8b99ec819ca Jan Kara 2020-01-07 2523 if (le32_to_cpu(lvid->numOfPartitions) > part) {
4b11111aba6c80 Marcin Slusarz 2008-02-08 @2524 accum = le32_to_cpu(
3c70bc4978e0cb F.A.Sulaiman 2021-08-11 2525 (lvid->freeSpaceTable + part));
^1da177e4c3f41 Linus Torvalds 2005-04-16 2526 if (accum == 0xFFFFFFFF)
^1da177e4c3f41 Linus Torvalds 2005-04-16 2527 accum = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 2528 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 2529 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 2530
^1da177e4c3f41 Linus Torvalds 2005-04-16 2531 if (accum)
^1da177e4c3f41 Linus Torvalds 2005-04-16 2532 return accum;
^1da177e4c3f41 Linus Torvalds 2005-04-16 2533
a4a8b99ec819ca Jan Kara 2020-01-07 2534 map = &sbi->s_partmaps[part];
6c79e987d629cb Marcin Slusarz 2008-02-08 2535 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
28de7948a89676 Cyrill Gorcunov 2007-07-21 2536 accum += udf_count_free_bitmap(sb,
6c79e987d629cb Marcin Slusarz 2008-02-08 2537 map->s_uspace.s_bitmap);
28de7948a89676 Cyrill Gorcunov 2007-07-21 2538 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 2539 if (accum)
^1da177e4c3f41 Linus Torvalds 2005-04-16 2540 return accum;
^1da177e4c3f41 Linus Torvalds 2005-04-16 2541
6c79e987d629cb Marcin Slusarz 2008-02-08 2542 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
28de7948a89676 Cyrill Gorcunov 2007-07-21 2543 accum += udf_count_free_table(sb,
6c79e987d629cb Marcin Slusarz 2008-02-08 2544 map->s_uspace.s_table);
28de7948a89676 Cyrill Gorcunov 2007-07-21 2545 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 2546 return accum;
^1da177e4c3f41 Linus Torvalds 2005-04-16 2547 }
54bb60d53114b8 Fabian Frederick 2017-01-06 2548

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 34744 bytes --]