include/linux/seq_file.h:247:9: warning: 'strncpy' output may be truncated copying 4 bytes from a string of length 4

From: kernel test robot
Date: Sun May 01 2022 - 00:45:38 EST


Hi Ilya,

FYI, the error/warning still remains.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 57ae8a492116910bad2b3497ffe555b3a4b4180f
commit: e37b3dd063a1a68e28a7cfaf77c84c472112e330 s390: enable KCSAN
date: 9 months ago
config: s390-randconfig-r015-20220501 (https://download.01.org/0day-ci/archive/20220501/202205011239.gGl2ZZel-lkp@xxxxxxxxx/config)
compiler: s390-linux-gcc (GCC) 11.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/torvalds/linux.git/commit/?id=e37b3dd063a1a68e28a7cfaf77c84c472112e330
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout e37b3dd063a1a68e28a7cfaf77c84c472112e330
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash

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 file included from include/linux/seq_file_net.h:5,
from include/net/net_namespace.h:179,
from include/linux/inet.h:42,
from fs/ocfs2/super.c:21:
fs/ocfs2/super.c: In function 'ocfs2_show_options':
>> include/linux/seq_file.h:247:9: warning: 'strncpy' output may be truncated copying 4 bytes from a string of length 4 [-Wstringop-truncation]
247 | strncpy(val_buf, value, length); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/ocfs2/super.c:1539:17: note: in expansion of macro 'seq_show_option_n'
1539 | seq_show_option_n(s, "cluster_stack", osb->osb_cluster_stack,
| ^~~~~~~~~~~~~~~~~


vim +/strncpy +247 include/linux/seq_file.h

a068acf2ee7769 Kees Cook 2015-09-04 233
a068acf2ee7769 Kees Cook 2015-09-04 234 /**
a068acf2ee7769 Kees Cook 2015-09-04 235 * seq_show_option_n - display mount options with appropriate escapes
a068acf2ee7769 Kees Cook 2015-09-04 236 * where @value must be a specific length.
a068acf2ee7769 Kees Cook 2015-09-04 237 * @m: the seq_file handle
a068acf2ee7769 Kees Cook 2015-09-04 238 * @name: the mount option name
a068acf2ee7769 Kees Cook 2015-09-04 239 * @value: the mount option name's value, cannot be NULL
a068acf2ee7769 Kees Cook 2015-09-04 240 * @length: the length of @value to display
a068acf2ee7769 Kees Cook 2015-09-04 241 *
a068acf2ee7769 Kees Cook 2015-09-04 242 * This is a macro since this uses "length" to define the size of the
a068acf2ee7769 Kees Cook 2015-09-04 243 * stack buffer.
a068acf2ee7769 Kees Cook 2015-09-04 244 */
a068acf2ee7769 Kees Cook 2015-09-04 245 #define seq_show_option_n(m, name, value, length) { \
a068acf2ee7769 Kees Cook 2015-09-04 246 char val_buf[length + 1]; \
a068acf2ee7769 Kees Cook 2015-09-04 @247 strncpy(val_buf, value, length); \
a068acf2ee7769 Kees Cook 2015-09-04 248 val_buf[length] = '\0'; \
a068acf2ee7769 Kees Cook 2015-09-04 249 seq_show_option(m, name, val_buf); \
a068acf2ee7769 Kees Cook 2015-09-04 250 }
a068acf2ee7769 Kees Cook 2015-09-04 251

:::::: The code at line 247 was first introduced by commit
:::::: a068acf2ee77693e0bf39d6e07139ba704f461c3 fs: create and use seq_show_option for escaping

:::::: TO: Kees Cook <keescook@xxxxxxxxxxxx>
:::::: CC: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>

--
0-DAY CI Kernel Test Service
https://01.org/lkp