hso_net_start_xmit() copies skb->len bytes into odev->mux_bulk_tx_buf, which is a fixed MUX_BULK_TX_BUF_SIZE (2048) allocation made by hso_create_net_device(), and passes the same length to usb_fill_bulk_urb(). Nothing bounds skb->len today: the net device does not set max_mtu, and even with max_mtu set the core does not clamp the length of the frames handed to ndo_start_xmit(), so AF_PACKET with PACKET_VNET_HDR, tpacket_snd() with a vnet header and an IPv4 route MTU metric above the device MTU can all deliver larger skbs. Cap the MTU at the buffer size and drop oversized frames in hso_net_start_xmit() instead of copying them past the end of the buffer. Fixes: 72dc1c096c70 ("HSO: add option hso driver") Cc: stable@vger.kernel.org Signed-off-by: Aibing Chen --- v2: - also drop frames larger than MUX_BULK_TX_BUF_SIZE in hso_net_start_xmit() with tx_dropped accounting: the max_mtu cap alone does not bound skb->len, as pointed out in the netdev review. drivers/net/usb/hso.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index 71caa3764..0df1d19cc 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -769,6 +769,18 @@ static netdev_tx_t hso_net_start_xmit(struct sk_buff *skb, struct hso_net *odev = netdev_priv(net); int result; + /* + * max_mtu only limits the MTU userspace can configure; the core does + * not clamp skb->len to it (AF_PACKET with PACKET_VNET_HDR, tpacket_snd() + * with a vnet header and a route MTU metric above the device MTU can all + * deliver larger frames), so drop anything that does not fit here. + */ + if (unlikely(skb->len > MUX_BULK_TX_BUF_SIZE)) { + net->stats.tx_dropped++; + kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_BIG); + return NETDEV_TX_OK; + } + /* Tell the kernel, "No more frames 'til we are done with this one." */ netif_stop_queue(net); if (hso_get_activity(odev->parent) == -EAGAIN) { @@ -2393,6 +2405,7 @@ static void hso_net_init(struct net_device *net) net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; net->type = ARPHRD_NONE; net->mtu = DEFAULT_MTU - 14; + net->max_mtu = MUX_BULK_TX_BUF_SIZE - 14; net->tx_queue_len = 10; net->ethtool_ops = &ops;