table: fix crash during key overload
authorMiroslaw Walukiewicz <miroslaw.walukiewicz@intel.com>
Tue, 3 Mar 2015 14:16:00 +0000 (09:16 -0500)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Thu, 26 Mar 2015 21:33:41 +0000 (22:33 +0100)
hash_key8_ext, hash_key16_ext and hash_key32_ext tables allocate cache
entries to support table overload cases. The crash can occur when cache
entry is free after use.
The problem is with computing the index of the free cache entry.

Signed-off-by: Mirek Walukiewicz <miroslaw.walukiewicz@intel.com>
Signed-off-by: Maciej Gajdzica <maciejx.t.gajdzica@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
lib/librte_table/rte_table_hash_key16.c
lib/librte_table/rte_table_hash_key32.c
lib/librte_table/rte_table_hash_key8.c

index ee5f639..f87ea0e 100644 (file)
@@ -535,9 +535,8 @@ rte_table_hash_entry_delete_key16_ext(
 
                                        memset(bucket, 0,
                                                sizeof(struct rte_bucket_4_16));
-                                       bucket_index = (bucket -
-                                               ((struct rte_bucket_4_16 *)
-                                               f->memory)) - f->n_buckets;
+                                       bucket_index = (((uint8_t *)bucket -
+                                               (uint8_t *)f->memory)/f->bucket_size) - f->n_buckets;
                                        f->stack[f->stack_pos++] = bucket_index;
                                }
 
index da0ce6a..6790594 100644 (file)
@@ -540,9 +540,8 @@ rte_table_hash_entry_delete_key32_ext(
 
                                        memset(bucket, 0,
                                                sizeof(struct rte_bucket_4_32));
-                                       bucket_index = (bucket -
-                                               ((struct rte_bucket_4_32 *)
-                                               f->memory)) - f->n_buckets;
+                                       bucket_index = (((uint8_t *)bucket -
+                                               (uint8_t *)f->memory)/f->bucket_size) - f->n_buckets;
                                        f->stack[f->stack_pos++] = bucket_index;
                                }
 
index 443ca7d..6803eb2 100644 (file)
@@ -528,9 +528,8 @@ rte_table_hash_entry_delete_key8_ext(
 
                                        memset(bucket, 0,
                                                sizeof(struct rte_bucket_4_8));
-                                       bucket_index = (bucket -
-                                               ((struct rte_bucket_4_8 *)
-                                               f->memory)) - f->n_buckets;
+                                       bucket_index = (((uint8_t *)bucket -
+                                               (uint8_t *)f->memory)/f->bucket_size) - f->n_buckets;
                                        f->stack[f->stack_pos++] = bucket_index;
                                }