struct fib_nh->nh_dev can be NULL, so we should check it before calling
__in_dev_get_rcu on it.
Multiple places seem to want this (and check the return value), so we can
add a convenience wrapper for this.
This fixes a crash in AF_NETLINK sendmsg().
Please double check that I caught all the callers that need the NULL
guard.
Fixes: 0eeb075fad73 ("net: ipv4 sysctl option to ignore routes when nexthop link is down")
Cc: Andy Gospodarek <redacted>
Cc: Dinesh Dutt <redacted>
Cc: Scott Feldman <redacted>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Vegard Nossum <redacted>
---
include/linux/inetdevice.h | 7 +++++++
net/ipv4/fib_semantics.c | 8 ++++----
2 files changed, 11 insertions(+), 4 deletions(-)
struct fib_nh->nh_dev can be NULL, so we should check it before calling
__in_dev_get_rcu on it.
That should say __in_dev_get_rtnl(), obviously.
Multiple places seem to want this (and check the return value), so we can
add a convenience wrapper for this.
This fixes a crash in AF_NETLINK sendmsg().
Please double check that I caught all the callers that need the NULL
guard.
Fixes: 0eeb075fad73 ("net: ipv4 sysctl option to ignore routes when nexthop link is down")
Cc: Andy Gospodarek <redacted>
Cc: Dinesh Dutt <redacted>
Cc: Scott Feldman <redacted>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Vegard Nossum <redacted>
I guess we could also add:
Cc: stable@vger.kernel.org
Vegard
struct fib_nh->nh_dev can be NULL, so we should check it before calling
__in_dev_get_rcu on it.
Multiple places seem to want this (and check the return value), so we can
add a convenience wrapper for this.
This fixes a crash in AF_NETLINK sendmsg().
Please double check that I caught all the callers that need the NULL
guard.
What kind of configuration causes such crash?
quoted hunk
Fixes: 0eeb075fad73 ("net: ipv4 sysctl option to ignore routes when nexthop link is down")
Cc: Andy Gospodarek <redacted>
Cc: Dinesh Dutt <redacted>
Cc: Scott Feldman <redacted>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Vegard Nossum <redacted>
---
include/linux/inetdevice.h | 7 +++++++
net/ipv4/fib_semantics.c | 8 ++++----
2 files changed, 11 insertions(+), 4 deletions(-)
@@ -1261,7 +1261,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif)) goto nla_put_failure; if (fi->fib_nh->nh_flags & RTNH_F_LINKDOWN) {- in_dev = __in_dev_get_rtnl(fi->fib_nh->nh_dev);+ in_dev = in_dev_get_rtnl(fi->fib_nh->nh_dev);
Looks like this is the only place that can crash,
adding extra cycles to the other places is not good. And this
can happen only because fib_create_info() allows RTNH_F_LINKDOWN
to come for routes with error. May be fc_flags should be masked
there? Or there is another place that sets the flag when nh_dev
is NULL?
quoted hunk
if (in_dev &&
IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
rtm->rtm_flags |= RTNH_F_DEAD;
@@ -1292,7 +1292,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, rtnh->rtnh_flags = nh->nh_flags & 0xFF; if (nh->nh_flags & RTNH_F_LINKDOWN) {- in_dev = __in_dev_get_rtnl(nh->nh_dev);+ in_dev = in_dev_get_rtnl(nh->nh_dev);
Not needed because fib_nhs > 1
if (in_dev &&
IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
rtnh->rtnh_flags |= RTNH_F_DEAD;
--
struct fib_nh->nh_dev can be NULL, so we should check it before calling
__in_dev_get_rcu on it.
Multiple places seem to want this (and check the return value), so we can
add a convenience wrapper for this.
This fixes a crash in AF_NETLINK sendmsg().
Please double check that I caught all the callers that need the NULL
guard.
What kind of configuration causes such crash?
It's not very easy to tell, sorry, I was using a netlink fuzzer to find
the crash. But see below, you identified the right bit of code.
@@ -1261,7 +1261,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif)) goto nla_put_failure; if (fi->fib_nh->nh_flags & RTNH_F_LINKDOWN) {- in_dev = __in_dev_get_rtnl(fi->fib_nh->nh_dev);+ in_dev = in_dev_get_rtnl(fi->fib_nh->nh_dev);
Looks like this is the only place that can crash,
adding extra cycles to the other places is not good. And this
can happen only because fib_create_info() allows RTNH_F_LINKDOWN
to come for routes with error. May be fc_flags should be masked
there? Or there is another place that sets the flag when nh_dev
is NULL?
Indeed, this is the (only) place that actually crashed for me.
quoted
if (in_dev &&
IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
rtm->rtm_flags |= RTNH_F_DEAD;
@@ -1292,7 +1292,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, rtnh->rtnh_flags = nh->nh_flags & 0xFF; if (nh->nh_flags & RTNH_F_LINKDOWN) {- in_dev = __in_dev_get_rtnl(nh->nh_dev);+ in_dev = in_dev_get_rtnl(nh->nh_dev);
Not needed because fib_nhs > 1
Alright.
Thanks for the review! I can submit a new patch to only check the one
place above that actually crashed. Otherwise, if you think it's better
to go with your fc_flags suggestion, feel free to send a patch for that.
As you can tell, I am not very familiar with this code :-) If you do
send a patch, I can test it easily.
Vegard
Alright.
Thanks for the review! I can submit a new patch to only check the one
place above that actually crashed. Otherwise, if you think it's better
to go with your fc_flags suggestion, feel free to send a patch for that.
As you can tell, I am not very familiar with this code :-) If you do
send a patch, I can test it easily.
Of course, here is untested version. May be I'll do some
testing this weekend and will submit with proper commit
message...
[PATCH RFC] ipv4: reject RTNH_F_LINKDOWN for incompatible routes
The RTNH_F_LINKDOWN flag is used only for link routes.
Reject it for error routes and local routes.
Signed-off-by: Julian Anastasov <ja@ssi.bg>
---
net/ipv4/fib_semantics.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Alright.
Thanks for the review! I can submit a new patch to only check the one
place above that actually crashed. Otherwise, if you think it's better
to go with your fc_flags suggestion, feel free to send a patch for that.
As you can tell, I am not very familiar with this code :-) If you do
send a patch, I can test it easily.
Of course, here is untested version. May be I'll do some
testing this weekend and will submit with proper commit
message...
[PATCH RFC] ipv4: reject RTNH_F_LINKDOWN for incompatible routes
The RTNH_F_LINKDOWN flag is used only for link routes.
Reject it for error routes and local routes.
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Tested your patch, it fixes the problem for me. I haven't tested if it
breaks anything else :-)
Vegard
[PATCH RFC] ipv4: reject RTNH_F_LINKDOWN for incompatible routes
The RTNH_F_LINKDOWN flag is used only for link routes.
Reject it for error routes and local routes.
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Tested your patch, it fixes the problem for me. I haven't tested if it
breaks anything else :-)