Skip to contentSkip to conversation

net/ixgbe: fix integer overflow in n-tuple filter mask

PATCH New Ciara Loftus 1 participant 1 message Nov 16 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/ixgbe: fix integer overflow in n-tuple filter mask

The uint8_t 5-tuple mask is promoted to a signed int before being shifted by IXGBE_FTQF_5TUPLE_MASK_SHIFT (25). The result does not fit in 32 bits, which is undefined behaviour for a signed type. In practice it is harmless since the bit that is lost does not contain any useful information. Regardless it should be fixed instead of relying on the undefined behaviour.

Fix it by casting the mask to uint32_t before the shift. For an unsigned type the result keeps only the low 32 bits, so the programmed value is unchanged.

Coverity issue: 507466

Fixes 76db0ac63987 ("ixgbe: add filters")
---
 drivers/net/intel/ixgbe/ixgbe_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/intel/ixgbe/ixgbe_ethdev.c +1 -1
index 7592031217..c81802c04c 100644
@@ -6413,7 +6413,7 @@ ixgbe_ntuple_filter_program(struct ixgbe_hw *hw, uint16_t index,
 		mask &= IXGBE_FTQF_DEST_PORT_MASK;
 	if (filter_info->proto_mask == 0)
 		mask &= IXGBE_FTQF_PROTOCOL_COMP_MASK;
-	ftqf |= mask << IXGBE_FTQF_5TUPLE_MASK_SHIFT;
+	ftqf |= (uint32_t)mask << IXGBE_FTQF_5TUPLE_MASK_SHIFT;
 	ftqf |= IXGBE_FTQF_POOL_MASK_EN;
 	ftqf |= IXGBE_FTQF_QUEUE_ENABLE;
 
Signature · 1 line
2.43.0