]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usbnet: limit max_mtu based on device's hard_mtu
authorLaurent Vivier <lvivier@redhat.com>
Mon, 19 Jan 2026 07:55:18 +0000 (08:55 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 30 Jan 2026 09:27:37 +0000 (10:27 +0100)
[ Upstream commit c7159e960f1472a5493ac99aff0086ab1d683594 ]

The usbnet driver initializes net->max_mtu to ETH_MAX_MTU before calling
the device's bind() callback. When the bind() callback sets
dev->hard_mtu based the device's actual capability (from CDC Ethernet's
wMaxSegmentSize descriptor), max_mtu is never updated to reflect this
hardware limitation).

This allows userspace (DHCP or IPv6 RA) to configure MTU larger than the
device can handle, leading to silent packet drops when the backend sends
packet exceeding the device's buffer size.

Fix this by limiting net->max_mtu to the device's hard_mtu after the
bind callback returns.

See https://gitlab.com/qemu-project/qemu/-/issues/3268 and
    https://bugs.passt.top/attachment.cgi?bugid=189

Fixes: f77f0aee4da4 ("net: use core MTU range checking in USB NIC drivers")
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Link: https://bugs.passt.top/show_bug.cgi?id=189
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Link: https://patch.msgid.link/20260119075518.2774373-1-lvivier@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/usb/usbnet.c

index e6a1864f03f948c7d3fbbbf0bafeac78ee418bb4..e41649365efffc0fa47bdf11ee6c2e5f34dd0081 100644 (file)
@@ -1799,9 +1799,12 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
                if ((dev->driver_info->flags & FLAG_NOARP) != 0)
                        net->flags |= IFF_NOARP;
 
-               /* maybe the remote can't receive an Ethernet MTU */
-               if (net->mtu > (dev->hard_mtu - net->hard_header_len))
-                       net->mtu = dev->hard_mtu - net->hard_header_len;
+               if (net->max_mtu > (dev->hard_mtu - net->hard_header_len))
+                       net->max_mtu = dev->hard_mtu - net->hard_header_len;
+
+               if (net->mtu > net->max_mtu)
+                       net->mtu = net->max_mtu;
+
        } else if (!info->in || !info->out)
                status = usbnet_get_endpoints (dev, udev);
        else {