usbnet: remove generic hard_header_len check
Subsystems (7)
PATCH 1/1 usbnet: remove generic hard_header_len check
This patch removes a generic hard_header_len check from the usbnet module that is causing dropped packages under certain circumstances for devices that send rx packets that cross urb boundaries.
One example is the AX88772B which occasionally send rx packets that cross urb boundaries where the remaining partial packet is sent with no hardware header. When the buffer with a partial packet is of less number of octets than the value of hard_header_len the buffer is discarded by the usbnet module.
With AX88772B this can be reproduced by using ping with a packet size between 1965-1976.
The bug has been reported here:
https://bugzilla.kernel.org/show_bug.cgi?id=29082
This patch introduces the following changes:
- Removes the generic hard_header_len check in the rx_complete function in the usbnet module.
- Introduces a ETH_HLEN check for skbs that are not cloned from within a rx_fixup callback.
- For safety a hard_header_len check is added to each rx_fixup callback function that could be affected by this change. These extra checks could possibly be removed by someone who has the hardware to test.
The changes place full responsibility on the rx_fixup callback functions that clone skbs to only pass valid skbs to the usbnet_skb_return function.
---
An alternative solution is to add the ETH_HLEN check to usbnet_skb_return() and add short skbs to the skb->done list to be cleaned up in rx_process().
drivers/net/usb/ax88179_178a.c | 4 ++++ drivers/net/usb/gl620a.c | 4 ++++ drivers/net/usb/mcs7830.c | 5 +++-- drivers/net/usb/net1080.c | 4 ++++ drivers/net/usb/qmi_wwan.c | 8 ++++---- drivers/net/usb/rndis_host.c | 4 ++++ drivers/net/usb/smsc75xx.c | 4 ++++ drivers/net/usb/smsc95xx.c | 4 ++++ drivers/net/usb/sr9800.c | 4 ++++ drivers/net/usb/usbnet.c | 25 ++++++++++--------------- 10 files changed, 45 insertions(+), 21 deletions(-)
drivers/net/usb/ax88179_178a.c +4 -0
@@ -1118,6 +1118,10 @@ static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb)u16 hdr_off;u32 *pkt_hdr; +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +skb_trim (skb, skb->len -4 );memcpy (&rx_hdr,skb_tail_pointer (skb),4 );le32_to_cpus (&rx_hdr);
drivers/net/usb/gl620a.c +4 -0
@@ -84,6 +84,10 @@ static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)u32 size;u32 count; +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; + header = (struct gl_header *) skb->data;// get the packet count of the received skb
drivers/net/usb/mcs7830.c +3 -2
@@ -526,8 +526,9 @@ static int mcs7830_rx_fixup(struct usbnet *dev, struct sk_buff *skb) {u8 status; -if (skb->len ==0 ) { -dev_err (&dev->udev->dev,"unexpected empty rx frame\n" ); +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) { +dev_err (&dev->udev->dev,"unexpected tiny rx frame\n" );return 0 ; }
drivers/net/usb/net1080.c +4 -0
@@ -364,6 +364,10 @@ static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb)struct nc_trailer *trailer;u16 hdr_len, packet_len; +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +if (!(skb->len &0x01 )) { netdev_dbg(dev->net, "rx framesize %d range %d..%d mtu %d\n", skb->len, dev->net->hard_header_len, dev->hard_mtu,
drivers/net/usb/qmi_wwan.c +4 -4
@@ -80,10 +80,10 @@ static int qmi_wwan_rx_fixup(struct usbnet *dev, struct sk_buff *skb) {__be16 proto; -/* usbnet rx_complete guarantees that skb->len is at least -* hard_header_len, so we can inspect the dest address without -* checking skb->len -*/ +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +switch (skb->data[0 ] &0xf0 ) {case 0x40 : proto =htons (ETH_P_IP );
drivers/net/usb/rndis_host.c +4 -0
@@ -492,6 +492,10 @@ EXPORT_SYMBOL_GPL(rndis_unbind);*/ int rndis_rx_fixup (struct usbnet *dev,struct sk_buff *skb) { +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +/* peripheral may have batched packets to us... */ while (likely (skb->len)) {struct rndis_data_hdr *hdr = (void *)skb->data;
drivers/net/usb/smsc75xx.c +4 -0
@@ -2106,6 +2106,10 @@ static void smsc75xx_rx_csum_offload(struct usbnet *dev, struct sk_buff *skb,static int smsc75xx_rx_fixup (struct usbnet *dev,struct sk_buff *skb) { +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +while (skb->len >0 ) {u32 rx_cmd_a, rx_cmd_b, align_count, size;struct sk_buff *ax_skb;
drivers/net/usb/smsc95xx.c +4 -0
@@ -1723,6 +1723,10 @@ static void smsc95xx_rx_csum_offload(struct sk_buff *skb)static int smsc95xx_rx_fixup (struct usbnet *dev,struct sk_buff *skb) { +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +while (skb->len >0 ) {u32 header, align_count;struct sk_buff *ax_skb;
drivers/net/usb/sr9800.c +4 -0
@@ -63,6 +63,10 @@ static int sr_rx_fixup(struct usbnet *dev, struct sk_buff *skb) {int offset =0 ; +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +while (offset +sizeof (u32) < skb->len) {struct sk_buff *sr_skb;u16 size;
drivers/net/usb/usbnet.c +10 -15
@@ -542,17 +542,19 @@ static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) }// else network stack removes extra byte if we forced a short packet -if (skb->len) { -/* all data was already cloned from skb inside the driver */ -if (dev->driver_info->flags &FLAG_MULTI_PACKET ) -dev_kfree_skb_any (skb); -else -usbnet_skb_return (dev, skb); +/* all data was already cloned from skb inside the driver */ +if (dev->driver_info->flags &FLAG_MULTI_PACKET ) + goto done; + +if (skb->len <ETH_HLEN ) { + dev->net->stats.rx_errors++; + dev->net->stats.rx_length_errors++; +netif_dbg (dev, rx_err, dev->net,"rx length %d\n" , skb->len); + }else { +usbnet_skb_return (dev, skb);return ; } -netif_dbg (dev, rx_err, dev->net,"drop\n" ); - dev->net->stats.rx_errors++; done:skb_queue_tail (&dev->done, skb); }
@@ -574,13 +576,6 @@ static void rx_complete (struct urb *urb)switch (urb_status) {/* success */ case 0 : -if (skb->len < dev->net->hard_header_len) { - state = rx_cleanup; - dev->net->stats.rx_errors++; - dev->net->stats.rx_length_errors++; -netif_dbg (dev, rx_err, dev->net, -"rx length %d\n" , skb->len); - }break ;/* stalls need manual reset. this is rare ... except that
Signature · 1 line
1.7.10.4
Bjørn Mork
maintainerQuoted 27 lines · Emil Goode
This patch removes a generic
hard_header_lencheck from the usbnet module that is causing dropped packages under certain circumstances for devices that send rx packets that cross urb boundaries.One example is the AX88772B which occasionally send rx packets that cross urb boundaries where the remaining partial packet is sent with no hardware header. When the buffer with a partial packet is of less number of octets than the value of
hard_header_lenthe buffer is discarded by the usbnet module.With AX88772B this can be reproduced by using ping with a packet size between 1965-1976.
The bug has been reported here:
https://bugzilla.kernel.org/show_bug.cgi?id=29082
This patch introduces the following changes:
- Removes the generichard_header_lencheck in therx_completefunction in the usbnet module.
- Introduces aETH_HLENcheck for skbs that are not cloned from within arx_fixupcallback.
- For safety ahard_header_lencheck is added to eachrx_fixupcallback function that could be affected by this change. These extra checks could possibly be removed by someone who has the hardware to test.
Quoted 6 lines
The changes place full responsibility on the
rx_fixupcallback functions that clone skbs to only pass valid skbs to theusbnet_skb_returnfunction.Signed-off-by Emil Goode <[email protected]>Reported-by Igor Gnatenko <[email protected]>
Great work! Looks good to me.
Just a couple of questions:
Quoted 24 lines
drivers/net/usb/qmi_wwan.c +4
-4@@ -80,10 +80,10 @@ static int qmi_wwan_rx_fixup(struct usbnet *dev, struct sk_buff *skb) {__be16 proto; -/* usbnet rx_complete guarantees that skb->len is at least -* hard_header_len, so we can inspect the dest address without -* checking skb->len -*/ +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +switch (skb->data[0 ] &0xf0 ) {case 0x40 : proto =htons (ETH_P_IP );drivers/net/usb/rndis_host.c +0
-0
drivers/net/usb/rndis_host.c EXPORT_SYMBOL_GPL(rndis_unbind); · line 498
Quoted 7 lines
drivers/net/usb/rndis_host.c +4
-0@@ -492,6 +492,10 @@ EXPORT_SYMBOL_GPL(rndis_unbind);*/ int rndis_rx_fixup (struct usbnet *dev,struct sk_buff *skb) { +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +
Wouldn't it be better to test against ETH_HLEN, since that is a constant and "obviously correct" in this case?
Quoted 22 lines
drivers/net/usb/usbnet.c +8
-6@@ -542,17 +542,19 @@ static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) }// else network stack removes extra byte if we forced a short packet -if (skb->len) { -/* all data was already cloned from skb inside the driver */ -if (dev->driver_info->flags &FLAG_MULTI_PACKET ) -dev_kfree_skb_any (skb); -else -usbnet_skb_return (dev, skb); +/* all data was already cloned from skb inside the driver */ +if (dev->driver_info->flags &FLAG_MULTI_PACKET ) + goto done; + +if (skb->len <ETH_HLEN ) { + dev->net->stats.rx_errors++; + dev->net->stats.rx_length_errors++; +netif_dbg (dev, rx_err, dev->net,"rx length %d\n" , skb->len);
drivers/net/usb/usbnet.c static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) · line 560
Quoted 10 lines
drivers/net/usb/usbnet.c +2
-2+ }else { +usbnet_skb_return (dev, skb);return ; } -netif_dbg (dev, rx_err, dev->net,"drop\n" ); - dev->net->stats.rx_errors++; done:skb_queue_tail (&dev->done, skb); }
At first glance I wondered where the dev_kfree_skb_any(skb) went. But then I realized that you leave that to the common rx_cleanup path, using the dev->done queue. Is that right? If so, then I guess it could use a bit of explaining in the commit message?
If I'm wrong, then I'm still looking for the explanation of where the dev_kfree_skb_any went :-)
Bjørn
Quoted 33 lines · Bjørn Mork
Quoted 31 lines · Emil Goode
This patch removes a generic
hard_header_lencheck from the usbnet module that is causing dropped packages under certain circumstances for devices that send rx packets that cross urb boundaries.One example is the AX88772B which occasionally send rx packets that cross urb boundaries where the remaining partial packet is sent with no hardware header. When the buffer with a partial packet is of less number of octets than the value of
hard_header_lenthe buffer is discarded by the usbnet module.With AX88772B this can be reproduced by using ping with a packet size between 1965-1976.
The bug has been reported here:
https://bugzilla.kernel.org/show_bug.cgi?id=29082
This patch introduces the following changes:
- Removes the generichard_header_lencheck in therx_completefunction in the usbnet module.
- Introduces aETH_HLENcheck for skbs that are not cloned from within arx_fixupcallback.
- For safety ahard_header_lencheck is added to eachrx_fixupcallback function that could be affected by this change. These extra checks could possibly be removed by someone who has the hardware to test.The changes place full responsibility on the
rx_fixupcallback functions that clone skbs to only pass valid skbs to theusbnet_skb_returnfunction.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Emil Goode <[email protected]>Reported-by Igor Gnatenko <[email protected]>Great work! Looks good to me.
Thank you :)
Quoted 28 lines
Just a couple of questions:
Quoted 26 lines
drivers/net/usb/qmi_wwan.c +4
-4@@ -80,10 +80,10 @@ static int qmi_wwan_rx_fixup(struct usbnet *dev, struct sk_buff *skb) {__be16 proto; -/* usbnet rx_complete guarantees that skb->len is at least -* hard_header_len, so we can inspect the dest address without -* checking skb->len -*/ +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +switch (skb->data[0 ] &0xf0 ) {case 0x40 : proto =htons (ETH_P_IP );drivers/net/usb/rndis_host.c +0
-0@@ -492,6 +492,10 @@ EXPORT_SYMBOL_GPL(rndis_unbind);*/ int rndis_rx_fixup (struct usbnet *dev,struct sk_buff *skb)
Quoted 8 lines
drivers/net/usb/rndis_host.c EXPORT_SYMBOL_GPL(rndis_unbind); · line 498
Quoted 5 lines
drivers/net/usb/rndis_host.c +4
-0{ +/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +Wouldn't it be better to test against
ETH_HLEN, since that is a constant and "obviously correct" in this case?
Some minidrivers change the default hard_header_len value so using it guarantees that the patch will not make any change to how the code is currently working. Using ETH_HLEN could be more informative about what the minidriver should check before passing skbs to usbnet_skb_return(). Then I think the comment should be changed as well. My intention was to not make any changes that affect how the code works for devices I cannot test, but I think either way is fine and if you insist on changing it let me know.
Quoted 27 lines
Quoted 27 lines
drivers/net/usb/usbnet.c +10
-6@@ -542,17 +542,19 @@ static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) }// else network stack removes extra byte if we forced a short packet -if (skb->len) { -/* all data was already cloned from skb inside the driver */ -if (dev->driver_info->flags &FLAG_MULTI_PACKET ) -dev_kfree_skb_any (skb); -else -usbnet_skb_return (dev, skb); +/* all data was already cloned from skb inside the driver */ +if (dev->driver_info->flags &FLAG_MULTI_PACKET ) + goto done; + +if (skb->len <ETH_HLEN ) { + dev->net->stats.rx_errors++; + dev->net->stats.rx_length_errors++; +netif_dbg (dev, rx_err, dev->net,"rx length %d\n" , skb->len); + }else { +usbnet_skb_return (dev, skb);return ; }
Quoted 11 lines
drivers/net/usb/usbnet.c static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) · line 560
Quoted 5 lines
drivers/net/usb/usbnet.c +0
-2-netif_dbg (dev, rx_err, dev->net,"drop\n" ); - dev->net->stats.rx_errors++; done:skb_queue_tail (&dev->done, skb); }At first glance I wondered where the
dev_kfree_skb_any(skb)went. But then I realized that you leave that to the commonrx_cleanuppath, using thedev->donequeue. Is that right? If so, then I guess it could use a bit of explaining in the commit message?
Yes I should have put a comment in the changelog about this. All skbs that are passed to rx_process have their state set to rx_cleanup and just because the skb was cloned doesn't mean that we should free the original in a different way. As it is I think we are acctually missing a call to usb_free_urb that is called on the common rx_cleanup path.
I will resend and add a comment about this.
Best regards,
Emil Goode
Bjørn Mork
maintainerQuoted 5 lines · Emil Goode
Yes I should have put a comment in the changelog about this. All skbs that are passed to
rx_processhave their state set torx_cleanupand just because the skb was cloned doesn't mean that we should free the original in a different way. As it is I think we are acctually missing a call tousb_free_urbthat is called on the commonrx_cleanuppath.
Yes, I wondered about that as well, thinking that this part actually should be a separate patch for net+stable.
But then I wondered how we could possibly have had a bug like that living here for so long, and the answer is we haven't. You don't want to free the URB. It is already resubmitted with a different skb as its buffer. The call to usb_free_urb in the rx_cleanup path is there only for the cases where the URB is not resubmitted. The rx_complete callback is controlling this by updating entry->urb as appropriate. So it will always be NULL if rx_process is called, and the call to usb_free_urb has no effect.
Rearranging this code to always take the same cleanup path is still a very nice cleanup IMHO.
Bjørn
From: Emil Goode
Quoted 10 lines
Quoted 9 lines
drivers/net/usb/ax88179_178a.c static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb) · line 1124
Quoted 6 lines
int
rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb){drivers/net/usb/ax88179_178a.c +4
-0+/* This check is no longer done by usbnet */ +if (skb->len < dev->net->hard_header_len) +return 0 ; +Wouldn't it be better to test against
ETH_HLEN, since that is a constant and "obviously correct" in this case?
Quoted 8 lines
Some minidrivers change the default
hard_header_lenvalue so using it guarantees that the patch will not make any change to how the code is currently working. UsingETH_HLENcould be more informative about what the minidriver should check before passing skbs tousbnet_skb_return(). Then I think the comment should be changed as well. My intention was to not make any changes that affect how the code works for devices I cannot test, but I think either way is fine and if you insist on changing it let me know.
I think that test is to ensure that the data passed to the mini-driver contains the ethernet frame encapsulation header (this typically contains the actual frame length and some flags) so that the minidriver won't read off the end of the usb data.
Any check for stupidly short ethernet frames would be later on. IIRC the absolute minimum 802.3 ethernet frame is 17 bytes (after frame padding has been stripped).
David