Skip to contentSkip to conversation

usbnet: fix bad header length bug

PATCH In review Emil Goode 5 participants 9 messages Feb 9, 2014 – Feb 11, 2014

Subsystems (5)
lore
Share & tools
lore

Emil Goode

author
#0 lore raw

PATCH v2 1/2 usbnet: fix bad header length bug

The AX88772B occasionally send rx packets that cross urb boundaries and 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. This is causing dropped packages and error messages in dmesg.

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 a new flag that enable minidrivers to disable the cleaning up of small partial packets with no hardware header. It is likely that other minidrivers will want to use this flag, currently the cx82310_eth is describing the same problem and solving it by setting the hard_header_len to 0. This patch also makes it more obvious to minidriver writers that the usbnet module is discarding small skbs, which I believe has caused some confusion.

---
v2: This patch solves the bug by introducing a new flag instead of
setting hard_header_len to 0. I realize that there are already a lot of flags but hard_header_len is used to calculate the mtu values in the usbnet_change_mtu, usbnet_probe functions and I believe it's better not to change it.

 drivers/net/usb/asix_devices.c |   10 ++++++----
 drivers/net/usb/usbnet.c       |    3 ++-
 include/linux/usb/usbnet.h     |    3 +++
 3 files changed, 11 insertions(+), 5 deletions(-)
drivers/net/usb/asix_devices.c +6 -4
index 9765a7d..7ced4ed 100644
@@ -891,7 +891,8 @@ static const struct driver_info ax88772_info = {
 	.status = asix_status,
 	.link_reset = ax88772_link_reset,
 	.reset = ax88772_reset,
-	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET,
+	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
+		 FLAG_MULTI_PACKET | FLAG_PARTIAL_RX_PKT,
 	.rx_fixup = asix_rx_fixup_common,
 	.tx_fixup = asix_tx_fixup,
 };
@@ -904,7 +905,7 @@ static const struct driver_info ax88772b_info = {
 	.link_reset = ax88772_link_reset,
 	.reset = ax88772_reset,
 	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
-	         FLAG_MULTI_PACKET,
+		 FLAG_MULTI_PACKET | FLAG_PARTIAL_RX_PKT,
 	.rx_fixup = asix_rx_fixup_common,
 	.tx_fixup = asix_tx_fixup,
 	.data = FLAG_EEPROM_MAC,
@@ -917,7 +918,8 @@ static const struct driver_info ax88178_info = {
 	.status = asix_status,
 	.link_reset = ax88178_link_reset,
 	.reset = ax88178_reset,
-	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR,
+	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
+		 FLAG_PARTIAL_RX_PKT,
 	.rx_fixup = asix_rx_fixup_common,
 	.tx_fixup = asix_tx_fixup,
 };
@@ -939,7 +941,7 @@ static const struct driver_info hg20f9_info = {
 	.link_reset = ax88772_link_reset,
 	.reset = ax88772_reset,
 	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
-	         FLAG_MULTI_PACKET,
+		 FLAG_MULTI_PACKET | FLAG_PARTIAL_RX_PKT,
 	.rx_fixup = asix_rx_fixup_common,
 	.tx_fixup = asix_tx_fixup,
 	.data = FLAG_EEPROM_MAC,
drivers/net/usb/usbnet.c +2 -1
index 4671da7..a1e6964 100644
@@ -574,7 +574,8 @@ static void rx_complete (struct urb *urb)
 	switch (urb_status) {
 	/* success */
 	case 0:
-		if (skb->len < dev->net->hard_header_len) {
+		if (skb->len < dev->net->hard_header_len &&
+		    !(dev->driver_info->flags & FLAG_PARTIAL_RX_PKT)) {
 			state = rx_cleanup;
 			dev->net->stats.rx_errors++;
 			dev->net->stats.rx_length_errors++;
include/linux/usb/usbnet.h +3 -0
index e303eef..818da3b 100644
@@ -117,6 +117,9 @@ struct driver_info {
 #define FLAG_RX_ASSEMBLE	0x4000	/* rx packets may span >1 frames */
 #define FLAG_NOARP		0x8000	/* device can't do ARP */
 
+/* Disables cleanup of small partial rx packets with no hardware header */
+#define FLAG_PARTIAL_RX_PKT    0x10000
+
 	/* init device ... can sleep, or cause probe() failure */
 	int	(*bind)(struct usbnet *, struct usb_interface *);
 
Signature · 1 line
1.7.10.4
author
#1 lore raw

PATCH 2/2 net: asix: add missing flag to struct driver_info

The struct driver_info ax88178_info is assigned the function asix_rx_fixup_common as it's rx_fixup callback. This means that FLAG_MULTI_PACKET must be set as this function is cloning the data and calling usbnet_skb_return. Not setting this flag leads to usbnet_skb_return beeing called a second time from within the rx_process function in the usbnet module.

---
 drivers/net/usb/asix_devices.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/usb/asix_devices.c +1 -1
index 7ced4ed..19d8821 100644
@@ -919,7 +919,7 @@ static const struct driver_info ax88178_info = {
 	.link_reset = ax88178_link_reset,
 	.reset = ax88178_reset,
 	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
-		 FLAG_PARTIAL_RX_PKT,
+		 FLAG_MULTI_PACKET | FLAG_PARTIAL_RX_PKT,
 	.rx_fixup = asix_rx_fixup_common,
 	.tx_fixup = asix_tx_fixup,
 };
Signature · 1 line
1.7.10.4
#2 lore raw
In reply to Emil Goode
Quoted 9 lines · Emil Goode

The AX88772B occasionally send rx packets that cross urb boundaries and 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. This is causing dropped packages and error messages in dmesg.

This can be reproduced by using ping with a packet size between 1965-1976.

Well, then how about simply removing the check?
It seems to have outlived its usefulness.

Regards
Oliver

author
#3 lore raw
Quoted 8 lines · Oliver Neukum
Quoted 7 lines · Emil Goode

The AX88772B occasionally send rx packets that cross urb boundaries and 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. This is causing dropped packages and error messages in dmesg.

Quoted 10 lines
Quoted 2 lines

This can be reproduced by using ping with a packet size between 1965-1976.

Well, then how about simply removing the check?
It seems to have outlived its usefulness.

Regards
Oliver

I did consider that and I think it is probably the best thing to do. However, I think the removal of the check could have negative effects on the other minidrivers, at least the qmi_wwan minidriver explicitly states that it is depending on this check to be made in rx_complete().

For safety the check could be added at the top of the rx_fixup callback of the affected minidrivers.

There are devices that depend on the usbnet module that do not have a rx_fixup callback assigned to it's driver_info struct, the check could be added for these in the rx_process function.

This led me to think it would be a lot of noise about a small check :)

My conclusion is that 12 rx_fixup callbacks might need the check to be added. There are 18 driver_info structs with no rx_fixup callback assigned, these devices might need the check to be added to the rx_process function.

Patches could be sent out to notify the affected minidrivers of the change and hopefully someone has the hardware to test if it's necessary to add the check to the minidriver?

I'm happy to do this if it seem like a good idea.

Best regards,

Emil Goode

#4 lore raw
Quoted 20 lines · Emil Goode
Quoted 8 lines · Oliver Neukum
Quoted 7 lines · Emil Goode

The AX88772B occasionally send rx packets that cross urb boundaries and 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. This is causing dropped packages and error messages in dmesg.

Quoted 10 lines
Quoted 2 lines

This can be reproduced by using ping with a packet size between 1965-1976.

Well, then how about simply removing the check?
It seems to have outlived its usefulness.

Regards
Oliver

Quoted 4 lines

I did consider that and I think it is probably the best thing to do. However, I think the removal of the check could have negative effects on the other minidrivers, at least the qmi_wwan minidriver explicitly states that it is depending on this check to be made in rx_complete().

<censored>. Oh well. But how about merging it with FLAG_MULTI_PACKET? I really don't want to add more flags. There is a point where enough flags make absurd having a common code. We are closing in on that point.

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

RnJvbTogT2xpdmVyIE5ldWt1bQ0KPiA8Y2Vuc29yZWQ+LiBPaCB3ZWxsLiBCdXQgaG93IGFib3V0 IG1lcmdpbmcgaXQgd2l0aCBGTEFHX01VTFRJX1BBQ0tFVD8NCj4gSSByZWFsbHkgZG9uJ3Qgd2Fu dCB0byBhZGQgbW9yZSBmbGFncy4gVGhlcmUgaXMgYSBwb2ludCB3aGVyZSBlbm91Z2gNCj4gZmxh Z3MgbWFrZSBhYnN1cmQgaGF2aW5nIGEgY29tbW9uIGNvZGUuIFdlIGFyZSBjbG9zaW5nIGluIG9u IHRoYXQgcG9pbnQuDQoNCkFueSBzdWItZHJpdmVyIHRoYXQgc3VwcG9ydHMgbXVsdGktcGFja2V0 IGVpdGhlciBoYXMgdG8gdXNlIHN0dXBpZGx5DQpsb25nIFVSQiBhbmQvb3Igc2V0IHRoZSByeF91 cmJfc2l6ZSB0byBhIG11bHRpcGxlIG9mIHRoZSB1c2IgdHJhbnNmZXINCnNpemUuDQoNCkl0IHdp bGwgYWxzbyBoYXZlIHRvIGRldGVjdCBpbGxlZ2FsIHNob3J0IGhlYWRlcnMuDQoNCkFjdHVhbGx5 IGl0IG1pZ2h0IGJlIHdvcnRoIGRvdWJsZS1jaGVja2luZyB0aGUgZW5jYXBzdWxhdGlvbnMgdXNl ZC4NCklJUkMgdGhlIGF4ODgxNzlfMTc4YSB1c2VzIGRpZmZlcmVudCBoZWFkZXJzIGZvciB0eCBh bmQgcnguDQpTbyB0aGVyZSBtaWdodCBiZSBzb21lIHRoYXQgc3VwcG9ydCBtdWx0aS1wYWNrZXQg YnV0IHN0aWxsIGhhdmUNCmEgc2hvcnQoaXNoKSBsaW1pdCBvbiB0aGUgYnVsayByZWNlaXZlIHNp emUgKGJlZm9yZSB0aGUgc2hvcnQgZnJhZ21lbnQpLg0KDQpJJ20gc2F0IGF0IHRoZSB3cm9uZyBk ZXNrIHRvIGxvb2sgYXQgdGhlIGNvZGUuLi4NCg0KCURhdmlkDQoNCg==
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
In reply to Oliver Neukum
Quoted 11 lines · Oliver Neukum
Quoted 10 lines · Emil Goode
Quoted 7 lines · Oliver Neukum

Well, then how about simply removing the check?
It seems to have outlived its usefulness.

Regards
Oliver

Quoted 6 lines
Quoted 4 lines

I did consider that and I think it is probably the best thing to do. However, I think the removal of the check could have negative effects on the other minidrivers, at least the qmi_wwan minidriver explicitly states that it is depending on this check to be made in rx_complete().

<censored>.

No need to do that. I had the exact same reaction myself :-)

Anyway, I put that comment there mostly as a note to myself why the check would be redundant at that point. I don't see any problem with removing the generic check in usbnet as long as we add similar checks whereever they are needed, like in qmi_wwan.

Note that usbnet_skb_return will be one of those places. It calls eth_type_trans() on the skb, so it should verify that the length is at least ETH_HLEN first.

Quoted 3 lines

Oh well. But how about merging it with FLAG_MULTI_PACKET?
I really don't want to add more flags. There is a point where enough flags make absurd having a common code. We are closing in on that point.

Agreed. I would even say we are past that point...

Bjørn

author
#7 lore raw
Quoted 17 lines · Bjørn Mork
Quoted 16 lines · Oliver Neukum
Quoted 14 lines · Emil Goode
Quoted 7 lines · Oliver Neukum

Well, then how about simply removing the check?
It seems to have outlived its usefulness.

Regards
Oliver

I did consider that and I think it is probably the best thing to do. However, I think the removal of the check could have negative effects on the other minidrivers, at least the qmi_wwan minidriver explicitly states that it is depending on this check to be made in rx_complete().

Quoted 8 lines
Quoted 1 line

<censored>.

No need to do that. I had the exact same reaction myself :-)

Anyway, I put that comment there mostly as a note to myself why the check would be redundant at that point. I don't see any problem with removing the generic check in usbnet as long as we add similar checks whereever they are needed, like in qmi_wwan.

I think it could be worth the trouble of removing the generic check in the usbnet module.

I believe that if you define your own rx_fixup callback then the usbnet module should not make it's own assumptions on what packets to discard.

Since the checks that need to be added in various places are all in the same subsystem I think it could be done in as little as one patch?

Quoted 9 lines

Note that usbnet_skb_return will be one of those places. It calls eth_type_trans() on the skb, so it should verify that the length is at least ETH_HLEN first.

Quoted 3 lines

Oh well. But how about merging it with FLAG_MULTI_PACKET?
I really don't want to add more flags. There is a point where enough flags make absurd having a common code. We are closing in on that point.

Agreed. I would even say we are past that point...

If nobody have any objections I will try removing the generic check and introduce checks where nessecary.

Best regards,

Emil Goode

#8 lore raw
Quoted 2 lines · Emil Goode

Since the checks that need to be added in various places are all in the same subsystem I think it could be done in as little as one patch?

Yes, please definitely. Best for bisectability.

Quoted 2 lines

If nobody have any objections I will try removing the generic check and introduce checks where nessecary.

Thank you

Regards
Oliver