]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
TCP: Fix size calculation in sk_stream_alloc_pskb
authorHerbert Xu <herbert@gondor.apana.org.au>
Wed, 14 Nov 2007 23:45:21 +0000 (15:45 -0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 16 Nov 2007 16:27:36 +0000 (08:27 -0800)
[TCP]: Fix size calculation in sk_stream_alloc_pskb

[ Upstream commit: fb93134dfc2a6e6fbedc7c270a31da03fce88db9 ]

We round up the header size in sk_stream_alloc_pskb so that
TSO packets get zero tail room.  Unfortunately this rounding
up is not coordinated with the select_size() function used by
TCP to calculate the second parameter of sk_stream_alloc_pskb.

As a result, we may allocate more than a page of data in the
non-TSO case when exactly one page is desired.

In fact, rounding up the head room is detrimental in the non-TSO
case because it makes memory that would otherwise be available to
the payload head room.  TSO doesn't need this either, all it wants
is the guarantee that there is no tail room.

So this patch fixes this by adjusting the skb_reserve call so that
exactly the requested amount (which all callers have calculated in
a precise way) is made available as tail room.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/net/sock.h

index dfeb8b13024f8827febf8cedbcee48666106d4b3..bdd9ebe6339283f4e0ee5f9a3b2b7bcb6ac6563f 100644 (file)
@@ -1199,14 +1199,16 @@ static inline struct sk_buff *sk_stream_alloc_pskb(struct sock *sk,
                                                   gfp_t gfp)
 {
        struct sk_buff *skb;
-       int hdr_len;
 
-       hdr_len = SKB_DATA_ALIGN(sk->sk_prot->max_header);
-       skb = alloc_skb_fclone(size + hdr_len, gfp);
+       skb = alloc_skb_fclone(size + sk->sk_prot->max_header, gfp);
        if (skb) {
                skb->truesize += mem;
                if (sk_stream_wmem_schedule(sk, skb->truesize)) {
-                       skb_reserve(skb, hdr_len);
+                       /*
+                        * Make sure that we have exactly size bytes
+                        * available to the caller, no more, no less.
+                        */
+                       skb_reserve(skb, skb_tailroom(skb) - size);
                        return skb;
                }
                __kfree_skb(skb);