public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Paul Durrant <paul.durrant@citrix•com>
To: <xen-devel@lists•xen.org>, <netdev@vger•kernel.org>
Cc: Paul Durrant <paul.durrant@citrix•com>,
	Wei Liu <wei.liu2@citrix•com>,
	Ian Campbell <ian.campbell@citrix•com>,
	David Vrabel <david.vrabel@citrix•com>
Subject: [PATCH net v2] xen-netback: fix fragment detection in checksum setup
Date: Thu, 28 Nov 2013 13:23:52 +0000	[thread overview]
Message-ID: <1385645032-29848-1-git-send-email-paul.durrant@citrix.com> (raw)

The code to detect fragments in checksum_setup() was missing for IPv4 and
too eager for IPv6. (It transpires that Windows seems to send IPv6 packets
with a fragment header even if they are not a fragment - i.e. offset is zero,
and M bit is not set).

Signed-off-by: Paul Durrant <paul.durrant@citrix•com>
Cc: Wei Liu <wei.liu2@citrix•com>
Cc: Ian Campbell <ian.campbell@citrix•com>
Cc: David Vrabel <david.vrabel@citrix•com>
---
v2

- Added comments noting what fragment/offset masks mean
  
 drivers/net/xen-netback/netback.c |   33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 919b650..c7464d8 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1165,15 +1165,28 @@ static int checksum_setup_ip(struct xenvif *vif, struct sk_buff *skb,
 	struct iphdr *iph = (void *)skb->data;
 	unsigned int header_size;
 	unsigned int off;
+	bool fragment;
 	int err = -EPROTO;
 
+	fragment = false;
+
 	off = sizeof(struct iphdr);
 
 	header_size = skb->network_header + off + MAX_IPOPTLEN;
 	maybe_pull_tail(skb, header_size);
 
+	/* 3fff -> fragment offset != 0 OR more fragments */
+	if (ntohs(iph->frag_off) & 0x3fff)
+		fragment = true;
+
 	off = iph->ihl * 4;
 
+	if (fragment) {
+		if (net_ratelimit())
+			netdev_err(vif->dev, "Packet is a fragment!\n");
+		goto out;
+	}
+
 	switch (iph->protocol) {
 	case IPPROTO_TCP:
 		if (!skb_partial_csum_set(skb, off,
@@ -1237,6 +1250,7 @@ static int checksum_setup_ipv6(struct xenvif *vif, struct sk_buff *skb,
 	bool fragment;
 	bool done;
 
+	fragment = false;
 	done = false;
 
 	off = sizeof(struct ipv6hdr);
@@ -1275,9 +1289,22 @@ static int checksum_setup_ipv6(struct xenvif *vif, struct sk_buff *skb,
 			off += (hp->hdrlen+2)<<2;
 			break;
 		}
-		case IPPROTO_FRAGMENT:
-			fragment = true;
-			/* fall through */
+		case IPPROTO_FRAGMENT: {
+			struct frag_hdr *hp = (void *)(skb->data + off);
+
+			header_size = skb->network_header +
+				off +
+				sizeof(struct frag_hdr);
+			maybe_pull_tail(skb, header_size);
+
+			/* fff9 -> fragment offset != 0 OR more fragments */
+			if (ntohs(hp->frag_off) & 0xfff9)
+				fragment = true;
+
+			nexthdr = hp->nexthdr;
+			off += sizeof(struct frag_hdr);
+			break;
+		}
 		default:
 			done = true;
 			break;
-- 
1.7.10.4

             reply	other threads:[~2013-11-28 13:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-28 13:23 Paul Durrant [this message]
2013-11-28 17:29 ` [PATCH net v2] xen-netback: fix fragment detection in checksum setup Eric Dumazet
2013-11-29 10:32   ` Paul Durrant
2013-11-29  5:35 ` annie li
2013-11-29  9:10   ` Paul Durrant
2013-11-29  9:57     ` [Xen-devel] " annie li

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=1385645032-29848-1-git-send-email-paul.durrant@citrix.com \
    --to=paul.durrant@citrix$(echo .)com \
    --cc=david.vrabel@citrix$(echo .)com \
    --cc=ian.campbell@citrix$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=wei.liu2@citrix$(echo .)com \
    --cc=xen-devel@lists$(echo .)xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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