ipv6: check for ip6_null_entry in __ip6_del_rt_siblings()
Subsystems (3)
PATCH 1/1 ipv6: check for ip6_null_entry in __ip6_del_rt_siblings()
Andrey reported a NULL pointer deref bug in ipv6_route_ioctl() -> ip6_route_del() -> __ip6_del_rt_siblings() code path. This is because ip6_null_entry is returned in this path since ip6_null_entry is kinda default for a ipv6 route table root node. Quote from David Ahern:
ip6_null_entry is the root of all ipv6 fib tables making it integrated into the table ...
We should ignore any attempt of trying to delete it, like we do in __ip6_del_rt() path and several others.
--- net/ipv6/route.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/ipv6/route.c +5 -2
@@ -2169,10 +2169,13 @@ int ip6_del_rt(struct rt6_info *rt)static int __ip6_del_rt_siblings (struct rt6_info *rt,struct fib6_config *cfg) {struct nl_info *info = &cfg->fc_nlinfo; +struct net *net = info->nl_net;struct sk_buff *skb =NULL ;struct fib6_table *table;int err; +if (rt == net->ipv6.ip6_null_entry) +return -ENOENT ; table = rt->rt6i_table;write_lock_bh (&table->tb6_lock);
@@ -2184,7 +2187,7 @@ static int __ip6_del_rt_siblings(struct rt6_info *rt, struct fib6_config *cfg)if (skb) {u32 seq = info->nlh ? info->nlh->nlmsg_seq :0 ; -if (rt6_fill_node (info->nl_net, skb, rt, +if (rt6_fill_node (net, skb, rt,NULL ,NULL ,0 ,RTM_DELROUTE , info->portid, seq,0 ) <0 ) {kfree_skb (skb);
@@ -2208,7 +2211,7 @@ static int __ip6_del_rt_siblings(struct rt6_info *rt, struct fib6_config *cfg)ip6_rt_put (rt);if (skb) { -rtnl_notify (skb, info->nl_net, info->portid,RTNLGRP_IPV6_ROUTE , +rtnl_notify (skb, net, info->portid,RTNLGRP_IPV6_ROUTE , info->nlh,gfp_any ()); }return err;
Signature · 1 line
2.5.5
Quoted 23 lines · Cong Wang
Andrey reported a NULL pointer deref bug in
ipv6_route_ioctl()->ip6_route_del()->__ip6_del_rt_siblings()code path. This is becauseip6_null_entryis returned in this path sinceip6_null_entryis kinda default for a ipv6 route table root node. Quote from David Ahern:
ip6_null_entryis the root of all ipv6 fib tables making it integrated into the table ...We should ignore any attempt of trying to delete it, like we do in
__ip6_del_rt()path and several others.Reported-by Andrey Konovalov <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/ipv6/route.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)net/ipv6/route.c +0
-0
net/ipv6/route.c int ip6_del_rt(struct rt6_info *rt) · line 2178
Quoted 10 lines
net/ipv6/route.c +3
-0@@ -2169,10 +2169,13 @@ int ip6_del_rt(struct rt6_info *rt)static int __ip6_del_rt_siblings (struct rt6_info *rt,struct fib6_config *cfg) {struct nl_info *info = &cfg->fc_nlinfo; +struct net *net = info->nl_net;struct sk_buff *skb =NULL ;struct fib6_table *table;int err; +if (rt == net->ipv6.ip6_null_entry) +return -ENOENT ;
It looks the caller did a dst_hold(&rt->dst);
So this new error path would leave a refcount leak.
Note that I was not able to trigger the crash on old kernels, so it would be nice to get a precise idea of bug origin.
Thanks.
Quoted 32 lines · Eric Dumazet
Quoted 31 lines · Cong Wang
Andrey reported a NULL pointer deref bug in
ipv6_route_ioctl()->ip6_route_del()->__ip6_del_rt_siblings()code path. This is becauseip6_null_entryis returned in this path sinceip6_null_entryis kinda default for a ipv6 route table root node. Quote from David Ahern:
ip6_null_entryis the root of all ipv6 fib tables making it integrated into the table ...We should ignore any attempt of trying to delete it, like we do in
__ip6_del_rt()path and several others.Reported-by Andrey Konovalov <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/ipv6/route.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)net/ipv6/route.c +1
-0@@ -2169,10 +2169,13 @@ int ip6_del_rt(struct rt6_info *rt)static int __ip6_del_rt_siblings (struct rt6_info *rt,struct fib6_config *cfg) {struct nl_info *info = &cfg->fc_nlinfo; +struct net *net = info->nl_net;struct sk_buff *skb =NULL ;struct fib6_table *table;int err;
Quoted 6 lines
net/ipv6/route.c int ip6_del_rt(struct rt6_info *rt) · line 2178
Quoted 2 lines
net/ipv6/route.c +2
-0+if (rt == net->ipv6.ip6_null_entry) +return -ENOENT ;It looks the caller did a
dst_hold(&rt->dst);So this new error path would leave a refcount leak.
Interesting, this error path is not new for __ip6_del_rt_siblings() so the leak was already there before mine, but you are probably right we have a leak here.
I will send a separate patch to address this leak.
Quoted 3 lines
Note that I was not able to trigger the crash on old kernels, so it would be nice to get a precise idea of bug origin.
Right, I miss:
nexthops in multipath route")
Thanks!
Quoted 37 lines · Eric Dumazet
Quoted 23 lines · Cong Wang
Andrey reported a NULL pointer deref bug in
ipv6_route_ioctl()->ip6_route_del()->__ip6_del_rt_siblings()code path. This is becauseip6_null_entryis returned in this path sinceip6_null_entryis kinda default for a ipv6 route table root node. Quote from David Ahern:
ip6_null_entryis the root of all ipv6 fib tables making it integrated into the table ...We should ignore any attempt of trying to delete it, like we do in
__ip6_del_rt()path and several others.Reported-by Andrey Konovalov <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/ipv6/route.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)net/ipv6/route.c +0
-0net/ipv6/route.c int ip6_del_rt(struct rt6_info *rt) · line 2178
Quoted 10 lines
net/ipv6/route.c +3
-0@@ -2169,10 +2169,13 @@ int ip6_del_rt(struct rt6_info *rt)static int __ip6_del_rt_siblings (struct rt6_info *rt,struct fib6_config *cfg) {struct nl_info *info = &cfg->fc_nlinfo; +struct net *net = info->nl_net;struct sk_buff *skb =NULL ;struct fib6_table *table;int err; +if (rt == net->ipv6.ip6_null_entry) +return -ENOENT ;It looks the caller did a
dst_hold(&rt->dst);
Quoted 5 lines
So this new error path would leave a refcount leak.
Note that I was not able to trigger the crash on old kernels, so it would be nice to get a precise idea of bug origin.
Cong: do you want to send a v2 catching the null entry in ip6_route_del before the refcnt?
for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {+ /* do not allow deletion of the null route */
+ if (rt == net->ipv6.ip6_null_entry)
+ continue;
multipath route
Quoted 38 lines · David Ahern
Quoted 37 lines · Eric Dumazet
Quoted 23 lines · Cong Wang
Andrey reported a NULL pointer deref bug in
ipv6_route_ioctl()->ip6_route_del()->__ip6_del_rt_siblings()code path. This is becauseip6_null_entryis returned in this path sinceip6_null_entryis kinda default for a ipv6 route table root node. Quote from David Ahern:
ip6_null_entryis the root of all ipv6 fib tables making it integrated into the table ...We should ignore any attempt of trying to delete it, like we do in
__ip6_del_rt()path and several others.Reported-by Andrey Konovalov <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/ipv6/route.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)net/ipv6/route.c +0
-0net/ipv6/route.c int ip6_del_rt(struct rt6_info *rt) · line 2178
Quoted 10 lines
net/ipv6/route.c +3
-0@@ -2169,10 +2169,13 @@ int ip6_del_rt(struct rt6_info *rt)static int __ip6_del_rt_siblings (struct rt6_info *rt,struct fib6_config *cfg) {struct nl_info *info = &cfg->fc_nlinfo; +struct net *net = info->nl_net;struct sk_buff *skb =NULL ;struct fib6_table *table;int err; +if (rt == net->ipv6.ip6_null_entry) +return -ENOENT ;It looks the caller did a
dst_hold(&rt->dst);
Quoted 8 lines
Quoted 5 lines
So this new error path would leave a refcount leak.
Note that I was not able to trigger the crash on old kernels, so it would be nice to get a precise idea of bug origin.
Cong: do you want to send a v2 catching the null entry in
ip6_route_delbefore the refcnt?
Yeah, actually it is introduced by my patch because there is already an ip6_rt_put() in __ip6_del_rt_siblings(). So v2 is coming...
Quoted 8 lines
for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {(quoted diff) +3
-0+ /* do not allow deletion of the null route */ + if (rt == net->ipv6.ip6_null_entry) + continue;Fixes 0ae8133586ad net: ipv6: Allow shorthand delete of all nexthops inmultipath route
Note, I moved the check into __ip6_del_rt_siblings() because __ip6_del_rt() has a same check.
Quoted 6 lines · Cong Wang
Quoted 6 lines
for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {(quoted diff) +3
-0+ /* do not allow deletion of the null route */ + if (rt == net->ipv6.ip6_null_entry) + continue;
Quoted 6 lines
Quoted 2 lines
Fixes 0ae8133586ad net: ipv6: Allow shorthand delete of all nexthops inmultipath route
Note, I moved the check into
__ip6_del_rt_siblings()because__ip6_del_rt()has a same check.
that's b/c __ip6_del_rt has a second call path. __ip6_del_rt_siblings is new and is not expecting to see the null entry. Catching it before the dst_hold would be better.
Quoted 10 lines · David Ahern
Quoted 9 lines · Cong Wang
Quoted 8 lines
for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {(quoted diff) +3
-0+ /* do not allow deletion of the null route */ + if (rt == net->ipv6.ip6_null_entry) + continue;Fixes 0ae8133586ad net: ipv6: Allow shorthand delete of all nexthops inmultipath route
Quoted 7 lines
Quoted 3 lines
Note, I moved the check into
__ip6_del_rt_siblings()because__ip6_del_rt()has a same check.that's b/c
__ip6_del_rthas a second call path.__ip6_del_rt_siblingsis new and is not expecting to see the null entry. Catching it before thedst_holdwould be better.
Yeah, but it also depends on if we want to continue after the null entry, at least __ip6_del_rt () returns an error for null entry, which looks more correct than continuing to proceed after it.