diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2011-12-04 08:51:08 +0000 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2012-05-11 13:14:22 +0100 |
commit | 91bb95f240936feb98f7d540027c78773e4b84cb (patch) | |
tree | a7effcaf9f318ad95a427afc74cb0088564e9d55 | |
parent | 34b0788a13e9c65440e3d736a91f75964356ad67 (diff) | |
download | linux-stable-91bb95f240936feb98f7d540027c78773e4b84cb.tar.gz linux-stable-91bb95f240936feb98f7d540027c78773e4b84cb.tar.bz2 linux-stable-91bb95f240936feb98f7d540027c78773e4b84cb.zip |
tcp: fix tcp_trim_head()
[ Upstream commit 4fa48bf3c75069d636fc8830743c929a062e80dc ]
commit f07d960df3 (tcp: avoid frag allocation for small frames)
breaked assumption in tcp stack that skb is either linear (skb->data_len
== 0), or fully fragged (skb->data_len == skb->len)
tcp_trim_head() made this assumption, we must fix it.
Thanks to Vijay for providing a very detailed explanation.
Reported-by: Vijay Subramanian <subramanian.vijay@gmail.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | net/ipv4/tcp_output.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 097e0c72b3fd..7413437efc8d 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1093,6 +1093,13 @@ static void __pskb_trim_head(struct sk_buff *skb, int len) { int i, k, eat; + eat = min_t(int, len, skb_headlen(skb)); + if (eat) { + __skb_pull(skb, eat); + len -= eat; + if (!len) + return; + } eat = len; k = 0; for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { @@ -1124,11 +1131,7 @@ int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len) if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) return -ENOMEM; - /* If len == headlen, we avoid __skb_pull to preserve alignment. */ - if (unlikely(len < skb_headlen(skb))) - __skb_pull(skb, len); - else - __pskb_trim_head(skb, len - skb_headlen(skb)); + __pskb_trim_head(skb, len); TCP_SKB_CB(skb)->seq += len; skb->ip_summed = CHECKSUM_PARTIAL; |