Skip to contentSkip to conversation

ip_route_input panic fix

PATCH In review Stephen Hemminger 4 participants 12 messages Apr 18, 2006 – Apr 19, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip_route_input panic fix

This fixes http://bugzilla.kernel.org/show_bug.cgi?id=6388
The bug is caused by ip_route_input dereferencing skb->nh.protocol of the dummy skb passed dow from inet_rtm_getroute (Thanks Thomas for seeing it). It only happens if the route requested is for a multicast IP address.

net/ipv4/route.c +4 -1
@@ -2750,7 +2750,10 @@ int inet_rtm_getroute(struct sk_buff *in
 	/* Reserve room for dummy headers, this skb can pass
 	   through good chunk of routing engine.
 	 */
-	skb->mac.raw = skb->data;
+	skb->mac.raw = skb->nh.raw = skb->data;
+
+	/* Bugfix: need to give ip_route_input enough of an IP header to not gag. */
+	skb->nh.iph->protocol = IPPROTO_ICMP;
 	skb_reserve(skb, MAX_HEADER + sizeof(struct iphdr));
 
 	if (rta[RTA_SRC - 1])
#1 lore raw

Hi Stephen:

Quoted 5 lines · Stephen Hemminger

This fixes http://bugzilla.kernel.org/show_bug.cgi?id=6388
The bug is caused by ip_route_input dereferencing skb->nh.protocol of the dummy skb passed dow from inet_rtm_getroute (Thanks Thomas for seeing it). It only happens if the route requested is for a multicast IP address.

Good catch.

net/ipv4/route.c int inet_rtm_getroute(struct sk_buff *in · line 2753

Quoted 2 lines
net/ipv4/route.c +1 -1
-       skb->mac.raw = skb->data;
+       skb->mac.raw = skb->nh.raw = skb->data;

This should fix it.

net/ipv4/route.c int inet_rtm_getroute(struct sk_buff *in · line 2756

Quoted 2 lines
net/ipv4/route.c +2 -0
+       /* Bugfix: need to give ip_route_input enough of an IP header to not gag. */
+       skb->nh.iph->protocol = IPPROTO_ICMP;

Do we really need this? After all we can get completely bogus values coming in through the network too.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw
Quoted 14 lines · On Tue, 18 Apr 2006 12:28:48 +1000 Herbert Xu <[email protected]>…

Hi Stephen:

Quoted 5 lines · Stephen Hemminger

This fixes http://bugzilla.kernel.org/show_bug.cgi?id=6388
The bug is caused by ip_route_input dereferencing skb->nh.protocol of the dummy skb passed dow from inet_rtm_getroute (Thanks Thomas for seeing it). It only happens if the route requested is for a multicast IP address.

Good catch.

net/ipv4/route.c int inet_rtm_getroute(struct sk_buff *in · line 2753

Quoted 2 lines
net/ipv4/route.c +1 -1
-       skb->mac.raw = skb->data;
+       skb->mac.raw = skb->nh.raw = skb->data;
Quoted 7 lines

This should fix it.

net/ipv4/route.c int inet_rtm_getroute(struct sk_buff *in · line 2756

Quoted 2 lines
net/ipv4/route.c +2 -0
+       /* Bugfix: need to give ip_route_input enough of an IP header to not gag. */
+       skb->nh.iph->protocol = IPPROTO_ICMP;

Do we really need this? After all we can get completely bogus values coming in through the network too.

Not really, just that ip_check_mc looks at the proto for !IGMP. And maybe some tool like coverity or sparse would be smart enough to look for uninitialized data usage.

#3 lore raw
Quoted 4 lines · Stephen Hemminger

Not really, just that ip_check_mc looks at the proto for !IGMP. And maybe some tool like coverity or sparse would be smart enough to look for uninitialized data usage.

That's a good point.

Thanks Stephen,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#4 lore raw
In reply to Herbert Xu

From: Herbert Xu <[email protected]>
Date: Tue, 18 Apr 2006 12:28:48 +1000

Quoted 6 lines

net/ipv4/route.c int inet_rtm_getroute(struct sk_buff *in · line 2756

Quoted 2 lines · Stephen Hemminger
net/ipv4/route.c +2 -0
+       /* Bugfix: need to give ip_route_input enough of an IP header to not gag. */
+       skb->nh.iph->protocol = IPPROTO_ICMP;

Do we really need this? After all we can get completely bogus values coming in through the network too.

ip_mc_check() will return 1 if it happens to be IGMP, that's not a good default for this netlink lookup case.

#5 lore raw
In reply to Stephen Hemminger

net/ipv4/route.c int inet_rtm_getroute(struct sk_buff *in · line 2756

Quoted 12 lines · Stephen Hemminger
net/ipv4/route.c +4 -1
@@ -2750,7 +2750,10 @@ int inet_rtm_getroute(struct sk_buff *in
       /* Reserve room for dummy headers, this skb can pass
          through good chunk of routing engine.
        */
-       skb->mac.raw = skb->data;
+       skb->mac.raw = skb->nh.raw = skb->data;
+
+       /* Bugfix: need to give ip_route_input enough of an IP header to not gag. */
+       skb->nh.iph->protocol = IPPROTO_ICMP;

Looking at this again, the root of this problem is the IGMPv3 patch which started using the skb->nh.iph->protocol as a key.

So what we really should do is make the protocol an explicit parameter to the ip_route_input function. This will make it clear to all the users which include some pretty weird cases that the protocol is needed.

In fact I'm unsure as to whether all the other users of ip_route_input is safe as it is regarding the protocol.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#6 lore raw

From: Herbert Xu <[email protected]>
Date: Tue, 18 Apr 2006 16:54:48 +1000

Quoted 9 lines

Looking at this again, the root of this problem is the IGMPv3 patch which started using the skb->nh.iph->protocol as a key.

So what we really should do is make the protocol an explicit parameter to the ip_route_input function. This will make it clear to all the users which include some pretty weird cases that the protocol is needed.

In fact I'm unsure as to whether all the other users of ip_route_input is safe as it is regarding the protocol.

There are other areas of the packet which are interpreted in various ways. For example, the martian source handling will dump the MAC directly from skb->mac.raw into the kernel logs.

The output path is so much cleaner, because things like the protocol are filled out in the struct flowi so there is no need to be parsing the SKB in any way.

#7 lore raw
Quoted 4 lines · David S. Miller

There are other areas of the packet which are interpreted in various ways. For example, the martian source handling will dump the MAC directly from skb->mac.raw into the kernel logs.

That's scary. I think this stuff needs an audit.

Quoted 3 lines

The output path is so much cleaner, because things like the protocol are filled out in the struct flowi so there is no need to be parsing the SKB in any way.

Absolutely. I think we should put Stephen's patch in ASAP. Once the immediate problem is gone we can take our time and make the input path more like the output.

At the end of this I'd like to see the skb argument from ip_route_input replaced by a dst_entry.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#8 lore raw
In reply to Herbert Xu

Hello!

Quoted 2 lines

Looking at this again, the root of this problem is the IGMPv3 patch which started using the skb->nh.iph->protocol as a key.

No, root is that this fake skb was not properly initialized. It should, it should be a good real IP skb.

Quoted 2 lines

In fact I'm unsure as to whether all the other users of ip_route_input is safe as it is regarding the protocol.

ip_route_input takes skb as an argument exactly because it needs nothing but skb and there is always an skb, when we "input". ip_route_output would be happy to take an skb as well,
but unfortuntely it happens before we have an skb.

I do not see anything scary here: agree, when skb->nh happens to be undefined, such skb would crash almost any place in IP stack. :-)

Actually, this weird case in inet_get_route() is the only place, where a dummy skb is used and it is needed mostly to resolve multicast routes. In this case this fake skb really passes through all the engine, even delivered to user space in some sense, and when the route is resolved, the same skb is submitted to netlink socket. I remember, Dave found something very bad about this and this even deserved a place in TODO list, but franky speaking I did not understand what is so wrong with this trick.

Alexey

#9 lore raw
Quoted 2 lines · Alexey Kuznetsov

Actually, this weird case in inet_get_route() is the only place, where

There is also the ARP code which passes an ARP packet through that would get dereferenced as an IP packet. Granted this shouldn't crash because nh is set properly.

But we really should make up our mind as to whether the routing key comes from the arguments to ip_route_input (src/dst/...) or the skb.

Using both is just asking for trouble.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#10 lore raw
In reply to Alexey Kuznetsov

From: Alexey Kuznetsov <[email protected]>
Date: Wed, 19 Apr 2006 03:52:22 +0400

Quoted 7 lines

Actually, this weird case in inet_get_route() is the only place, where a dummy skb is used and it is needed mostly to resolve multicast routes. In this case this fake skb really passes through all the engine, even delivered to user space in some sense, and when the route is resolved, the same skb is submitted to netlink socket. I remember, Dave found something very bad about this and this even deserved a place in TODO list, but franky speaking I did not understand what is so wrong with this trick.

Problem there is via rt_fill_info(). When multicast route cannot be found by ipmr, it tries to use this netlink SKB to send out a probe.

ipmr_get_route() is the trouble maker. If ipmr_cache_find() cannot find an entry, it tries to use the netlink SKB to send out an ipv4 packet, completely mangling it, via ipmr_cache_unresolved().

Even worse it may even free the skb on us, or queue it to mroute_socket.

It is pure disaster, this entire code path.

#11 lore raw

Hello!

Quoted 3 lines

ipmr_get_route() is the trouble maker. If ipmr_cache_find() cannot find an entry, it tries to use the netlink SKB to send out an ipv4 packet, completely mangling it, via ipmr_cache_unresolved().

It just adds dummy IP header to tail of this skb. Nothing illegal. The skb is not sent out, it is enqueued in an ARP-like queue and the IP header is submitted to mroute_socket.

When user level mrouter resolves the route, ipmr_cache_resolve() removes this, completes filling netlink attributes and sends it to netlink.

Quoted 1 line

Even worse it may even free the skb on us,

Oops, seems, this is a real bug... Need to think how to fix.

Quoted 1 line

or queue it to mroute_socket.

It is OK, it is the purpose.

Quoted 1 line

It is pure disaster, this entire code path.

Well, it may be buggy, but esentially there is nothing to simplify. At least, I do not see.

Alexey