Skip to content

Commit f8ebb3a

Browse files
j-alonsoPaolo Abeni
authored andcommitted
net: usb: ax88179_178a: Fix packet receiving
This patch corrects packet receiving in ax88179_rx_fixup. - problem observed: ifconfig shows allways a lot of 'RX Errors' while packets are received normally. This occurs because ax88179_rx_fixup does not recognise properly the usb urb received. The packets are normally processed and at the end, the code exits with 'return 0', generating RX Errors. (pkt_cnt==-2 and ptk_hdr over field rx_hdr trying to identify another packet there) This is a usb urb received by "tcpdump -i usbmon2 -X" on a little-endian CPU: 0x0000: eeee f8e3 3b19 87a0 94de 80e3 daac 0800 ^ packet 1 start (pkt_len = 0x05ec) ^^^^ IP alignment pseudo header ^ ethernet packet start last byte ethernet packet v padding (8-bytes aligned) vvvv vvvv 0x05e0: c92d d444 1420 8a69 83dd 272f e82b 9811 0x05f0: eeee f8e3 3b19 87a0 94de 80e3 daac 0800 ... ^ packet 2 0x0be0: eeee f8e3 3b19 87a0 94de 80e3 daac 0800 ... 0x1130: 9d41 9171 8a38 0ec5 eeee f8e3 3b19 87a0 ... 0x1720: 8cfc 15ff 5e4c e85c eeee f8e3 3b19 87a0 ... 0x1d10: ecfa 2a3a 19ab c78c eeee f8e3 3b19 87a0 ... 0x2070: eeee f8e3 3b19 87a0 94de 80e3 daac 0800 ... ^ packet 7 0x2120: 7c88 4ca5 5c57 7dcc 0d34 7577 f778 7e0a 0x2130: f032 e093 7489 0740 3008 ec05 0000 0080 ====1==== ====2==== hdr_off ^ pkt_len = 0x05ec ^^^^ AX_RXHDR_*=0x00830 ^^^^ ^ pkt_len = 0 ^^^^ AX_RXHDR_DROP_ERR=0x80000000 ^^^^ ^ 0x2140: 3008 ec05 0000 0080 3008 5805 0000 0080 0x2150: 3008 ec05 0000 0080 3008 ec05 0000 0080 0x2160: 3008 5803 0000 0080 3008 c800 0000 0080 ===11==== ===12==== ===13==== ===14==== 0x2170: 0000 0000 0e00 3821 ^^^^ ^^^^ rx_hdr ^^^^ pkt_cnt=14 ^^^^ hdr_off=0x2138 ^^^^ ^^^^ padding The dump shows that pkt_cnt is the number of entrys in the per-packet metadata. It is "2 * packet count". Each packet have two entrys. The first have a valid value (pkt_len and AX_RXHDR_*) and the second have a dummy-header 0x80000000 (pkt_len=0 with AX_RXHDR_DROP_ERR). Why exists dummy-header for each packet?!? My guess is that this was done probably to align the entry for each packet to 64-bits and maintain compatibility with old firmware. There is also a padding (0x00000000) before the rx_hdr to align the end of rx_hdr to 64-bit. Note that packets have a alignment of 64-bits (8-bytes). This patch assumes that the dummy-header and the last padding are optional. So it preserves semantics and recognises the same valid packets as the current code. This patch was made using only the dumpfile information and tested with only one device: 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet Fixes: 57bc3d3 ("net: usb: ax88179_178a: Fix out-of-bounds accesses in RX fixup") Fixes: e2ca90c ("ax88179_178a: ASIX AX88179_178A USB 3.0/2.0 to gigabit ethernet adapter driver") Signed-off-by: Jose Alonso <[email protected]> Acked-by: Paolo Abeni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 050133e commit f8ebb3a

File tree

1 file changed

+76
-25
lines changed

1 file changed

+76
-25
lines changed

drivers/net/usb/ax88179_178a.c

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,42 @@ static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
14721472
* are bundled into this buffer and where we can find an array of
14731473
* per-packet metadata (which contains elements encoded into u16).
14741474
*/
1475+
1476+
/* SKB contents for current firmware:
1477+
* <packet 1> <padding>
1478+
* ...
1479+
* <packet N> <padding>
1480+
* <per-packet metadata entry 1> <dummy header>
1481+
* ...
1482+
* <per-packet metadata entry N> <dummy header>
1483+
* <padding2> <rx_hdr>
1484+
*
1485+
* where:
1486+
* <packet N> contains pkt_len bytes:
1487+
* 2 bytes of IP alignment pseudo header
1488+
* packet received
1489+
* <per-packet metadata entry N> contains 4 bytes:
1490+
* pkt_len and fields AX_RXHDR_*
1491+
* <padding> 0-7 bytes to terminate at
1492+
* 8 bytes boundary (64-bit).
1493+
* <padding2> 4 bytes to make rx_hdr terminate at
1494+
* 8 bytes boundary (64-bit)
1495+
* <dummy-header> contains 4 bytes:
1496+
* pkt_len=0 and AX_RXHDR_DROP_ERR
1497+
* <rx-hdr> contains 4 bytes:
1498+
* pkt_cnt and hdr_off (offset of
1499+
* <per-packet metadata entry 1>)
1500+
*
1501+
* pkt_cnt is number of entrys in the per-packet metadata.
1502+
* In current firmware there is 2 entrys per packet.
1503+
* The first points to the packet and the
1504+
* second is a dummy header.
1505+
* This was done probably to align fields in 64-bit and
1506+
* maintain compatibility with old firmware.
1507+
* This code assumes that <dummy header> and <padding2> are
1508+
* optional.
1509+
*/
1510+
14751511
if (skb->len < 4)
14761512
return 0;
14771513
skb_trim(skb, skb->len - 4);
@@ -1485,51 +1521,66 @@ static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
14851521
/* Make sure that the bounds of the metadata array are inside the SKB
14861522
* (and in front of the counter at the end).
14871523
*/
1488-
if (pkt_cnt * 2 + hdr_off > skb->len)
1524+
if (pkt_cnt * 4 + hdr_off > skb->len)
14891525
return 0;
14901526
pkt_hdr = (u32 *)(skb->data + hdr_off);
14911527

14921528
/* Packets must not overlap the metadata array */
14931529
skb_trim(skb, hdr_off);
14941530

1495-
for (; ; pkt_cnt--, pkt_hdr++) {
1531+
for (; pkt_cnt > 0; pkt_cnt--, pkt_hdr++) {
1532+
u16 pkt_len_plus_padd;
14961533
u16 pkt_len;
14971534

14981535
le32_to_cpus(pkt_hdr);
14991536
pkt_len = (*pkt_hdr >> 16) & 0x1fff;
1537+
pkt_len_plus_padd = (pkt_len + 7) & 0xfff8;
15001538

1501-
if (pkt_len > skb->len)
1539+
/* Skip dummy header used for alignment
1540+
*/
1541+
if (pkt_len == 0)
1542+
continue;
1543+
1544+
if (pkt_len_plus_padd > skb->len)
15021545
return 0;
15031546

15041547
/* Check CRC or runt packet */
1505-
if (((*pkt_hdr & (AX_RXHDR_CRC_ERR | AX_RXHDR_DROP_ERR)) == 0) &&
1506-
pkt_len >= 2 + ETH_HLEN) {
1507-
bool last = (pkt_cnt == 0);
1508-
1509-
if (last) {
1510-
ax_skb = skb;
1511-
} else {
1512-
ax_skb = skb_clone(skb, GFP_ATOMIC);
1513-
if (!ax_skb)
1514-
return 0;
1515-
}
1516-
ax_skb->len = pkt_len;
1517-
/* Skip IP alignment pseudo header */
1518-
skb_pull(ax_skb, 2);
1519-
skb_set_tail_pointer(ax_skb, ax_skb->len);
1520-
ax_skb->truesize = pkt_len + sizeof(struct sk_buff);
1521-
ax88179_rx_checksum(ax_skb, pkt_hdr);
1548+
if ((*pkt_hdr & (AX_RXHDR_CRC_ERR | AX_RXHDR_DROP_ERR)) ||
1549+
pkt_len < 2 + ETH_HLEN) {
1550+
dev->net->stats.rx_errors++;
1551+
skb_pull(skb, pkt_len_plus_padd);
1552+
continue;
1553+
}
15221554

1523-
if (last)
1524-
return 1;
1555+
/* last packet */
1556+
if (pkt_len_plus_padd == skb->len) {
1557+
skb_trim(skb, pkt_len);
15251558

1526-
usbnet_skb_return(dev, ax_skb);
1559+
/* Skip IP alignment pseudo header */
1560+
skb_pull(skb, 2);
1561+
1562+
skb->truesize = SKB_TRUESIZE(pkt_len_plus_padd);
1563+
ax88179_rx_checksum(skb, pkt_hdr);
1564+
return 1;
15271565
}
15281566

1529-
/* Trim this packet away from the SKB */
1530-
if (!skb_pull(skb, (pkt_len + 7) & 0xFFF8))
1567+
ax_skb = skb_clone(skb, GFP_ATOMIC);
1568+
if (!ax_skb)
15311569
return 0;
1570+
skb_trim(ax_skb, pkt_len);
1571+
1572+
/* Skip IP alignment pseudo header */
1573+
skb_pull(ax_skb, 2);
1574+
1575+
skb->truesize = pkt_len_plus_padd +
1576+
SKB_DATA_ALIGN(sizeof(struct sk_buff));
1577+
ax88179_rx_checksum(ax_skb, pkt_hdr);
1578+
usbnet_skb_return(dev, ax_skb);
1579+
1580+
skb_pull(skb, pkt_len_plus_padd);
15321581
}
1582+
1583+
return 0;
15331584
}
15341585

15351586
static struct sk_buff *

0 commit comments

Comments
 (0)