]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: usb: aqc111: Fix out-of-bounds accesses in RX fixup
authorMarcin Kozlowski <marcinguy@gmail.com>
Wed, 6 Apr 2022 08:05:37 +0000 (10:05 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Apr 2022 07:19:37 +0000 (09:19 +0200)
[ Upstream commit afb8e246527536848b9b4025b40e613edf776a9d ]

aqc111_rx_fixup() contains several out-of-bounds accesses that can be
triggered by a malicious (or defective) USB device, in particular:

 - The metadata array (desc_offset..desc_offset+2*pkt_count) can be out of bounds,
   causing OOB reads and (on big-endian systems) OOB endianness flips.
 - A packet can overlap the metadata array, causing a later OOB
   endianness flip to corrupt data used by a cloned SKB that has already
   been handed off into the network stack.
 - A packet SKB can be constructed whose tail is far beyond its end,
   causing out-of-bounds heap data to be considered part of the SKB's
   data.

Found doing variant analysis. Tested it with another driver (ax88179_178a), since
I don't have a aqc111 device to test it, but the code looks very similar.

Signed-off-by: Marcin Kozlowski <marcinguy@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/usb/aqc111.c

index 7e44110746dd00f11382b9a03d8c56e724e00c59..68912e266826bc8eca7e50d0e88efa908b5d6ba9 100644 (file)
@@ -1102,10 +1102,15 @@ static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
        if (start_of_descs != desc_offset)
                goto err;
 
-       /* self check desc_offset from header*/
-       if (desc_offset >= skb_len)
+       /* self check desc_offset from header and make sure that the
+        * bounds of the metadata array are inside the SKB
+        */
+       if (pkt_count * 2 + desc_offset >= skb_len)
                goto err;
 
+       /* Packets must not overlap the metadata array */
+       skb_trim(skb, desc_offset);
+
        if (pkt_count == 0)
                goto err;