staging: gdm724x: check for overflow in gdm_lte_netif_rx()
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 14 Jun 2021 09:58:36 +0000 (12:58 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 14 Jun 2021 14:39:33 +0000 (16:39 +0200)
This code assumes that "len" is at least 62 bytes, but we need a check
to prevent a read overflow.

Fixes: 61e121047645 ("staging: gdm7240: adding LTE USB driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/YMcoTPsCYlhh2TQo@mwanda
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/gdm724x/gdm_lte.c

index d4dfaead25dac2ebfc8dd6bc50f9a652d154ff61..e390c924ec1c8fdb1bbe5264998193039a58cfcc 100644 (file)
@@ -611,10 +611,12 @@ static void gdm_lte_netif_rx(struct net_device *dev, char *buf,
                                                  * bytes (99,130,83,99 dec)
                                                  */
                        } __packed;
-                       void *addr = buf + sizeof(struct iphdr) +
-                               sizeof(struct udphdr) +
-                               offsetof(struct dhcp_packet, chaddr);
-                       ether_addr_copy(nic->dest_mac_addr, addr);
+                       int offset = sizeof(struct iphdr) +
+                                    sizeof(struct udphdr) +
+                                    offsetof(struct dhcp_packet, chaddr);
+                       if (offset + ETH_ALEN > len)
+                               return;
+                       ether_addr_copy(nic->dest_mac_addr, buf + offset);
                }
        }