lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231216010431.84776-1-gsmecher@threespeedlogic.com>
Date: Fri, 15 Dec 2023 17:04:31 -0800
From: Graeme Smecher <gsmecher@...eespeedlogic.com>
To: David Ahern <dsahern@...nel.org>
Cc: "David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	netdev@...r.kernel.org,
	claudiu.beznea@...on.dev,
	nicolas.ferre@...rochip.com,
	mdf@...nel.org,
	Graeme Smecher <gsmecher@...eespeedlogic.com>
Subject: [PATCH] RFC: net: ipconfig: temporarily bring interface down when changing MTU.

Several network drivers (sh_eth, macb_main, nixge, sundance) only allow
the MTU to be changed when the interface is down, because their buffer
allocations are performed during ndo_open() and calculated using a
specific MTU.

Kick-tested using QEMU (rtl8139, e1000).

Tested-by: Graeme Smecher <gsmecher@...eespeedlogic.com>
---
 net/ipv4/ipconfig.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index c56b6fe6f0d7..69c2a41393a0 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -396,9 +396,21 @@ static int __init ic_setup_if(void)
 	 */
 	if (ic_dev_mtu != 0) {
 		rtnl_lock();
-		if ((err = dev_set_mtu(ic_dev->dev, ic_dev_mtu)) < 0)
-			pr_err("IP-Config: Unable to set interface mtu to %d (%d)\n",
-			       ic_dev_mtu, err);
+		/* Some Ethernet adapters only allow MTU to change when down. */
+		if((err = dev_change_flags(ic_dev->dev, ic_dev->dev->flags | IFF_UP, NULL)))
+			pr_err("IP-Config: About to set MTU, but failed to "
+				 "bring interface %s down! (%d)\n",
+				 ic_dev->dev->name, err);
+		else {
+			if ((err = dev_set_mtu(ic_dev->dev, ic_dev_mtu)) < 0)
+				pr_err("IP-Config: Unable to set interface mtu to %d (%d)\n",
+				       ic_dev_mtu, err);
+
+			if((err = dev_change_flags(ic_dev->dev, ic_dev->dev->flags | IFF_UP, NULL)))
+				pr_err("IP-Config: Trying to set MTU, but unable "
+					 "to bring interface %s back up! (%d)\n",
+					 ic_dev->dev->name, err);
+		}
 		rtnl_unlock();
 	}
 	return 0;
-- 
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ