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

From: Simon Horman

Date: Mon Nov 23 2026 - 09:41:46 EST


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@xxxxxxxxxxxxxxxx>
> Signed-off-by: Sean Tranchetti <sean.tranchetti@xxxxxxxxxxxxxxxx>
> Signed-off-by: Subash Abhinov Kasiviswanathan <subash.a.kasiviswanathan@xxxxxxxxxxxxxxxx>
> ---
> .../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.

...