drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:948 npc_update_entry() error: buffer overflow 'kw' 8 <= 8

kernel test robot <[email protected]>
Newsgroups dev.linux.lists.oe-kbuild
Message-ID <[email protected]>
BCC: [email protected]
CC: [email protected]
CC: [email protected]
TO: Ratheesh Kannoth <[email protected]>
CC: Jakub Kicinski <[email protected]>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   f5bbbfec59b4e2fb7520a91de3df8a6174325d6a
commit: de3f88b465c8fda07b1dc44648a99f7dec390705 octeontx2-af: npc: cn20k: Prepare for new SoC
date:   6 months ago
:::::: branch date: 30 hours ago
:::::: commit date: 6 months ago
config: arm64-randconfig-r071-20260812 (https://download.01.org/0day-ci/archive/20260813/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 9.5.0
smatch: v0.5.0-9187-g5189e3fb

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
| Fixes: de3f88b465c8 ("octeontx2-af: npc: cn20k: Prepare for new SoC")
| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

New smatch warnings:
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:948 npc_update_entry() error: buffer overflow 'kw' 8 <= 8
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:953 npc_update_entry() error: buffer overflow 'kw_mask' 8 <= 8

Old smatch warnings:
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:947 npc_update_entry() error: buffer overflow 'field->kw_mask' 8 <= 8
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:952 npc_update_entry() error: buffer overflow 'field->kw_mask' 8 <= 8
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:961 npc_update_entry() error: buffer overflow 'field->kw_mask' 8 <= 8
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:963 npc_update_entry() error: buffer overflow 'field->kw_mask' 8 <= 9
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:964 npc_update_entry() error: buffer overflow 'kw' 8 <= 8
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:965 npc_update_entry() error: buffer overflow 'kw' 8 <= 9
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:969 npc_update_entry() error: buffer overflow 'field->kw_mask' 8 <= 8
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:971 npc_update_entry() error: buffer overflow 'field->kw_mask' 8 <= 9
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:972 npc_update_entry() error: buffer overflow 'kw_mask' 8 <= 8
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c:973 npc_update_entry() error: buffer overflow 'kw_mask' 8 <= 9

vim +/kw +948 drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c

55307fcb925846d Subbaraya Sundeep 2020-11-15  893  
55307fcb925846d Subbaraya Sundeep 2020-11-15  894  /* npc_update_entry - Based on the masks generated during
55307fcb925846d Subbaraya Sundeep 2020-11-15  895   * the key scanning, updates the given entry with value and
55307fcb925846d Subbaraya Sundeep 2020-11-15  896   * masks for the field of interest. Maximum 16 bytes of a packet
55307fcb925846d Subbaraya Sundeep 2020-11-15  897   * header can be extracted by HW hence lo and hi are sufficient.
55307fcb925846d Subbaraya Sundeep 2020-11-15  898   * When field bytes are less than or equal to 8 then hi should be
55307fcb925846d Subbaraya Sundeep 2020-11-15  899   * 0 for value and mask.
55307fcb925846d Subbaraya Sundeep 2020-11-15  900   *
55307fcb925846d Subbaraya Sundeep 2020-11-15  901   * If exact match of value is required then mask should be all 1's.
55307fcb925846d Subbaraya Sundeep 2020-11-15  902   * If any bits in mask are 0 then corresponding bits in value are
55307fcb925846d Subbaraya Sundeep 2020-11-15  903   * dont care.
55307fcb925846d Subbaraya Sundeep 2020-11-15  904   */
56d9f5fd2246241 Ratheesh Kannoth  2022-07-08  905  void npc_update_entry(struct rvu *rvu, enum key_fields type,
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  906  		      struct mcam_entry_mdata *mdata, u64 val_lo,
55307fcb925846d Subbaraya Sundeep 2020-11-15  907  		      u64 val_hi, u64 mask_lo, u64 mask_hi, u8 intf)
55307fcb925846d Subbaraya Sundeep 2020-11-15  908  {
55307fcb925846d Subbaraya Sundeep 2020-11-15  909  	struct npc_mcam *mcam = &rvu->hw->mcam;
55307fcb925846d Subbaraya Sundeep 2020-11-15  910  	struct mcam_entry dummy = { {0} };
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  911  	u64 *kw, *kw_mask, *val, *mask;
55307fcb925846d Subbaraya Sundeep 2020-11-15  912  	struct npc_key_field *field;
55307fcb925846d Subbaraya Sundeep 2020-11-15  913  	u64 kw1, kw2, kw3;
ef992a0f12e8268 Suman Ghosh       2026-02-24  914  	int i, max_kw;
55307fcb925846d Subbaraya Sundeep 2020-11-15  915  	u8 shift;
55307fcb925846d Subbaraya Sundeep 2020-11-15  916  
55307fcb925846d Subbaraya Sundeep 2020-11-15  917  	field = &mcam->rx_key_fields[type];
55307fcb925846d Subbaraya Sundeep 2020-11-15  918  	if (is_npc_intf_tx(intf))
55307fcb925846d Subbaraya Sundeep 2020-11-15  919  		field = &mcam->tx_key_fields[type];
55307fcb925846d Subbaraya Sundeep 2020-11-15  920  
55307fcb925846d Subbaraya Sundeep 2020-11-15  921  	if (!field->nr_kws)
55307fcb925846d Subbaraya Sundeep 2020-11-15  922  		return;
55307fcb925846d Subbaraya Sundeep 2020-11-15  923  
ef992a0f12e8268 Suman Ghosh       2026-02-24  924  	max_kw = NPC_MAX_KWS_IN_KEY;
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  925  	kw = dummy.kw;
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  926  	kw_mask = dummy.kw_mask;
ef992a0f12e8268 Suman Ghosh       2026-02-24  927  
ef992a0f12e8268 Suman Ghosh       2026-02-24  928  	for (i = 0; i < max_kw; i++) {
55307fcb925846d Subbaraya Sundeep 2020-11-15  929  		if (!field->kw_mask[i])
55307fcb925846d Subbaraya Sundeep 2020-11-15  930  			continue;
55307fcb925846d Subbaraya Sundeep 2020-11-15  931  		/* place key value in kw[x] */
55307fcb925846d Subbaraya Sundeep 2020-11-15  932  		shift = __ffs64(field->kw_mask[i]);
55307fcb925846d Subbaraya Sundeep 2020-11-15  933  		/* update entry value */
55307fcb925846d Subbaraya Sundeep 2020-11-15  934  		kw1 = (val_lo << shift) & field->kw_mask[i];
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  935  		kw[i] = kw1;
55307fcb925846d Subbaraya Sundeep 2020-11-15  936  		/* update entry mask */
55307fcb925846d Subbaraya Sundeep 2020-11-15  937  		kw1 = (mask_lo << shift) & field->kw_mask[i];
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  938  		kw_mask[i] = kw1;
55307fcb925846d Subbaraya Sundeep 2020-11-15  939  
55307fcb925846d Subbaraya Sundeep 2020-11-15  940  		if (field->nr_kws == 1)
55307fcb925846d Subbaraya Sundeep 2020-11-15  941  			break;
55307fcb925846d Subbaraya Sundeep 2020-11-15  942  		/* place remaining bits of key value in kw[x + 1] */
55307fcb925846d Subbaraya Sundeep 2020-11-15  943  		if (field->nr_kws == 2) {
55307fcb925846d Subbaraya Sundeep 2020-11-15  944  			/* update entry value */
55307fcb925846d Subbaraya Sundeep 2020-11-15  945  			kw2 = shift ? val_lo >> (64 - shift) : 0;
55307fcb925846d Subbaraya Sundeep 2020-11-15  946  			kw2 |= (val_hi << shift);
55307fcb925846d Subbaraya Sundeep 2020-11-15  947  			kw2 &= field->kw_mask[i + 1];
de3f88b465c8fda Ratheesh Kannoth  2026-02-24 @948  			kw[i + 1] = kw2;
55307fcb925846d Subbaraya Sundeep 2020-11-15  949  			/* update entry mask */
55307fcb925846d Subbaraya Sundeep 2020-11-15  950  			kw2 = shift ? mask_lo >> (64 - shift) : 0;
55307fcb925846d Subbaraya Sundeep 2020-11-15  951  			kw2 |= (mask_hi << shift);
55307fcb925846d Subbaraya Sundeep 2020-11-15  952  			kw2 &= field->kw_mask[i + 1];
de3f88b465c8fda Ratheesh Kannoth  2026-02-24 @953  			kw_mask[i + 1] = kw2;
55307fcb925846d Subbaraya Sundeep 2020-11-15  954  			break;
55307fcb925846d Subbaraya Sundeep 2020-11-15  955  		}
55307fcb925846d Subbaraya Sundeep 2020-11-15  956  		/* place remaining bits of key value in kw[x + 1], kw[x + 2] */
55307fcb925846d Subbaraya Sundeep 2020-11-15  957  		if (field->nr_kws == 3) {
55307fcb925846d Subbaraya Sundeep 2020-11-15  958  			/* update entry value */
55307fcb925846d Subbaraya Sundeep 2020-11-15  959  			kw2 = shift ? val_lo >> (64 - shift) : 0;
55307fcb925846d Subbaraya Sundeep 2020-11-15  960  			kw2 |= (val_hi << shift);
55307fcb925846d Subbaraya Sundeep 2020-11-15  961  			kw2 &= field->kw_mask[i + 1];
55307fcb925846d Subbaraya Sundeep 2020-11-15  962  			kw3 = shift ? val_hi >> (64 - shift) : 0;
55307fcb925846d Subbaraya Sundeep 2020-11-15  963  			kw3 &= field->kw_mask[i + 2];
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  964  			kw[i + 1] = kw2;
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  965  			kw[i + 2] = kw3;
55307fcb925846d Subbaraya Sundeep 2020-11-15  966  			/* update entry mask */
55307fcb925846d Subbaraya Sundeep 2020-11-15  967  			kw2 = shift ? mask_lo >> (64 - shift) : 0;
55307fcb925846d Subbaraya Sundeep 2020-11-15  968  			kw2 |= (mask_hi << shift);
55307fcb925846d Subbaraya Sundeep 2020-11-15  969  			kw2 &= field->kw_mask[i + 1];
55307fcb925846d Subbaraya Sundeep 2020-11-15  970  			kw3 = shift ? mask_hi >> (64 - shift) : 0;
55307fcb925846d Subbaraya Sundeep 2020-11-15  971  			kw3 &= field->kw_mask[i + 2];
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  972  			kw_mask[i + 1] = kw2;
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  973  			kw_mask[i + 2] = kw3;
55307fcb925846d Subbaraya Sundeep 2020-11-15  974  			break;
55307fcb925846d Subbaraya Sundeep 2020-11-15  975  		}
55307fcb925846d Subbaraya Sundeep 2020-11-15  976  	}
55307fcb925846d Subbaraya Sundeep 2020-11-15  977  	/* dummy is ready with values and masks for given key
55307fcb925846d Subbaraya Sundeep 2020-11-15  978  	 * field now clear and update input entry with those
55307fcb925846d Subbaraya Sundeep 2020-11-15  979  	 */
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  980  
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  981  	val = mdata->kw;
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  982  	mask = mdata->kw_mask;
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  983  
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  984  	for (i = 0; i < max_kw; i++, val++, mask++) {
55307fcb925846d Subbaraya Sundeep 2020-11-15  985  		if (!field->kw_mask[i])
55307fcb925846d Subbaraya Sundeep 2020-11-15  986  			continue;
55307fcb925846d Subbaraya Sundeep 2020-11-15  987  
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  988  		*val &= ~field->kw_mask[i];
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  989  		*mask &= ~field->kw_mask[i];
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  990  
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  991  		*val |= kw[i];
de3f88b465c8fda Ratheesh Kannoth  2026-02-24  992  		*mask |= kw_mask[i];
55307fcb925846d Subbaraya Sundeep 2020-11-15  993  	}
55307fcb925846d Subbaraya Sundeep 2020-11-15  994  }
55307fcb925846d Subbaraya Sundeep 2020-11-15  995  

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.