Commit c55e2f49 authored by Al Viro's avatar Al Viro Committed by David S. Miller

[IPV4]: ipip and ip_gre encapsulation bugs

Handling of ipip and ip_gre ICMP error relaying is b0rken; it accesses
8bit field + 3 reserved octets as host-endian 32bit, does comparison,
subtraction and stuffs the result back.  That breaks on big-endian.

Fixed, made endian-clean.

[ Note that this effected code is permanently commented out with
  and ifdef, so this error couldn't actually cause problems for
  anyone. -DaveM ]
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 593f16aa
...@@ -393,7 +393,8 @@ static void ipgre_err(struct sk_buff *skb, u32 info) ...@@ -393,7 +393,8 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
int code = skb->h.icmph->code; int code = skb->h.icmph->code;
int rel_type = 0; int rel_type = 0;
int rel_code = 0; int rel_code = 0;
int rel_info = 0; __be32 rel_info = 0;
__u32 n = 0;
u16 flags; u16 flags;
int grehlen = (iph->ihl<<2) + 4; int grehlen = (iph->ihl<<2) + 4;
struct sk_buff *skb2; struct sk_buff *skb2;
...@@ -422,14 +423,16 @@ static void ipgre_err(struct sk_buff *skb, u32 info) ...@@ -422,14 +423,16 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
default: default:
return; return;
case ICMP_PARAMETERPROB: case ICMP_PARAMETERPROB:
if (skb->h.icmph->un.gateway < (iph->ihl<<2)) n = ntohl(skb->h.icmph->un.gateway) >> 24;
if (n < (iph->ihl<<2))
return; return;
/* So... This guy found something strange INSIDE encapsulated /* So... This guy found something strange INSIDE encapsulated
packet. Well, he is fool, but what can we do ? packet. Well, he is fool, but what can we do ?
*/ */
rel_type = ICMP_PARAMETERPROB; rel_type = ICMP_PARAMETERPROB;
rel_info = skb->h.icmph->un.gateway - grehlen; n -= grehlen;
rel_info = htonl(n << 24);
break; break;
case ICMP_DEST_UNREACH: case ICMP_DEST_UNREACH:
...@@ -440,13 +443,14 @@ static void ipgre_err(struct sk_buff *skb, u32 info) ...@@ -440,13 +443,14 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
return; return;
case ICMP_FRAG_NEEDED: case ICMP_FRAG_NEEDED:
/* And it is the only really necessary thing :-) */ /* And it is the only really necessary thing :-) */
rel_info = ntohs(skb->h.icmph->un.frag.mtu); n = ntohs(skb->h.icmph->un.frag.mtu);
if (rel_info < grehlen+68) if (n < grehlen+68)
return; return;
rel_info -= grehlen; n -= grehlen;
/* BSD 4.2 MORE DOES NOT EXIST IN NATURE. */ /* BSD 4.2 MORE DOES NOT EXIST IN NATURE. */
if (rel_info > ntohs(eiph->tot_len)) if (n > ntohs(eiph->tot_len))
return; return;
rel_info = htonl(n);
break; break;
default: default:
/* All others are translated to HOST_UNREACH. /* All others are translated to HOST_UNREACH.
...@@ -508,12 +512,11 @@ static void ipgre_err(struct sk_buff *skb, u32 info) ...@@ -508,12 +512,11 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
/* change mtu on this route */ /* change mtu on this route */
if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) { if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) {
if (rel_info > dst_mtu(skb2->dst)) { if (n > dst_mtu(skb2->dst)) {
kfree_skb(skb2); kfree_skb(skb2);
return; return;
} }
skb2->dst->ops->update_pmtu(skb2->dst, rel_info); skb2->dst->ops->update_pmtu(skb2->dst, n);
rel_info = htonl(rel_info);
} else if (type == ICMP_TIME_EXCEEDED) { } else if (type == ICMP_TIME_EXCEEDED) {
struct ip_tunnel *t = netdev_priv(skb2->dev); struct ip_tunnel *t = netdev_priv(skb2->dev);
if (t->parms.iph.ttl) { if (t->parms.iph.ttl) {
......
...@@ -341,7 +341,8 @@ static int ipip_err(struct sk_buff *skb, u32 info) ...@@ -341,7 +341,8 @@ static int ipip_err(struct sk_buff *skb, u32 info)
int code = skb->h.icmph->code; int code = skb->h.icmph->code;
int rel_type = 0; int rel_type = 0;
int rel_code = 0; int rel_code = 0;
int rel_info = 0; __be32 rel_info = 0;
__u32 n = 0;
struct sk_buff *skb2; struct sk_buff *skb2;
struct flowi fl; struct flowi fl;
struct rtable *rt; struct rtable *rt;
...@@ -354,14 +355,15 @@ static int ipip_err(struct sk_buff *skb, u32 info) ...@@ -354,14 +355,15 @@ static int ipip_err(struct sk_buff *skb, u32 info)
default: default:
return 0; return 0;
case ICMP_PARAMETERPROB: case ICMP_PARAMETERPROB:
if (skb->h.icmph->un.gateway < hlen) n = ntohl(skb->h.icmph->un.gateway) >> 24;
if (n < hlen)
return 0; return 0;
/* So... This guy found something strange INSIDE encapsulated /* So... This guy found something strange INSIDE encapsulated
packet. Well, he is fool, but what can we do ? packet. Well, he is fool, but what can we do ?
*/ */
rel_type = ICMP_PARAMETERPROB; rel_type = ICMP_PARAMETERPROB;
rel_info = skb->h.icmph->un.gateway - hlen; rel_info = htonl((n - hlen) << 24);
break; break;
case ICMP_DEST_UNREACH: case ICMP_DEST_UNREACH:
...@@ -372,13 +374,14 @@ static int ipip_err(struct sk_buff *skb, u32 info) ...@@ -372,13 +374,14 @@ static int ipip_err(struct sk_buff *skb, u32 info)
return 0; return 0;
case ICMP_FRAG_NEEDED: case ICMP_FRAG_NEEDED:
/* And it is the only really necessary thing :-) */ /* And it is the only really necessary thing :-) */
rel_info = ntohs(skb->h.icmph->un.frag.mtu); n = ntohs(skb->h.icmph->un.frag.mtu);
if (rel_info < hlen+68) if (n < hlen+68)
return 0; return 0;
rel_info -= hlen; n -= hlen;
/* BSD 4.2 MORE DOES NOT EXIST IN NATURE. */ /* BSD 4.2 MORE DOES NOT EXIST IN NATURE. */
if (rel_info > ntohs(eiph->tot_len)) if (n > ntohs(eiph->tot_len))
return 0; return 0;
rel_info = htonl(n);
break; break;
default: default:
/* All others are translated to HOST_UNREACH. /* All others are translated to HOST_UNREACH.
...@@ -440,12 +443,11 @@ static int ipip_err(struct sk_buff *skb, u32 info) ...@@ -440,12 +443,11 @@ static int ipip_err(struct sk_buff *skb, u32 info)
/* change mtu on this route */ /* change mtu on this route */
if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) { if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) {
if (rel_info > dst_mtu(skb2->dst)) { if (n > dst_mtu(skb2->dst)) {
kfree_skb(skb2); kfree_skb(skb2);
return 0; return 0;
} }
skb2->dst->ops->update_pmtu(skb2->dst, rel_info); skb2->dst->ops->update_pmtu(skb2->dst, n);
rel_info = htonl(rel_info);
} else if (type == ICMP_TIME_EXCEEDED) { } else if (type == ICMP_TIME_EXCEEDED) {
struct ip_tunnel *t = netdev_priv(skb2->dev); struct ip_tunnel *t = netdev_priv(skb2->dev);
if (t->parms.iph.ttl) { if (t->parms.iph.ttl) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment