mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aibing Chen <chenaibing@cmss.chinamobile.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: linux-usb@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] net: hso: cap the MTU and drop oversized frames
Date: Fri, 20 Nov 2026 09:23:09 +0800	[thread overview]
Message-ID: <20261120012309.19-1-chenaibing@cmss.chinamobile.com> (raw)
In-Reply-To: <20261116014904.556-1-chenaibing@cmss.chinamobile.com>

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 <chenaibing@cmss.chinamobile.com>
---
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;
 



  parent reply	other threads:[~2026-11-20  1:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  1:49 [PATCH] net: hso: cap the MTU to the mux tx buffer size Aibing Chen
2026-11-16  1:53 ` netdev-bot+sinfo
2026-11-16  2:58   ` Aibing Chen
2026-11-19 19:50 ` netdev-bot+sashiko
2026-11-20  1:23 ` Aibing Chen [this message]
2026-11-20  1:26   ` [PATCH v2] net: hso: cap the MTU and drop oversized frames netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120012309.19-1-chenaibing@cmss.chinamobile.com \
    --to=chenaibing@cmss.chinamobile.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®