Skip to content

Commit 43b27d1

Browse files
gal-pressmanPaolo Abeni
authored andcommitted
net/mlx5e: Fix wraparound in rate limiting for values above 255 Gbps
Add validation to reject rates exceeding 255 Gbps that would overflow the 8 bits max bandwidth field. Fixes: d888079 ("net/mlx5e: Implement DCBNL IEEE max rate") Signed-off-by: Gal Pressman <gal@nvidia.com> Reviewed-by: Nimrod Oren <noren@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/1762681073-1084058-5-git-send-email-tariqt@nvidia.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent a7bf4d5 commit 43b27d1

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,13 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
596596
u8 max_bw_value[IEEE_8021QAZ_MAX_TCS];
597597
u8 max_bw_unit[IEEE_8021QAZ_MAX_TCS];
598598
__u64 upper_limit_mbps;
599+
__u64 upper_limit_gbps;
599600
int i;
600601

601602
memset(max_bw_value, 0, sizeof(max_bw_value));
602603
memset(max_bw_unit, 0, sizeof(max_bw_unit));
603604
upper_limit_mbps = 255 * MLX5E_100MB;
605+
upper_limit_gbps = 255 * MLX5E_1GB;
604606

605607
for (i = 0; i <= mlx5_max_tc(mdev); i++) {
606608
if (!maxrate->tc_maxrate[i]) {
@@ -612,10 +614,16 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
612614
MLX5E_100MB);
613615
max_bw_value[i] = max_bw_value[i] ? max_bw_value[i] : 1;
614616
max_bw_unit[i] = MLX5_100_MBPS_UNIT;
615-
} else {
617+
} else if (max_bw_value[i] <= upper_limit_gbps) {
616618
max_bw_value[i] = div_u64(maxrate->tc_maxrate[i],
617619
MLX5E_1GB);
618620
max_bw_unit[i] = MLX5_GBPS_UNIT;
621+
} else {
622+
netdev_err(netdev,
623+
"tc_%d maxrate %llu Kbps exceeds limit %llu\n",
624+
i, maxrate->tc_maxrate[i],
625+
upper_limit_gbps);
626+
return -EINVAL;
619627
}
620628
}
621629

0 commit comments

Comments
 (0)