fib_trie: Fix regression in handling of inflate/halve failure
authorAlexander Duyck <alexander.h.duyck@redhat.com>
Mon, 23 Mar 2015 18:51:53 +0000 (11:51 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 23 Mar 2015 20:58:32 +0000 (16:58 -0400)
When I updated the code to address a possible null pointer dereference in
resize I ended up reverting an exception handling fix for the suffix length
in the event that inflate or halve failed.  This change is meant to correct
that by reverting the earlier fix and instead simply getting the parent
again after inflate has been completed to avoid the possible null pointer
issue.

Fixes: ddb4b9a13 ("fib_trie: Address possible NULL pointer dereference in resize")
Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/fib_trie.c

index e3b4aee4244e1702b9ad34ffc788a5268447e8e5..2c7c299ee2b923e8a7d5394f49868d305dd5df74 100644 (file)
@@ -830,7 +830,7 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn)
        /* Double as long as the resulting node has a number of
         * nonempty nodes that are above the threshold.
         */
-       while (should_inflate(tp, tn) && max_work--) {
+       while (should_inflate(tp, tn) && max_work) {
                tp = inflate(t, tn);
                if (!tp) {
 #ifdef CONFIG_IP_FIB_TRIE_STATS
@@ -839,17 +839,21 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn)
                        break;
                }
 
+               max_work--;
                tn = get_child(tp, cindex);
        }
 
+       /* update parent in case inflate failed */
+       tp = node_parent(tn);
+
        /* Return if at least one inflate is run */
        if (max_work != MAX_WORK)
-               return node_parent(tn);
+               return tp;
 
        /* Halve as long as the number of empty children in this
         * node is above threshold.
         */
-       while (should_halve(tp, tn) && max_work--) {
+       while (should_halve(tp, tn) && max_work) {
                tp = halve(t, tn);
                if (!tp) {
 #ifdef CONFIG_IP_FIB_TRIE_STATS
@@ -858,6 +862,7 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn)
                        break;
                }
 
+               max_work--;
                tn = get_child(tp, cindex);
        }
 
@@ -865,7 +870,7 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn)
        if (should_collapse(tn))
                return collapse(t, tn);
 
-       /* update parent in case inflate or halve failed */
+       /* update parent in case halve failed */
        tp = node_parent(tn);
 
        /* Return if at least one deflate was run */
This page took 0.026487 seconds and 5 git commands to generate.