drivers/net/bonding/bond_options.c:1171:2: warning: 'strncpy' specified bound 16 equals destination size

From: kernel test robot
Date: Fri Feb 26 2021 - 09:03:36 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 2c87f7a38f930ef6f6a7bdd04aeb82ce3971b54b
commit: 421015713b306e47af95d4d61cdfbd96d462e4cb ARM: 9017/2: Enable KASan for ARM
date: 4 months ago
config: arm-randconfig-r012-20210226 (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.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=421015713b306e47af95d4d61cdfbd96d462e4cb
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 421015713b306e47af95d4d61cdfbd96d462e4cb
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.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 >>):

drivers/net/bonding/bond_options.c: In function 'bond_option_primary_set':
>> drivers/net/bonding/bond_options.c:1171:2: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
1171 | strncpy(bond->params.primary, primary, IFNAMSIZ);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
drivers/net/wireless/atmel/atmel.c: In function 'atmel_ioctl':
>> drivers/net/wireless/atmel/atmel.c:2659:3: warning: 'strncpy' output may be truncated copying 31 bytes from a string of length 31 [-Wstringop-truncation]
2659 | strncpy(priv->firmware_id, com.id, 31);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
In file included from drivers/net/wireless/broadcom/brcm80211/brcmsmac/main.h:24,
from drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c:26:
drivers/net/wireless/broadcom/brcm80211/brcmsmac/d11.h:786:1: warning: alignment 1 of 'struct d11txh' is less than 2 [-Wpacked-not-aligned]
786 | } __packed;
| ^
drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c: In function 'dma_attach':
>> drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c:587:2: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation]
587 | strncpy(di->name, name, MAXNAMEL);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/strncpy +1171 drivers/net/bonding/bond_options.c

0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1133
f3253339a47ff3 stephen hemminger 2014-03-04 1134 static int bond_option_primary_set(struct bonding *bond,
28f084cca35a73 stephen hemminger 2014-03-06 1135 const struct bond_opt_value *newval)
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1136 {
180222f08861d8 Nikolay Aleksandrov 2014-01-22 1137 char *p, *primary = newval->string;
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1138 struct list_head *iter;
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1139 struct slave *slave;
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1140
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1141 block_netpoll_tx();
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1142
180222f08861d8 Nikolay Aleksandrov 2014-01-22 1143 p = strchr(primary, '\n');
180222f08861d8 Nikolay Aleksandrov 2014-01-22 1144 if (p)
180222f08861d8 Nikolay Aleksandrov 2014-01-22 1145 *p = '\0';
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1146 /* check to see if we are clearing primary */
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1147 if (!strlen(primary)) {
eac306b4adb745 Michael Dilmore 2017-06-26 1148 netdev_dbg(bond->dev, "Setting primary slave to None\n");
059b47e8aaf997 Nikolay Aleksandrov 2014-09-09 1149 RCU_INIT_POINTER(bond->primary_slave, NULL);
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1150 memset(bond->params.primary, 0, sizeof(bond->params.primary));
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1151 bond_select_active_slave(bond);
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1152 goto out;
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1153 }
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1154
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1155 bond_for_each_slave(bond, slave, iter) {
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1156 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
f887e54ce34906 Jarod Wilson 2019-06-07 1157 slave_dbg(bond->dev, slave->dev, "Setting as primary slave\n");
059b47e8aaf997 Nikolay Aleksandrov 2014-09-09 1158 rcu_assign_pointer(bond->primary_slave, slave);
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1159 strcpy(bond->params.primary, slave->dev->name);
eb55bbf865d997 Xiangning Yu 2018-06-07 1160 bond->force_primary = true;
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1161 bond_select_active_slave(bond);
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1162 goto out;
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1163 }
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1164 }
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1165
059b47e8aaf997 Nikolay Aleksandrov 2014-09-09 1166 if (rtnl_dereference(bond->primary_slave)) {
eac306b4adb745 Michael Dilmore 2017-06-26 1167 netdev_dbg(bond->dev, "Setting primary slave to None\n");
059b47e8aaf997 Nikolay Aleksandrov 2014-09-09 1168 RCU_INIT_POINTER(bond->primary_slave, NULL);
c59ab673699b6d dingtianhong 2014-01-18 1169 bond_select_active_slave(bond);
c59ab673699b6d dingtianhong 2014-01-18 1170 }
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 @1171 strncpy(bond->params.primary, primary, IFNAMSIZ);
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1172 bond->params.primary[IFNAMSIZ - 1] = 0;
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1173
f887e54ce34906 Jarod Wilson 2019-06-07 1174 netdev_dbg(bond->dev, "Recording %s as primary, but it has not been enslaved yet\n",
f887e54ce34906 Jarod Wilson 2019-06-07 1175 primary);
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1176
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1177 out:
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1178 unblock_netpoll_tx();
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1179
180222f08861d8 Nikolay Aleksandrov 2014-01-22 1180 return 0;
0a98a0d12c40f9 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1181 }
8a41ae4496e534 sfeldma@xxxxxxxxxxxxxxxxxxx 2013-12-15 1182

:::::: The code at line 1171 was first introduced by commit
:::::: 0a98a0d12c40f9354b942325045cae123d594341 bonding: add primary attribute netlink support

:::::: TO: sfeldma@xxxxxxxxxxxxxxxxxxx <sfeldma@xxxxxxxxxxxxxxxxxxx>
:::::: CC: David S. Miller <davem@xxxxxxxxxxxxx>

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

Attachment: .config.gz
Description: application/gzip