Skip to contentSkip to conversation

RDMA/mlx5: Fix cntrs_max_index overflow when binding flow counters

PATCH Applied Hungyu Lin 3 participants 3 messages Nov 15 – Nov 16

Subsystems (2)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 RDMA/mlx5: Fix cntrs_max_index overflow when binding flow counters

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")
---
 drivers/infiniband/hw/mlx5/counters.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/hw/mlx5/counters.c +2 -1
index 1c25b825d0bd..742bb10adc57 100644
@@ -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

#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines

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.

Quoted 6 lines

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")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Hungyu Lin
Quoted 9 lines · Hungyu Lin

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

[...]

Applied, thanks!

[1/1] RDMA/mlx5: Fix cntrs_max_index overflow when binding flow counters

      https://git.kernel.org/rdma/rdma/c/4583abff319acf

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>