DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 25.11] table: fix no cast overflow
@ 2026-11-13 14:34 Bulatov Mark
  0 siblings, 0 replies; only message in thread
From: Bulatov Mark @ 2026-11-13 14:34 UTC (permalink / raw)
  To: Cristian Dumitrescu; +Cc: dev, stable, Mark Bulatov

From: Mark Bulatov <ms.bulatov7@gmail.com>

The sum p->n_buckets + n_buckets_ext fits within the bounds of a uint32_t.
However, multiplying this result by bucket_size causes an overflow.

Fix this by using type casting.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: fc972a1305 ("table: rework 16-byte key hash tables")
Fixes: ea31510376 ("table: rework 32-byte key hash tables")
Fixes: 36842d0aee ("table: rework 8-byte key hash tables")
Cc: stable@dpdk.org

Signed-off-by: Mark Bulatov <ms.bulatov7@gmail.com>
---
 lib/table/rte_table_hash_key16.c | 2 +-
 lib/table/rte_table_hash_key32.c | 2 +-
 lib/table/rte_table_hash_key8.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/table/rte_table_hash_key16.c b/lib/table/rte_table_hash_key16.c
index 5b69106dd7..99ccf3f549 100644
--- a/lib/table/rte_table_hash_key16.c
+++ b/lib/table/rte_table_hash_key16.c
@@ -394,7 +394,7 @@ rte_table_hash_create_key16_ext(void *params,
 		KEYS_PER_BUCKET * entry_size);
 	stack_size = RTE_CACHE_LINE_ROUNDUP(n_buckets_ext * sizeof(uint32_t));
 	total_size = sizeof(struct rte_table_hash) +
-		(p->n_buckets + n_buckets_ext) * bucket_size + stack_size;
+		(uint64_t)(p->n_buckets + n_buckets_ext) * bucket_size + stack_size;
 	if (total_size > SIZE_MAX) {
 		TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes "
 			"for hash table %s",
diff --git a/lib/table/rte_table_hash_key32.c b/lib/table/rte_table_hash_key32.c
index 0963f57828..1b359bbeb8 100644
--- a/lib/table/rte_table_hash_key32.c
+++ b/lib/table/rte_table_hash_key32.c
@@ -403,7 +403,7 @@ rte_table_hash_create_key32_ext(void *params,
 		KEYS_PER_BUCKET * entry_size);
 	stack_size = RTE_CACHE_LINE_ROUNDUP(n_buckets_ext * sizeof(uint32_t));
 	total_size = sizeof(struct rte_table_hash) +
-		(p->n_buckets + n_buckets_ext) * bucket_size + stack_size;
+		(uint64_t)(p->n_buckets + n_buckets_ext) * bucket_size + stack_size;
 	if (total_size > SIZE_MAX) {
 		TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes "
 			"for hash table %s",
diff --git a/lib/table/rte_table_hash_key8.c b/lib/table/rte_table_hash_key8.c
index 5e9dcf10ee..8fd80edafc 100644
--- a/lib/table/rte_table_hash_key8.c
+++ b/lib/table/rte_table_hash_key8.c
@@ -379,7 +379,7 @@ rte_table_hash_create_key8_ext(void *params, int socket_id, uint32_t entry_size)
 		KEYS_PER_BUCKET * entry_size);
 	stack_size = RTE_CACHE_LINE_ROUNDUP(n_buckets_ext * sizeof(uint32_t));
 	total_size = sizeof(struct rte_table_hash) +
-		(p->n_buckets + n_buckets_ext) * bucket_size + stack_size;
+		(uint64_t)(p->n_buckets + n_buckets_ext) * bucket_size + stack_size;
 
 	if (total_size > SIZE_MAX) {
 		TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes "
-- 
2.39.5


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-13 16:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 14:34 [PATCH 25.11] table: fix no cast overflow Bulatov Mark

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