table: fix no cast overflow
PATCH 1/1 table: fix no cast overflow
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")
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(-)
lib/table/rte_table_hash_key16.c +1 -1
@@ -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",
lib/table/rte_table_hash_key32.c +1 -1
@@ -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",
lib/table/rte_table_hash_key8.c +1 -1
@@ -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 "
Signature · 1 line
2.39.5