Skip to contentSkip to conversation

net/mlx5: fix heap-buffer-overflow in sample group match

PATCH In review Shani Peretz 2 participants 2 messages Mar 15 – Mar 24 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5: fix heap-buffer-overflow in sample group match

The cached group match callback compares serialized actions using memcmp with the size of the new actions buffer. When the new actions serialize to a larger buffer than an existing cached entry, memcmp reads past the cached entry's heap allocation, causing a heap-buffer-overflow detected by AddressSanitizer.

Add a size comparison before the memcmp so that entries with different serialized sizes are rejected as non-matching immediately, avoiding the out-of-bounds read.

Fixes d986f04d6529 ("net/mlx5: add functions for non-template flow sample")
---
 drivers/net/mlx5/mlx5_nta_sample.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/mlx5/mlx5_nta_sample.c +2 -0
index c637b0ede3..158720fb87 100644
@@ -293,6 +293,8 @@ mlx5_nta_sample_cached_group_match(void *cache_ctx __rte_unused,
 		container_of(entry, struct mlx5_nta_sample_cached_group, entry);
 	if (actions_size < 0)
 		return ~0;
+	if ((size_t)actions_size != cached_obj->actions_size)
+		return ~0;
 	return memcmp(cached_obj->actions, obj_ctx->actions, actions_size);
 }
 
Signature · 1 line
2.34.1
#1 lore raw

Hi,

Quoted 10 lines · Shani Peretz

The cached group match callback compares serialized actions using memcmp with the size of the new actions buffer. When the new actions serialize to a larger buffer than an existing cached entry, memcmp reads past the cached entry's heap allocation, causing a heap-buffer-overflow detected by AddressSanitizer.

Add a size comparison before the memcmp so that entries with different serialized sizes are rejected as non-matching immediately, avoiding the out-of-bounds read.

Quoted 5 lines
Fixes d986f04d6529 ("net/mlx5: add functions for non-template flow sample")

Patch applied to next-net-mlx,

Kindest regards
Raslan Darawsheh