Commit ef4656af authored by David S. Miller's avatar David S. Miller Committed by Greg Kroah-Hartman

ipv6: Check ip6_find_1stfragopt() return value properly.


[ Upstream commit 7dd7eb95 ]

Do not use unsigned variables to see if it returns a negative
error or not.

Fixes: 2423496a ("ipv6: Prevent overrun when parsing v6 header options")
Reported-by: default avatarJulia Lawall <julia.lawall@lip6.fr>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5ca68dbb
...@@ -62,7 +62,6 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, ...@@ -62,7 +62,6 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
const struct net_offload *ops; const struct net_offload *ops;
int proto; int proto;
struct frag_hdr *fptr; struct frag_hdr *fptr;
unsigned int unfrag_ip6hlen;
u8 *prevhdr; u8 *prevhdr;
int offset = 0; int offset = 0;
bool encap, udpfrag; bool encap, udpfrag;
...@@ -121,10 +120,10 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, ...@@ -121,10 +120,10 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
skb->network_header = (u8 *)ipv6h - skb->head; skb->network_header = (u8 *)ipv6h - skb->head;
if (udpfrag) { if (udpfrag) {
unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr); int err = ip6_find_1stfragopt(skb, &prevhdr);
if (unfrag_ip6hlen < 0) if (err < 0)
return ERR_PTR(unfrag_ip6hlen); return ERR_PTR(err);
fptr = (struct frag_hdr *)((u8 *)ipv6h + unfrag_ip6hlen); fptr = (struct frag_hdr *)((u8 *)ipv6h + err);
fptr->frag_off = htons(offset); fptr->frag_off = htons(offset);
if (skb->next != NULL) if (skb->next != NULL)
fptr->frag_off |= htons(IP6_MF); fptr->frag_off |= htons(IP6_MF);
......
...@@ -569,11 +569,10 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -569,11 +569,10 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
u8 *prevhdr, nexthdr = 0; u8 *prevhdr, nexthdr = 0;
struct net *net = dev_net(skb_dst(skb)->dev); struct net *net = dev_net(skb_dst(skb)->dev);
hlen = ip6_find_1stfragopt(skb, &prevhdr); err = ip6_find_1stfragopt(skb, &prevhdr);
if (hlen < 0) { if (err < 0)
err = hlen;
goto fail; goto fail;
} hlen = err;
nexthdr = *prevhdr; nexthdr = *prevhdr;
mtu = ip6_skb_dst_mtu(skb); mtu = ip6_skb_dst_mtu(skb);
......
...@@ -29,6 +29,7 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, ...@@ -29,6 +29,7 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb,
u8 frag_hdr_sz = sizeof(struct frag_hdr); u8 frag_hdr_sz = sizeof(struct frag_hdr);
__wsum csum; __wsum csum;
int tnl_hlen; int tnl_hlen;
int err;
mss = skb_shinfo(skb)->gso_size; mss = skb_shinfo(skb)->gso_size;
if (unlikely(skb->len <= mss)) if (unlikely(skb->len <= mss))
...@@ -93,9 +94,10 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, ...@@ -93,9 +94,10 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb,
/* Find the unfragmentable header and shift it left by frag_hdr_sz /* Find the unfragmentable header and shift it left by frag_hdr_sz
* bytes to insert fragment header. * bytes to insert fragment header.
*/ */
unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr); err = ip6_find_1stfragopt(skb, &prevhdr);
if (unfrag_ip6hlen < 0) if (err < 0)
return ERR_PTR(unfrag_ip6hlen); return ERR_PTR(err);
unfrag_ip6hlen = err;
nexthdr = *prevhdr; nexthdr = *prevhdr;
*prevhdr = NEXTHDR_FRAGMENT; *prevhdr = NEXTHDR_FRAGMENT;
unfrag_len = (skb_network_header(skb) - skb_mac_header(skb)) + unfrag_len = (skb_network_header(skb) - skb_mac_header(skb)) +
......
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