lpm6: fix use after free
authorChristian Ehrhardt <christian.ehrhardt@canonical.com>
Mon, 21 Mar 2016 14:06:11 +0000 (15:06 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 22 Mar 2016 16:55:16 +0000 (17:55 +0100)
In certain autotests lpm->max_rules turned out to be non initialized.
That was caused by a failing allocation for lpm->rules_tbl in rte_lpm6_create.
It then left the function via goto exit with lpm freed, but still a pointer
value being set.

In case of an allocation failure it resets lpm to NULL now, to avoid the
upper layers operate on that already freed memory.
Along that is also makes the RTE_LOG message of the failed allocation unique.

Fixes: 5c510e13a9cb ("lpm: add IPv6 support")

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
lib/librte_lpm/rte_lpm6.c

index eded772..4c44cd7 100644 (file)
@@ -206,8 +206,9 @@ rte_lpm6_create(const char *name, int socket_id,
                        (size_t)rules_size, RTE_CACHE_LINE_SIZE, socket_id);
 
        if (lpm->rules_tbl == NULL) {
-               RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
+               RTE_LOG(ERR, LPM, "LPM rules_tbl allocation failed\n");
                rte_free(lpm);
+               lpm = NULL;
                rte_free(te);
                goto exit;
        }