Commit 4c028756 authored by Florian Westphal's avatar Florian Westphal Committed by Jiri Slaby

ipv6: avoid write to a possibly cloned skb

[ Upstream commit 79e49503 ]

ip6_fragment, in case skb has a fraglist, checks if the
skb is cloned.  If it is, it will move to the 'slow path' and allocates
new skbs for each fragment.

However, right before entering the slowpath loop, it updates the
nexthdr value of the last ipv6 extension header to NEXTHDR_FRAGMENT,
to account for the fragment header that will be inserted in the new
ipv6-fragment skbs.

In case original skb is cloned this munges nexthdr value of another
skb.  Avoid this by doing the nexthdr update for each of the new fragment
skbs separately.

This was observed with tcpdump on a bridge device where netfilter ipv6
reassembly is active:  tcpdump shows malformed fragment headers as
the l4 header (icmpv6, tcp, etc). is decoded as a fragment header.

Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
Reported-by: default avatarAndreas Karis <akaris@redhat.com>
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent 3c1417ea
...@@ -716,7 +716,6 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -716,7 +716,6 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
* Fragment the datagram. * Fragment the datagram.
*/ */
*prevhdr = NEXTHDR_FRAGMENT;
hroom = LL_RESERVED_SPACE(rt->dst.dev); hroom = LL_RESERVED_SPACE(rt->dst.dev);
troom = rt->dst.dev->needed_tailroom; troom = rt->dst.dev->needed_tailroom;
...@@ -724,6 +723,8 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -724,6 +723,8 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
* Keep copying data until we run out. * Keep copying data until we run out.
*/ */
while(left > 0) { while(left > 0) {
u8 *fragnexthdr_offset;
len = left; len = left;
/* IF: it doesn't fit, use 'mtu' - the data space left */ /* IF: it doesn't fit, use 'mtu' - the data space left */
if (len > mtu) if (len > mtu)
...@@ -770,6 +771,10 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -770,6 +771,10 @@ int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
*/ */
skb_copy_from_linear_data(skb, skb_network_header(frag), hlen); skb_copy_from_linear_data(skb, skb_network_header(frag), hlen);
fragnexthdr_offset = skb_network_header(frag);
fragnexthdr_offset += prevhdr - skb_network_header(skb);
*fragnexthdr_offset = NEXTHDR_FRAGMENT;
/* /*
* Build fragment header. * Build fragment header.
*/ */
......
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