Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: octeontx2-pf: Fix UB in shift operation
@ 2026-07-24 12:19 Sergey.V.Frolov
  2026-07-27  3:27 ` Ratheesh Kannoth
  0 siblings, 1 reply; 5+ messages in thread
From: Sergey.V.Frolov @ 2026-07-24 12:19 UTC (permalink / raw)
  To: sgoutham, gakula, rkannoth, sbhatta, bbhushan2, andrew+netdev,
	davem, edumazet, kuba, pabeni
  Cc: netdev, Sergey.V.Frolov

From: "Sergey.V.Frolov" <Sergey.V.Frolov@kaspersky.com>

In function otx2_get_egress_burst_cfg, when the parameter `burst` is
255 and the max mantissa is 255 (0xFFULL), `burst_exp` is set to
`ilog2(255) - 1`, which equals 6.

This results in an unsigned wrap-around when calculating
`(1ULL << (*burst_exp - 7))`, since `*burst_exp - 7` becomes -1,
which makes the shift operand 0xFFFFFFFF. This value is greater than
the width of the left operand.

According to standard 6.5.7 p.3:
"The type of the result is that of the promoted left operand.
If the value of the right operand is negative or is greater than
or equal to the width of the promoted left operand, the behavior
is undefined."

Add a check to handle cases where `*burst_exp` is less than 7.

Signed-off-by: Sergey.V.Frolov <Sergey.V.Frolov@kaspersky.com>
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
index 40162b08014d..39bd73a214af 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
@@ -53,10 +53,15 @@ static void otx2_get_egress_burst_cfg(struct otx2_nic *nic, u32 burst,
 	if (burst) {
 		*burst_exp = ilog2(burst) ? ilog2(burst) - 1 : 0;
 		tmp = burst - rounddown_pow_of_two(burst);
-		if (burst < max_mantissa)
+		if (burst < max_mantissa) {
 			*burst_mantissa = tmp * 2;
-		else
-			*burst_mantissa = tmp / (1ULL << (*burst_exp - 7));
+		} else {
+			if (*burst_exp >= 7) {
+				*burst_mantissa = tmp / (1ULL << (*burst_exp - 7));
+			} else {
+				*burst_mantissa = tmp * (1ULL << (7 - *burst_exp));
+			}
+		}
 	} else {
 		*burst_exp = MAX_BURST_EXPONENT;
 		*burst_mantissa = max_mantissa;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-28  8:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24 12:19 [PATCH net] net: octeontx2-pf: Fix UB in shift operation Sergey.V.Frolov
2026-07-27  3:27 ` Ratheesh Kannoth
2026-07-27 11:46   ` Sergey V. Frolov
2026-07-28  3:47     ` Ratheesh Kannoth
2026-07-28  8:13       ` Sergey V. Frolov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox