Skip to content

Commit ddb4b9a

Browse files
Alexander Duyckdavem330
authored andcommitted
fib_trie: Address possible NULL pointer dereference in resize
If the inflate call failed it would return NULL. As a result tp would be set to NULL and cause use to trigger a NULL pointer dereference in should_halve if the inflate failed on the first attempt. In order to prevent this we should decrement max_work before we actually attempt to inflate as this will force us to exit before attempting to halve a node we should have inflated. In order to keep things symmetric between inflate and halve I went ahead and also moved the decrement of max_work for the halve case as well so we take care of that before we actually attempt to halve the tnode. Fixes: 88bae71 ("fib_trie: Add key vector to root, return parent key_vector in resize") Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Alexander Duyck <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 416377e commit ddb4b9a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

net/ipv4/fib_trie.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn)
830830
/* Double as long as the resulting node has a number of
831831
* nonempty nodes that are above the threshold.
832832
*/
833-
while (should_inflate(tp, tn) && max_work) {
833+
while (should_inflate(tp, tn) && max_work--) {
834834
tp = inflate(t, tn);
835835
if (!tp) {
836836
#ifdef CONFIG_IP_FIB_TRIE_STATS
@@ -839,7 +839,6 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn)
839839
break;
840840
}
841841

842-
max_work--;
843842
tn = get_child(tp, cindex);
844843
}
845844

@@ -850,7 +849,7 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn)
850849
/* Halve as long as the number of empty children in this
851850
* node is above threshold.
852851
*/
853-
while (should_halve(tp, tn) && max_work) {
852+
while (should_halve(tp, tn) && max_work--) {
854853
tp = halve(t, tn);
855854
if (!tp) {
856855
#ifdef CONFIG_IP_FIB_TRIE_STATS
@@ -859,7 +858,6 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn)
859858
break;
860859
}
861860

862-
max_work--;
863861
tn = get_child(tp, cindex);
864862
}
865863

0 commit comments

Comments
 (0)