[gustavoars-linux:for-next/Warray-bounds 1/1] arch/arm/kernel/atags_compat.c:200:2: warning: 'strcpy' offset 364 from the object at 'tags' is out of the bounds of referenced subobject 'cmdline' with type 'char[1]' at offset 364

From: kernel test robot
Date: Thu Jul 15 2021 - 06:36:48 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git for-next/Warray-bounds
head: 0d6455c92b82b36e29e5206a46329058d75fbc33
commit: 0d6455c92b82b36e29e5206a46329058d75fbc33 [1/1] Makefile: Enable -Warray-bounds
config: arm-randconfig-r035-20210715 (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 10.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=0d6455c92b82b36e29e5206a46329058d75fbc33
git remote add gustavoars-linux https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git
git fetch --no-tags gustavoars-linux for-next/Warray-bounds
git checkout 0d6455c92b82b36e29e5206a46329058d75fbc33
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross ARCH=arm

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

All warnings (new ones prefixed by >>):

In function 'build_tag_list',
inlined from 'convert_to_tag_list' at arch/arm/kernel/atags_compat.c:213:2:
>> arch/arm/kernel/atags_compat.c:200:2: warning: 'strcpy' offset 364 from the object at 'tags' is out of the bounds of referenced subobject 'cmdline' with type 'char[1]' at offset 364 [-Warray-bounds]
200 | strcpy(tag->u.cmdline.cmdline, params->commandline);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from arch/arm/include/asm/setup.h:14,
from arch/arm/kernel/atags_compat.c:20:
arch/arm/kernel/atags_compat.c: In function 'convert_to_tag_list':
arch/arm/include/uapi/asm/setup.h:127:7: note: subobject 'cmdline' declared here
127 | char cmdline[1]; /* this is the minimum size */
| ^~~~~~~


vim +200 arch/arm/kernel/atags_compat.c

^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 195
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 196 tag = tag_next(tag);
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 197 tag->hdr.tag = ATAG_CMDLINE;
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 198 tag->hdr.size = (strlen(params->commandline) + 3 +
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 199 sizeof(struct tag_header)) >> 2;
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 @200 strcpy(tag->u.cmdline.cmdline, params->commandline);
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 201
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 202 tag = tag_next(tag);
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 203 tag->hdr.tag = ATAG_NONE;
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 204 tag->hdr.size = 0;
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 205
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 206 memmove(params, taglist, ((int)tag) - ((int)taglist) +
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 207 sizeof(struct tag_header));
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 208 }
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 209
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 210 void __init convert_to_tag_list(struct tag *tags)
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 211 {
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 212 struct param_struct *params = (struct param_struct *)tags;
^1da177e4c3f41 arch/arm/kernel/compat.c Linus Torvalds 2005-04-16 @213 build_tag_list(params, &params->u2);

:::::: The code at line 200 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@xxxxxxxxxxxxxxx>
:::::: CC: Linus Torvalds <torvalds@xxxxxxxxxxxxxxx>

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

Attachment: .config.gz
Description: application/gzip