Skip to contentSkip to conversation

octeontx2-af: cn10k: fix an array overflow in is_lmac_valid()

PATCH Applied Dan Carpenter 2 participants 2 messages Mar 3, 2021 – Mar 4, 2021

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

PATCH 1/1 octeontx2-af: cn10k: fix an array overflow in is_lmac_valid()

The value of "lmac_id" can be controlled by the user and if it is larger then the number of bits in long then it reads outside the bitmap. The highest valid value is less than MAX_LMAC_PER_CGX (4).

Fixes 91c6945ea1f9 ("octeontx2-af: cn10k: Add RPM MAC support")
---
 drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +3 -1
index 9caa375d01b1..68deae529bc9 100644
@@ -56,7 +56,9 @@ static bool is_dev_rpm(void *cgxd)
 
 bool is_lmac_valid(struct cgx *cgx, int lmac_id)
 {
-	return cgx && test_bit(lmac_id, &cgx->lmac_bmap);
+	if (!cgx || lmac_id < 0 || lmac_id >= MAX_LMAC_PER_CGX)
+		return false;
+	return test_bit(lmac_id, &cgx->lmac_bmap);
 }
 
 struct mac_ops *get_mac_ops(void *cgxd)
Signature · 1 line
2.30.1
#1 lore raw
This patch was applied to netdev/net.git (refs/heads/master):

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

Quoted 8 lines · On Tue, 2 Mar 2021 14:21:54 +0300 you wrote:

The value of "lmac_id" can be controlled by the user and if it is larger then the number of bits in long then it reads outside the bitmap. The highest valid value is less than MAX_LMAC_PER_CGX (4).

Fixes 91c6945ea1f9 ("octeontx2-af: cn10k: Add RPM MAC support")

[...]

Here is the summary with links:
- [net] octeontx2-af: cn10k: fix an array overflow in is_lmac_valid()

    https://git.kernel.org/netdev/net/c/2378b2c9ecf4

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html