[PATCH net-next v01 5/7] hinic3: Add MTU size validation

Fan Gong posted 7 patches 3 weeks, 4 days ago
There is a newer version of this series
[PATCH net-next v01 5/7] hinic3: Add MTU size validation
Posted by Fan Gong 3 weeks, 4 days ago
  Check whether the MTU size is within a reasonable range.

Co-developed-by: Zhu Yikai <zhuyikai1@h-partners.com>
Signed-off-by: Zhu Yikai <zhuyikai1@h-partners.com>
Signed-off-by: Fan Gong <gongfan1@huawei.com>
---
 drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c b/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c
index e7aa54b0e465..aed95fdeccda 100644
--- a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c
+++ b/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c
@@ -246,6 +246,19 @@ int hinic3_set_port_mtu(struct net_device *netdev, u16 new_mtu)
 	struct l2nic_func_tbl_cfg func_tbl_cfg = {};
 	struct hinic3_hwdev *hwdev = nic_dev->hwdev;
 
+	if (new_mtu < HINIC3_MIN_MTU_SIZE) {
+		dev_err(hwdev->dev,
+			"Invalid mtu size: %ubytes, mtu size < %ubytes\n",
+			new_mtu, HINIC3_MIN_MTU_SIZE);
+		return -EINVAL;
+	}
+
+	if (new_mtu > HINIC3_MAX_JUMBO_FRAME_SIZE) {
+		dev_err(hwdev->dev, "Invalid mtu size: %ubytes, mtu size > %ubytes\n",
+			new_mtu, HINIC3_MAX_JUMBO_FRAME_SIZE);
+		return -EINVAL;
+	}
+
 	func_tbl_cfg.mtu = new_mtu;
 
 	return hinic3_set_function_table(hwdev, BIT(L2NIC_FUNC_TBL_CFG_MTU),
-- 
2.43.0
Re: [PATCH net-next v01 5/7] hinic3: Add MTU size validation
Posted by Maxime Chevallier 3 weeks, 4 days ago
Hi,

On 13/03/2026 08:54, Fan Gong wrote:
>   Check whether the MTU size is within a reasonable range.

I don't get why this is needed when we have netdev->min_mtu and
netdev->max_mtu already to sanitize these parameters.

Is this patch needed, and if so can you explain why the
netdev->min/max_mtu parameters aren't enough ?

Maxime
Re: [PATCH net-next v01 5/7] hinic3: Add MTU size validation
Posted by Fan Gong 3 weeks, 1 day ago
On 3/13/2026 4:50 PM, Maxime Chevallier wrote:
> Hi,
>
> On 13/03/2026 08:54, Fan Gong wrote:
>>   Check whether the MTU size is within a reasonable range.
>
> I don't get why this is needed when we have netdev->min_mtu and
> netdev->max_mtu already to sanitize these parameters.
>
> Is this patch needed, and if so can you explain why the
> netdev->min/max_mtu parameters aren't enough ?
>
> Maxime
>

Thanks for your two reviews. We overlooked redundant defensive code and
pointer release operation in patch 2/7.
We will fix them in next version.

Fan gong