netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net,stable] net: cdc_mbim: handle unaccelerated VLAN tagged frames
@ 2014-05-09 12:45 Bjørn Mork
       [not found] ` <1399639500-13907-1-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Bjørn Mork @ 2014-05-09 12:45 UTC (permalink / raw)
  To: netdev; +Cc: linux-usb, Oliver Neukum, Bjørn Mork, Greg Suarez

This driver maps 802.1q VLANs to MBIM sessions. The mapping is based on
a bogus assumption that all tagged frames will use the acceleration API
because we enable NETIF_F_HW_VLAN_CTAG_TX. This fails for e.g. frames
tagged in userspace using packet sockets. Such frames will erroneously
be considered as untagged and silently dropped based on not being IP.

Fix by falling back to looking into the ethernet header for a tag if no
accelerated tag was found.

Fixes: a82c7ce5bc5b ("net: cdc_ncm: map MBIM IPS SessionID to VLAN ID")
Cc: Greg Suarez <gsuarez@smithmicro.com>
Signed-off-by: Bjørn Mork <bjorn@mork.no>
---
This bug has been present since the driver was introduced in v3.8, and
should therefore be applied to all maintained stable kernels from v3.8
and onwards.  I have verified that it applies cleanly to the original
v3.8 version as well as the current net/master, so I believe it should
apply unmodified all versions in between.


Thanks,
Bjørn


 drivers/net/usb/cdc_mbim.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c
index 13f7705fd679..2e025ddcef21 100644
--- a/drivers/net/usb/cdc_mbim.c
+++ b/drivers/net/usb/cdc_mbim.c
@@ -120,6 +120,16 @@ static void cdc_mbim_unbind(struct usbnet *dev, struct usb_interface *intf)
 	cdc_ncm_unbind(dev, intf);
 }
 
+/* verify that the ethernet protocol is IPv4 or IPv6 */
+static bool is_ip_proto(__be16 proto)
+{
+	switch (proto) {
+	case htons(ETH_P_IP):
+	case htons(ETH_P_IPV6):
+		return true;
+	}
+	return false;
+}
 
 static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
 {
@@ -128,6 +138,7 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
 	struct cdc_ncm_ctx *ctx = info->ctx;
 	__le32 sign = cpu_to_le32(USB_CDC_MBIM_NDP16_IPS_SIGN);
 	u16 tci = 0;
+	bool is_ip;
 	u8 *c;
 
 	if (!ctx)
@@ -137,25 +148,32 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
 		if (skb->len <= ETH_HLEN)
 			goto error;
 
+		/* Some applications using e.g. packet sockets will
+		 * bypass the VLAN acceleration and create tagged
+		 * ethernet frames directly.  We primarily look for
+		 * the accelerated out-of-band tag, but fall back if
+		 * required
+		 */
+		skb_reset_mac_header(skb);
+		if (vlan_get_tag(skb, &tci) < 0 && skb->len > VLAN_ETH_HLEN &&
+		    __vlan_get_tag(skb, &tci) == 0) {
+			is_ip = is_ip_proto(vlan_eth_hdr(skb)->h_vlan_encapsulated_proto);
+			skb_pull(skb, VLAN_ETH_HLEN);
+		} else {
+			is_ip = is_ip_proto(eth_hdr(skb)->h_proto);
+			skb_pull(skb, ETH_HLEN);
+		}
+
 		/* mapping VLANs to MBIM sessions:
 		 *   no tag     => IPS session <0>
 		 *   1 - 255    => IPS session <vlanid>
 		 *   256 - 511  => DSS session <vlanid - 256>
 		 *   512 - 4095 => unsupported, drop
 		 */
-		vlan_get_tag(skb, &tci);
-
 		switch (tci & 0x0f00) {
 		case 0x0000: /* VLAN ID 0 - 255 */
-			/* verify that datagram is IPv4 or IPv6 */
-			skb_reset_mac_header(skb);
-			switch (eth_hdr(skb)->h_proto) {
-			case htons(ETH_P_IP):
-			case htons(ETH_P_IPV6):
-				break;
-			default:
+			if (!is_ip)
 				goto error;
-			}
 			c = (u8 *)&sign;
 			c[3] = tci;
 			break;
@@ -169,7 +187,6 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
 				  "unsupported tci=0x%04x\n", tci);
 			goto error;
 		}
-		skb_pull(skb, ETH_HLEN);
 	}
 
 	spin_lock_bh(&ctx->mtx);
-- 
2.0.0.rc2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net,stable] net: cdc_mbim: handle unaccelerated VLAN tagged frames
       [not found] ` <1399639500-13907-1-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
@ 2014-05-09 17:30   ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-05-09 17:30 UTC (permalink / raw)
  To: bjorn-yOkvZcmFvRU
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	oliver-GvhC2dPhHPQdnm+yROfE0A, gsuarez-AKjrjAf1O7qe8kRwQpwjMg

From: Bjørn Mork <bjorn-yOkvZcmFvRU@public.gmane.org>
Date: Fri,  9 May 2014 14:45:00 +0200

> This driver maps 802.1q VLANs to MBIM sessions. The mapping is based on
> a bogus assumption that all tagged frames will use the acceleration API
> because we enable NETIF_F_HW_VLAN_CTAG_TX. This fails for e.g. frames
> tagged in userspace using packet sockets. Such frames will erroneously
> be considered as untagged and silently dropped based on not being IP.
> 
> Fix by falling back to looking into the ethernet header for a tag if no
> accelerated tag was found.
> 
> Fixes: a82c7ce5bc5b ("net: cdc_ncm: map MBIM IPS SessionID to VLAN ID")
> Cc: Greg Suarez <gsuarez-AKjrjAf1O7qe8kRwQpwjMg@public.gmane.org>
> Signed-off-by: Bjørn Mork <bjorn-yOkvZcmFvRU@public.gmane.org>

Applied, thank you!

> This bug has been present since the driver was introduced in v3.8, and
> should therefore be applied to all maintained stable kernels from v3.8
> and onwards.  I have verified that it applies cleanly to the original
> v3.8 version as well as the current net/master, so I believe it should
> apply unmodified all versions in between.

This annotation is very much appreciated, because when I process my
-stable queue this information in right there waiting for me in the
patchwork bundle I create.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-09 17:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-09 12:45 [PATCH net,stable] net: cdc_mbim: handle unaccelerated VLAN tagged frames Bjørn Mork
     [not found] ` <1399639500-13907-1-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
2014-05-09 17:30   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).