Skip to content

Commit

Permalink
IPV6 Fix a crash when trying to replace non existing route
Browse files Browse the repository at this point in the history
This patch fixes a crash when non existing IPv6 route is tried to be changed.

When new destination node was inserted in middle of FIB6 tree, no relevant
sanity checks were performed. Later route insertion might have been prevented
due to invalid request, causing node with no rt info being left in tree.
When this node was accessed, a crash occurred.

Patch adds missing checks in fib6_add_1()

Signed-off-by: Matti Vaittinen <Mazziesaccount@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Matti Vaittinen authored and David S. Miller committed Nov 17, 2011
1 parent 8f5f698 commit 14df015
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions net/ipv6/ip6_fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,15 @@ static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr,
*/
if (plen < fn->fn_bit ||
!ipv6_prefix_equal(&key->addr, addr, fn->fn_bit)) {
if (!allow_create)
if (!allow_create) {
if (replace_required) {
printk(KERN_WARNING
"IPv6: Can't replace route, no match found\n");
return ERR_PTR(-ENOENT);
}
printk(KERN_WARNING
"IPv6: NLM_F_CREATE should be set when creating new route\n");
}
goto insert_above;
}

Expand Down Expand Up @@ -482,7 +488,7 @@ static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr,
fn = dir ? fn->right: fn->left;
} while (fn);

if (replace_required && !allow_create) {
if (!allow_create) {
/* We should not create new node because
* NLM_F_REPLACE was specified without NLM_F_CREATE
* I assume it is safe to require NLM_F_CREATE when
Expand All @@ -492,16 +498,17 @@ static struct fib6_node * fib6_add_1(struct fib6_node *root, void *addr,
* MUST be specified if new route is created.
* That would keep IPv6 consistent with IPv4
*/
printk(KERN_WARNING
"IPv6: NLM_F_CREATE should be set when creating new route - ignoring request\n");
return ERR_PTR(-ENOENT);
if (replace_required) {
printk(KERN_WARNING
"IPv6: Can't replace route, no match found\n");
return ERR_PTR(-ENOENT);
}
printk(KERN_WARNING "IPv6: NLM_F_CREATE should be set when creating new route\n");
}
/*
* We walked to the bottom of tree.
* Create new leaf node without children.
*/
if (!allow_create)
printk(KERN_WARNING "IPv6: NLM_F_CREATE should be set when creating new route\n");

ln = node_alloc();

Expand Down

0 comments on commit 14df015

Please sign in to comment.