* [PATCH] RDMA/mlx5: Fix cntrs_max_index overflow when binding flow counters
@ 2026-11-15 8:50 Hungyu Lin
2026-11-15 9:00 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Hungyu Lin @ 2026-11-15 8:50 UTC (permalink / raw)
To: leon; +Cc: jgg, raeds, yishaih, linux-rdma, linux-kernel, dennylin0707
counters_set_description() stores the highest counter index supplied by
the user plus one in cntrs_max_index. Both are u32, so an index of
U32_MAX wraps cntrs_max_index to zero, and the entries after it can only
raise it to their own index plus one.
mlx5_ib_read_counters() uses cntrs_max_index to check that every bound
index fits in the output buffer before it runs
read_attr->counters_buff[desc[i].index] += ...
With the wrapped value the check passes whatever the buffer size is, and
the entry with index U32_MAX is added to memory almost 32 GiB past the
start of the buffer.
Reject an index of U32_MAX in counters_set_description(), so that
cntrs_max_index is larger than every bound index.
Fixes: 3b3233fbf02e ("IB/mlx5: Add flow counters binding support")
Cc: stable@vger.kernel.org
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
drivers/infiniband/hw/mlx5/counters.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/mlx5/counters.c b/drivers/infiniband/hw/mlx5/counters.c
index 1c25b825d0bd..742bb10adc57 100644
--- a/drivers/infiniband/hw/mlx5/counters.c
+++ b/drivers/infiniband/hw/mlx5/counters.c
@@ -1038,7 +1038,8 @@ static int counters_set_description(
mcounters->ncounters = ncounters;
/* each counter entry have both description and index pair */
for (i = 0; i < ncounters; i++) {
- if (desc_data[i].description > IB_COUNTER_BYTES)
+ if (desc_data[i].description > IB_COUNTER_BYTES ||
+ desc_data[i].index == U32_MAX)
return -EINVAL;
if (cntrs_max_index <= desc_data[i].index)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] RDMA/mlx5: Fix cntrs_max_index overflow when binding flow counters
2026-11-15 8:50 [PATCH] RDMA/mlx5: Fix cntrs_max_index overflow when binding flow counters Hungyu Lin
@ 2026-11-15 9:00 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-15 9:00 UTC (permalink / raw)
To: Hungyu Lin; +Cc: linux-rdma
> counters_set_description() stores the highest counter index supplied by
> the user plus one in cntrs_max_index. Both are u32, so an index of
> U32_MAX wraps cntrs_max_index to zero, and the entries after it can only
> raise it to their own index plus one.
>
> mlx5_ib_read_counters() uses cntrs_max_index to check that every bound
> index fits in the output buffer before it runs
>
> read_attr->counters_buff[desc[i].index] += ...
>
> With the wrapped value the check passes whatever the buffer size is, and
> the entry with index U32_MAX is added to memory almost 32 GiB past the
> start of the buffer.
>
> Reject an index of U32_MAX in counters_set_description(), so that
> cntrs_max_index is larger than every bound index.
>
> Fixes: 3b3233fbf02e ("IB/mlx5: Add flow counters binding support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261115085025.53203-1-dennylin0707@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-15 9:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 8:50 [PATCH] RDMA/mlx5: Fix cntrs_max_index overflow when binding flow counters Hungyu Lin
2026-11-15 9:00 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.