]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: eth: harden receive path 22884/head
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Fri, 10 Apr 2026 20:02:59 +0000 (22:02 +0200)
committerRobert Marko <robimarko@gmail.com>
Fri, 24 Apr 2026 07:47:04 +0000 (09:47 +0200)
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>
target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c

index ccad659d4e0311da9df93d351132f5bcbdfe49f1..599c5cf29c09a2efd31ebf9dbf855f359bf4dcdb 100644 (file)
@@ -1022,11 +1022,11 @@ static int rteth_hw_receive(struct net_device *dev, int ring, int budget)
                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);