inet: fix possible memory corruption with UDP_CORK and UFO
authorHannes Frederic Sowa <hannes@stressinduktion.org>
Mon, 21 Oct 2013 22:07:47 +0000 (00:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 19 May 2014 05:54:21 +0000 (07:54 +0200)
[ This is a simplified -stable version of a set of upstream commits. ]

This is a replacement patch only for stable which does fix the problems
handled by the following two commits in -net:

"ip_output: do skb ufo init for peeked non ufo skb as well" (e93b7d748be887cd7639b113ba7d7ef792a7efb9)
"ip6_output: do skb ufo init for peeked non ufo skb as well" (c547dbf55d5f8cf615ccc0e7265e98db27d3fb8b)

Three frames are written on a corked udp socket for which the output
netdevice has UFO enabled.  If the first and third frame are smaller than
the mtu and the second one is bigger, we enqueue the second frame with
skb_append_datato_frags without initializing the gso fields. This leads
to the third frame appended regulary and thus constructing an invalid skb.

This fixes the problem by always using skb_append_datato_frags as soon
as the first frag got enqueued to the skb without marking the packet
as SKB_GSO_UDP.

The problem with only two frames for ipv6 was fixed by "ipv6: udp
packets following an UFO enqueued packet need also be handled by UFO"
(2811ebac2521ceac84f2bdae402455baa6a7fb47).

Cc: Jiri Pirko <jiri@resnulli.us>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: David Miller <davem@davemloft.net>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
(cherry picked from commit 5124ae99ac8a8f63d0fca9b75adaef40b20678ff)
Signed-off-by: Willy Tarreau <w@1wt.eu>
net/ipv4/ip_output.c
net/ipv6/ip6_output.c

index 2cd69e3497ad6c4e58191b3ef8928c9447ca22aa..faa662396bc8c1a66864f5bea6b8dd183e4d94f0 100644 (file)
@@ -875,7 +875,7 @@ int ip_append_data(struct sock *sk,
        skb = skb_peek_tail(&sk->sk_write_queue);
 
        inet->cork.length += length;
-       if (((length > mtu) || (skb && skb_is_gso(skb))) &&
+       if (((length > mtu) || (skb && skb_has_frags(skb))) &&
            (sk->sk_protocol == IPPROTO_UDP) &&
            (rt->u.dst.dev->features & NETIF_F_UFO)) {
                err = ip_ufo_append_data(sk, getfrag, from, length, hh_len,
index 5a1b5bca19dac10b437fe5b3d68746aa1e36bb82..6dff3d7835e897fd2cb094cfc5ce5681758b1e88 100644 (file)
@@ -1257,7 +1257,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
        inet->cork.length += length;
        skb = skb_peek_tail(&sk->sk_write_queue);
        if (((length > mtu) ||
-            (skb && skb_is_gso(skb))) &&
+            (skb && skb_has_frags(skb))) &&
            (sk->sk_protocol == IPPROTO_UDP) &&
            (rt->u.dst.dev->features & NETIF_F_UFO)) {
                err = ip6_ufo_append_data(sk, getfrag, from, length,