Skip to contentSkip to conversation

octeontx2-af: Fix potential integer overflows on integer shifts

PATCH Applied Colin Ian King 4 participants 4 messages Oct 10, 2024 – Oct 15, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 octeontx2-af: Fix potential integer overflows on integer shifts

The left shift int 32 bit integer constants 1 is evaluated using 32 bit arithmetic and then assigned to a 64 bit unsigned integer. In the case where the shift is 32 or more this can lead to an overflow. Avoid this by shifting using the BIT_ULL macro instead.

Fixes 019aba04f08c ("octeontx2-af: Modify SMQ flush sequence to drop packets")

---

V2: Fix both (1 << i) shifts, thanks to Dan Carpenter for spotting the
second shift that I overlooked in the first patch.

---
 drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +2 -2
index 82832a24fbd8..da69350c6f76 100644
@@ -2411,7 +2411,7 @@ static int nix_smq_flush(struct rvu *rvu, int blkaddr,
 				 NIX_AF_TL3_TL2X_LINKX_CFG(tl2_tl3_link_schq, link));
 		if (!(cfg & BIT_ULL(12)))
 			continue;
-		bmap |= (1 << i);
+		bmap |= BIT_ULL(i);
 		cfg &= ~BIT_ULL(12);
 		rvu_write64(rvu, blkaddr,
 			    NIX_AF_TL3_TL2X_LINKX_CFG(tl2_tl3_link_schq, link), cfg);
@@ -2432,7 +2432,7 @@ static int nix_smq_flush(struct rvu *rvu, int blkaddr,
 
 	/* Set NIX_AF_TL3_TL2_LINKX_CFG[ENA] for the TL3/TL2 queue */
 	for (i = 0; i < (rvu->hw->cgx_links + rvu->hw->lbk_links); i++) {
-		if (!(bmap & (1 << i)))
+		if (!(bmap & BIT_ULL(i)))
 			continue;
 		cfg = rvu_read64(rvu, blkaddr,
 				 NIX_AF_TL3_TL2X_LINKX_CFG(tl2_tl3_link_schq, link));
Signature · 1 line
2.39.5
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Colin Ian King

The left shift int 32 bit integer constants 1 is evaluated using 32 bit arithmetic and then assigned to a 64 bit unsigned integer. In the case where the shift is 32 or more this can lead to an overflow. Avoid this by shifting using the BIT_ULL macro instead.

Fixes 019aba04f08c ("octeontx2-af: Modify SMQ flush sequence to drop packets")

---

V2: Fix both (1 << i) shifts, thanks to Dan Carpenter for spotting the
second shift that I overlooked in the first patch.

regards,
dan carpenter

maintainer
#2 lore raw
In reply to Colin Ian King
Quoted 11 lines · Colin Ian King

The left shift int 32 bit integer constants 1 is evaluated using 32 bit arithmetic and then assigned to a 64 bit unsigned integer. In the case where the shift is 32 or more this can lead to an overflow. Avoid this by shifting using the BIT_ULL macro instead.

Fixes 019aba04f08c ("octeontx2-af: Modify SMQ flush sequence to drop packets")

---

V2: Fix both (1 << i) shifts, thanks to Dan Carpenter for spotting the
second shift that I overlooked in the first patch.

The blamed commit is in the 'net' tree already, I'm applying the patch there.

Cheers,

Paolo

#3 lore raw
In reply to Colin Ian King
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Thu, 10 Oct 2024 16:45:19 +0100 you wrote:

The left shift int 32 bit integer constants 1 is evaluated using 32 bit arithmetic and then assigned to a 64 bit unsigned integer. In the case where the shift is 32 or more this can lead to an overflow. Avoid this by shifting using the BIT_ULL macro instead.

Fixes 019aba04f08c ("octeontx2-af: Modify SMQ flush sequence to drop packets")

[...]

Here is the summary with links:
- [next,V2] octeontx2-af: Fix potential integer overflows on integer shifts

    https://git.kernel.org/netdev/net/c/637c4f6fe40b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html