From: Mark Bulatov <[email protected]>
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: [email protected]
Signed-off-by: Mark Bulatov <[email protected]>
---
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