Skip to content

Commit 79e4950

Browse files
Florian Westphaldavem330
authored andcommitted
ipv6: avoid write to a possibly cloned skb
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: Andreas Karis <akaris@redhat.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6e526fd commit 79e4950

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎net/ipv6/ip6_output.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,14 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
768768
* Fragment the datagram.
769769
*/
770770

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

774773
/*
775774
* Keep copying data until we run out.
776775
*/
777776
while (left > 0) {
777+
u8 *fragnexthdr_offset;
778+
778779
len = left;
779780
/* IF: it doesn't fit, use 'mtu' - the data space left */
780781
if (len > mtu)
@@ -819,6 +820,10 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
819820
*/
820821
skb_copy_from_linear_data(skb, skb_network_header(frag), hlen);
821822

823+
fragnexthdr_offset = skb_network_header(frag);
824+
fragnexthdr_offset += prevhdr - skb_network_header(skb);
825+
*fragnexthdr_offset = NEXTHDR_FRAGMENT;
826+
822827
/*
823828
* Build fragment header.
824829
*/

0 commit comments

Comments
 (0)