octeontx2-af: cn10k: fix an array overflow in is_lmac_valid()
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 2 Mar 2021 11:21:54 +0000 (14:21 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 3 Mar 2021 16:44:24 +0000 (08:44 -0800)
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")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/marvell/octeontx2/af/cgx.c

index 9caa375d01b15dec793e26209b8ea8cc97bda720..68deae529bc94a4ddb32503ce6424d8122495c6b 100644 (file)
@@ -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)