| From 51190ee94a74beedf33d6d7108b3560532b15010 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Wed, 18 Dec 2019 11:17:37 +0100 |
| Subject: net: stmmac: Do not accept invalid MTU values |
| |
| From: Jose Abreu <Jose.Abreu@synopsys.com> |
| |
| [ Upstream commit eaf4fac478077d4ed57cbca2c044c4b58a96bd98 ] |
| |
| 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: 7ac6653a085b ("stmmac: Move the STMicroelectronics driver") |
| Signed-off-by: Jose Abreu <Jose.Abreu@synopsys.com> |
| Signed-off-by: David S. Miller <davem@davemloft.net> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 ++++++++++++ |
| 1 file changed, 12 insertions(+) |
| |
| diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |
| index d9520c029ae5..1b4968e4a313 100644 |
| --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |
| +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |
| @@ -3745,12 +3745,24 @@ static void stmmac_set_rx_mode(struct net_device *dev) |
| static int stmmac_change_mtu(struct net_device *dev, int new_mtu) |
| { |
| struct stmmac_priv *priv = netdev_priv(dev); |
| + int txfifosz = priv->plat->tx_fifo_size; |
| + |
| + if (txfifosz == 0) |
| + txfifosz = priv->dma_cap.tx_fifo_size; |
| + |
| + txfifosz /= priv->plat->tx_queues_to_use; |
| |
| if (netif_running(dev)) { |
| netdev_err(priv->dev, "must be stopped to change its MTU\n"); |
| return -EBUSY; |
| } |
| |
| + new_mtu = STMMAC_ALIGN(new_mtu); |
| + |
| + /* If condition true, FIFO is too small or MTU too large */ |
| + if ((txfifosz < new_mtu) || (new_mtu > BUF_SIZE_16KiB)) |
| + return -EINVAL; |
| + |
| dev->mtu = new_mtu; |
| |
| netdev_update_features(dev); |
| -- |
| 2.20.1 |
| |