Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Vijay Subramanian <subramanian.vijay@gmail.com>
Cc: Tom Herbert <therbert@google.com>,
	Linux Netdev List <netdev@vger.kernel.org>,
	David Miller <davem@davemloft.net>
Subject: Re: Bug in computing data_len in tcp_sendmsg?
Date: Fri, 02 Dec 2011 16:44:23 +0100	[thread overview]
Message-ID: <1322840663.2762.26.camel@edumazet-laptop> (raw)
In-Reply-To: <1322827188.2607.19.camel@edumazet-laptop>

Le vendredi 02 décembre 2011 à 12:59 +0100, Eric Dumazet a écrit :

> Thanks for this detailed explanation !
> 
> And yes, you're probably right.
> 
> Are you willing to submit a patch to fix this ?
> 
> (If not, I can do it myself of course)
> 

[PATCH net-next] tcp: fix tcp_trim_head()

commit f07d960df3 (tcp: avoid frag allocation for small frames)
breaked assumption in tcp stack that skb is either linear (data_len ==
0), either fully fragged (data_len == len)

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>
---
 net/ipv4/tcp_output.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 58f69ac..4a0f54a 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;

  reply	other threads:[~2011-12-02 15:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-01  1:48 Bug in computing data_len in tcp_sendmsg? Tom Herbert
2011-12-01  3:42 ` Eric Dumazet
2011-12-01  4:06   ` Tom Herbert
2011-12-01  4:16     ` David Miller
2011-12-01  4:17     ` Eric Dumazet
2011-12-01  5:09       ` Tom Herbert
2011-12-01  9:15         ` Eric Dumazet
2011-12-01 17:29           ` Jesse Brandeburg
2011-12-01 18:04             ` David Miller
2011-12-01 20:37             ` Eric Dumazet
2011-12-01 22:18       ` Vijay Subramanian
2011-12-01 22:30         ` Eric Dumazet
2011-12-02  6:18           ` Vijay Subramanian
2011-12-02 11:59             ` Eric Dumazet
2011-12-02 15:44               ` Eric Dumazet [this message]
2011-12-02 16:05                 ` Eric Dumazet
2011-12-02 18:13                   ` David Miller
2011-12-02 18:36                     ` Eric Dumazet
2011-12-02 18:40                       ` David Miller
2011-12-02 20:22                         ` Eric Dumazet
2011-12-02 20:24                           ` David Miller
2011-12-02 20:45                             ` Eric Dumazet
2011-12-02 20:48                               ` Eric Dumazet
2011-12-02 21:30                               ` David Miller
2011-12-03 15:09                                 ` Eric Dumazet
2011-12-04  7:39                                   ` [PATCH] tcp: take care of misalignments Eric Dumazet
2011-12-04 18:21                                     ` David Miller
2011-12-04 18:51                                       ` Eric Dumazet
2011-12-05 23:45                                         ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1322840663.2762.26.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=subramanian.vijay@gmail.com \
    --cc=therbert@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox