The hardware usually takes care that
- a packet is no larger than the available buffer
- has at least a FCS checksum of 4 bytes
Nevertheless be cautious and improve the existing
packet check. Just in case ...
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/22884
Signed-off-by: Robert Marko <robimarko@gmail.com>
packet = &ctrl->rx_data[ring].packet[slot];
len = packet->len;
- if (!len) {
- netdev_err(dev, "empty packet received\n");
+ if (len < ETH_FCS_LEN || len > RING_BUFFER) {
+ netdev_err(dev, "invalid packet with %d bytes received\n", len);
break;
} else if (!dsa) {
- len -= 4;
+ len -= ETH_FCS_LEN;
}
skb = netdev_alloc_skb_ip_align(dev, len);