The MAC supported by the aqc111 driver is very similar to the AX88179A. During the development of the driver for the AX88179A, the following issues in endianness, respectively alignment-handling were found, which are also present in the aqc111 driver: CHECK drivers/net/usb/aqc111.c drivers/net/usb/aqc111.c:1094:34: warning: incorrect type in argument 1 (different base types) drivers/net/usb/aqc111.c:1094:34: expected restricted __le64 const [usertype] *p drivers/net/usb/aqc111.c:1094:34: got unsigned long long [usertype] * drivers/net/usb/aqc111.c:1122:45: warning: incorrect type in argument 1 (different base types) drivers/net/usb/aqc111.c:1122:45: expected restricted __le64 const [usertype] *p drivers/net/usb/aqc111.c:1122:45: got unsigned long long [usertype] *[assigned] pkt_desc_ptr drivers/net/usb/aqc111.c:1235:22: warning: incorrect type in assignment (different base types) drivers/net/usb/aqc111.c:1235:22: expected unsigned long long [usertype] drivers/net/usb/aqc111.c:1235:22: got restricted __le64 [usertype] While sparse complains about lack of the use of __le64, these spots also incorrectly handle alignment. Fix these problems by introducing __le64 where necessary and additionally make use of get_unaligned_le64/ put_unalignged_le64(). The current code also incorrectly modifies the skb buffer without checking it was cloned, possibly corrupting a shared buffer. This issue is also fixed. Finally, also introduce a minimum lengthe check for packets as the packet length is received via a USB transfer and may be incorrect. Fixes: 361459cd9642 ("net: usb: aqc111: Implement RX data path") Fixes: 4a3576d2bcc7 ("net: usb: aqc111: Implement TX data path") Signed-off-by: Birger Koblitz --- The MAC supported by the aqc111 driver is very similar to the AX88179A. During the development of the driver for the AX88179A, the following issues in endianness-handling were found, which are also present in the aqc111 driver: CHECK drivers/net/usb/aqc111.c drivers/net/usb/aqc111.c:1094:34: warning: incorrect type in argument 1 (different base types) drivers/net/usb/aqc111.c:1094:34: expected restricted __le64 const [usertype] *p drivers/net/usb/aqc111.c:1094:34: got unsigned long long [usertype] * drivers/net/usb/aqc111.c:1122:45: warning: incorrect type in argument 1 (different base types) drivers/net/usb/aqc111.c:1122:45: expected restricted __le64 const [usertype] *p drivers/net/usb/aqc111.c:1122:45: got unsigned long long [usertype] *[assigned] pkt_desc_ptr drivers/net/usb/aqc111.c:1235:22: warning: incorrect type in assignment (different base types) drivers/net/usb/aqc111.c:1235:22: expected unsigned long long [usertype] ddrivers/net/usb/aqc111.c:1235:22: got restricted __le64 [usertype] Fix these problems and additionally also make sure that cloned skbs are always copied for expansion. Finally also a length-cleck on the minimum length of received packets is added. --- Changes in v2: - Do not use cast in desc_hdr = get_unaligned_le64((__le64 *)skb_tail_pointer(skb)); - Added packet-length check - Improved commit subject and description covering alignment and skb-cloned fixes - Link to v1: https://lore.kernel.org/r/20261117-aqc111-v1-1-27a54c4b54ca@birger-koblitz.de --- drivers/net/usb/aqc111.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index 12a99df77f0d332053852e44991188c690c4c0bc..ee7c8bb858458418048dc05defe4a642b6d05b05 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -1078,7 +1078,7 @@ static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) struct aqc111_data *aqc111_data = dev->driver_priv; struct sk_buff *new_skb = NULL; u32 pkt_total_offset = 0; - u64 *pkt_desc_ptr = NULL; + __le64 *pkt_desc_ptr = NULL; u32 start_of_descs = 0; u32 desc_offset = 0; /*RX Header Offset*/ u16 pkt_count = 0; @@ -1095,7 +1095,7 @@ static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) /* RX Descriptor Header */ skb_trim(skb, skb_len - sizeof(desc_hdr)); - desc_hdr = le64_to_cpup((u64 *)skb_tail_pointer(skb)); + desc_hdr = get_unaligned_le64(skb_tail_pointer(skb)); /* Check these packets */ desc_offset = (desc_hdr & AQ_RX_DH_DESC_OFFSET_MASK) >> @@ -1120,10 +1120,10 @@ static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) goto err; /* Get the first RX packet descriptor */ - pkt_desc_ptr = (u64 *)(skb->data + desc_offset); + pkt_desc_ptr = (__le64 *)(skb->data + desc_offset); while (pkt_count--) { - u64 pkt_desc = le64_to_cpup(pkt_desc_ptr); + u64 pkt_desc = get_unaligned_le64(pkt_desc_ptr); u32 pkt_len_with_padd = 0; u32 pkt_len = 0; @@ -1139,6 +1139,7 @@ static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) if (pkt_desc & AQ_RX_PD_DROP || !(pkt_desc & AQ_RX_PD_RX_OK) || + pkt_len < (ETH_HLEN + AQ_RX_HW_PAD) || pkt_len > (dev->hard_mtu + AQ_RX_HW_PAD)) { skb_pull(skb, pkt_len_with_padd); /* Next RX Packet Descriptor */ @@ -1224,7 +1225,8 @@ static struct sk_buff *aqc111_tx_fixup(struct usbnet *dev, struct sk_buff *skb, headroom = skb_headroom(skb); tailroom = skb_tailroom(skb); - if (!(headroom >= sizeof(tx_desc) && tailroom >= padding_size)) { + if (skb_cloned(skb) || + !(headroom >= sizeof(tx_desc) && tailroom >= padding_size)) { new_skb = skb_copy_expand(skb, sizeof(tx_desc), padding_size, flags); dev_kfree_skb_any(skb); @@ -1236,7 +1238,7 @@ static struct sk_buff *aqc111_tx_fixup(struct usbnet *dev, struct sk_buff *skb, skb_put_zero(skb, padding_size); /* Copy TX header */ tx_desc_ptr = skb_push(skb, sizeof(tx_desc)); - *tx_desc_ptr = cpu_to_le64(tx_desc); + put_unaligned_le64(tx_desc, tx_desc_ptr); usbnet_set_skb_tx_stats(skb, 1, 0); --- base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d change-id: 20261117-aqc111-b0cf408d776b Best regards, -- Birger Koblitz