Skip to content

Commit

Permalink
ipv6: avoid write to a possibly cloned skb
Browse files Browse the repository at this point in the history
BugLink: http://bugs.launchpad.net/bugs/1675789

[ Upstream commit 79e4950 ]

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 <[email protected]>
Reported-by: Andreas Karis <[email protected]>
Signed-off-by: Florian Westphal <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Tim Gardner <[email protected]>
Signed-off-by: Thadeu Lima de Souza Cascardo <[email protected]>
  • Loading branch information
Florian Westphal authored and Thadeu Lima de Souza Cascardo committed Apr 6, 2017
1 parent 15e5372 commit b95910e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion net/ipv6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,14 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
* Fragment the datagram.
*/

*prevhdr = NEXTHDR_FRAGMENT;
troom = rt->dst.dev->needed_tailroom;

/*
* Keep copying data until we run out.
*/
while (left > 0) {
u8 *fragnexthdr_offset;

len = left;
/* IF: it doesn't fit, use 'mtu' - the data space left */
if (len > mtu)
Expand Down Expand Up @@ -793,6 +794,10 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
*/
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.
*/
Expand Down

0 comments on commit b95910e

Please sign in to comment.