🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21088

Re: [PATCH net v5 3/5] net: qualcomm: rmnet: Fix MTU underflow and clamp to the maximum packet size

#21088
From: Simon Horman
Date: Mon, 23 Nov 2026 14:41
52 lines
9985 bytes
On Mon, Nov 16, 2026 at 10:07:36PM -0800, Subash Abhinov Kasiviswanathan wrote:
> The MTU helpers subtract the egress headroom from the real device MTU
> using unsigned arithmetic. A real device MTU smaller than the headroom
> underflows and results in a huge target MTU instead of an error.
> 
> Additionally, a real device with a jumbo MTU makes the creation of the
> first rmnet device fail since the unclamped value exceeds
> RMNET_MAX_PACKET_SIZE, while resizing an existing device clamps it.
> 
> Add a helper which computes the largest MTU usable on top of the real
> device for a data format, rejects real device MTUs below the headroom
> before doing any arithmetic and clamps the result to
> RMNET_MAX_PACKET_SIZE. Use it for both new and existing devices and add
> the same underflow check to the other helpers.
> 
> Fixes: b7f5eb6ba21b ("net: qualcomm: rmnet: Update rmnet device MTU based on real device")
> Co-developed-by: Sean Tranchetti <sean.tranchetti@oss.qualcomm.com>
> Signed-off-by: Sean Tranchetti <sean.tranchetti@oss.qualcomm.com>
> Signed-off-by: Subash Abhinov Kasiviswanathan <subash.a.kasiviswanathan@oss.qualcomm.com>
> ---
>  .../net/ethernet/qualcomm/rmnet/rmnet_vnd.c   | 58 +++++++++++++------
>  1 file changed, 41 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
> index 984c66bee863..2f3fefe58bce 100644
> --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
> +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
> @@ -80,6 +80,20 @@ static int rmnet_vnd_headroom(u32 data_format)
>  	return headroom;
>  }
>  
> +/* Largest MTU an rmnet device can use on top of real_dev for the given data
> + * format, or -EINVAL if real_dev cannot even fit the headers.
> + */
> +static int rmnet_vnd_target_mtu(struct net_device *real_dev, u32 data_format)
> +{
> +	u32 headroom;
> +
> +	headroom = rmnet_vnd_headroom(data_format);
> +	if (real_dev->mtu < headroom)
> +		return -EINVAL;
> +
> +	return min_t(int, real_dev->mtu - headroom, RMNET_MAX_PACKET_SIZE);
> +}

real_dev->mtu - headroom is guaranteed to be non-negative.
And RMNET_MAX_PACKET_SIZE is also non-negative.

I believe min() is sufficient here. And if so, it is preferred.

...
Technical Details
Message-ID: <20261123144139.GE31322@horms.kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369489-linux-kernel-netdev=dewy.ru
References: <20261117060737.2764327-1-subash.a.kasiviswanathan@oss.qualcomm.com> <20261117060737.2764327-4-subash.a.kasiviswanathan@oss.qualcomm.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369489-linux-kernel-netdev=dewy.ru
From: horms@kernel.org (Simon Horman)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v5 3/5] net: qualcomm: rmnet: Fix MTU underflow and
 clamp to the maximum packet size
Date: Mon, 23 Nov 2026 14:41:39 +0000
Organization: Usenet Network
Message-ID: <20261123144139.GE31322@horms.kernel.org>
References: <20261117060737.2764327-1-subash.a.kasiviswanathan@oss.qualcomm.com>
 <20261117060737.2764327-4-subash.a.kasiviswanathan@oss.qualcomm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="3903958"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:MoemxNVRuJyB4jUd1Z4YeyvSESA= sha256:MMvQxMtiL/H08s+eevUaxdlVMjoiiu6Vt6g9c5Co1iA=
	sha1:ULZKPXjYYMjcIrS2ney6zceHmdU= sha256:MWPIk1OhJe3+2P6WXzJ7s+2EAtsPXH5LE14ypJB32sI=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 44C91125DB9; Mon, 23 Nov 2026 17:42:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id r6Nyw94lLMV8;
	Mon, 23 Nov 2026 17:42:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369489-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id C6005125DBA; Mon, 23 Nov 2026 17:41:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id DA8EE299FD; Mon, 23 Nov 2026 14:41:49 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1795444904;
	b=5oBTBSv2cuPULe6t9XRETdEwUgZR/JpMcrA3VK4LDY6+8qCYZqyULYPDTy/4L+g96x+v
	 l717CrLJXNhwg0M/1Phy7NpRJZoGV0XTTQ6+46WnGyTNShOjiBnVvtGuJo1oIWEPG9DIP
	 zdKXcGoJinsp4SYxt4fVZXjhrBGYGBEYgAu55WSZwvbI6hJBNKuedAgQNrKtoT6CzuhPJ
	 XQeQnZ6uWwSsU420JfinDzS4Xtfsvg4k4XyV7pxXkcKpq7xHkI3mWkCLBtS75aS0UfRdf
	 I+MlLZ5EooOom3UR/AwwSKlYuaCZydePIBlq9C8rbNDAXJ5NL6txCoGk7SvA3lZxZFA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795444904;
	h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=iSBki08s6Y37g2ektwoZx+CNumkLlun7bvIhU3NlRbU=;
	b=SliU/Hsn2dwfNSAYPiOdY8e5RwtEpdLMOnhZgNgFN7Kp4/fVRTo/3PPkxEgoo8V2JeOV
	 eUvtDG8YULyLY4954yOIE564pamV0OL8zfYSg3h7kUt6e30zpIliaM1TJaHRaCTyEI1bM
	 wpPCtI2Ov7/Vvu4/sW7B8iIMK68Hnp/lZMl3VEBq1+9D7hs6O/sPoVO/LNzQKUCABQ0mK
	 tkc6wWSiRtD6xwwrm1iEfdYg0S3/2McyA8wYL7ZhNMszuXmsA3zF6g2T6LgvLFxgib5TA
	 CQlUysP/MNs1RlqEkXtBTbxzGR7YFWps/XqqZZ85pYIiOjY9PIuwQnQZnKiri4KnCtg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EHuGOoU2;
	arc=fail smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B096606A333;
	Mon, 23 Nov 2026 14:41:44 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EHuGOoU2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795444903;
	b=ja5VZvQtkkk8k35poedb02MO/GpEszPGj944k/eLzUfUSv23yraO7qqOmHgMal+Rak6o
	 HTuHlpYI+WCcMMVYTsRyt0uXEmavQk4FO0T9wSkhHPvoOrLLIfcvsfTBLXcSIwNa90mgv
	 Ny+LfkvV4dQsFYeyjVEUfrLDKuvzfga5BcrLKq0jismktJjxvVBMVl0H3bPRvG5j0MrNv
	 9tXicLocNYRej7DrV6lrZ0+3VGsPE5BcBaQ/0kBwJQE9+BA/9oPcQYIG3MPLb9rBJxsxk
	 hYZEh8ScAH1Ev5W4DzylqeLzHgGxWlT+2UkNncUArq78cwsEKu7LFIdngBRiqmCzllQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795444903;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=iSBki08s6Y37g2ektwoZx+CNumkLlun7bvIhU3NlRbU=;
	b=SmmgOJ+6pB9EKUOCvVxxLjRwpebZPSLbgyw7vmVxIuxQrBNj3s8jXRuG+J9LIdl4NbHX
	 GgihRQVicYW9haqLpeE4dRUTOuW8wrhTZbvAhimo/Xbu7gaYSY+te9ElBuCq3r/wdeS3z
	 A7Qq4IF6cKtnNwXO0Lge32e9BkxsB/T3thD8hCXpef1FQHVa3V1KWOgzwT/B0hSxOhlf+
	 EnMItONfC3UJ+olAKUaEjRcYpvDqLrmHyBPgoxTN0KecTWndJVbrAxgOmSGQmiqvGdSwv
	 zO1JtCn364RlhJIEJhwm83HbSP3M3PMWjqgAPF495PEAO1nf2MkpKPxsYzRzHTQpiMA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EHuGOoU2;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA5E3606A31A;
	Mon, 23 Nov 2026 14:41:43 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7809E1F000C4;
	Mon, 23 Nov 2026 14:41:41 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795444903;
	bh=iSBki08s6Y37g2ektwoZx+CNumkLlun7bvIhU3NlRbU=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=EHuGOoU2Kf4sRbb4VJLaKTj0cVtrWzSgcO4CmmdLPtaz0HOTZkmEy2Z5xHxtCbl4p
	 yN27U5Ajrq/4uyqMmqEuP2wK6QzgGkKpQFWwDctHcpvz3UnVX5IDcaFEjFZ/3XWwp8
	 xsT5CJGd4sWHcvmdoxRcVyPFEBT3CoGktwCjZYRDsQetjnYGE6eqPbskRMR3EYWolS
	 8kCLMW3wmtkuf8XPvltYBPF+pCu5wp0klYnKDGCL9+7/OHtxxiJaBIaQ1x/19DKeYp
	 N0nBqONBCJL0sMAoG/c3u+IcjwK/dvZYIfsimg/n5uMomnTIG/uK96QaGkCI9PBh0J
	 twoVwLbxQf0ng==
X-Cc: sean.tranchetti@oss.qualcomm.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261117060737.2764327-4-subash.a.kasiviswanathan@oss.qualcomm.com>