Skip to content

Commit eaf4fac

Browse files
joabreudavem330
authored andcommitted
net: stmmac: Do not accept invalid MTU values
The maximum MTU value is determined by the maximum size of TX FIFO so that a full packet can fit in the FIFO. Add a check for this in the MTU change callback. Also check if provided and rounded MTU does not passes the maximum limit of 16K. Changes from v2: - Align MTU before checking if its valid Fixes: 7ac6653 ("stmmac: Move the STMicroelectronics driver") Signed-off-by: Jose Abreu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5d626c8 commit eaf4fac

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,12 +3827,24 @@ static void stmmac_set_rx_mode(struct net_device *dev)
38273827
static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
38283828
{
38293829
struct stmmac_priv *priv = netdev_priv(dev);
3830+
int txfifosz = priv->plat->tx_fifo_size;
3831+
3832+
if (txfifosz == 0)
3833+
txfifosz = priv->dma_cap.tx_fifo_size;
3834+
3835+
txfifosz /= priv->plat->tx_queues_to_use;
38303836

38313837
if (netif_running(dev)) {
38323838
netdev_err(priv->dev, "must be stopped to change its MTU\n");
38333839
return -EBUSY;
38343840
}
38353841

3842+
new_mtu = STMMAC_ALIGN(new_mtu);
3843+
3844+
/* If condition true, FIFO is too small or MTU too large */
3845+
if ((txfifosz < new_mtu) || (new_mtu > BUF_SIZE_16KiB))
3846+
return -EINVAL;
3847+
38363848
dev->mtu = new_mtu;
38373849

38383850
netdev_update_features(dev);

0 commit comments

Comments
 (0)