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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181215153320.14113-1-bluca@debian.org>
Date:   Sat, 15 Dec 2018 15:33:20 +0000
From:   Luca Boccassi <bluca@...ian.org>
To:     netdev@...r.kernel.org
Cc:     stephen@...workplumber.org, Luca Boccassi <bluca@...ian.org>
Subject: [PATCH iproute2 4/4] testsuite: remove gre kmods if the test loads them

The tunnel test leaves behind link devices created by the GRE kernel
modules:

$ ip -br link
...
gre0@...E    DOWN 0.0.0.0 <NOARP>
gretap0@...E DOWN 00:00:00:00:00:00 <BROADCAST,MULTICAST>
erspan0@...E DOWN 00:00:00:00:00:00 <BROADCAST,MULTICAST>
ip6tnl0@...E DOWN :: <NOARP>
ip6gre0@...E DOWN 00:00:00:00:

$ lsmod | grep gre
ip6_gre      40960  0
ip6_tunnel   40960  1 ip6_gre
ip_gre       32768  0
ip_tunnel    24576  1 ip_gre
gre          16384  2 ip6_gre,ip_gre

Check beforehand if the gre kernel module is loaded, and if not unload
them all at the end of the test. This should avoid causing problems if
a user is already using GRE for other purposes.

Signed-off-by: Luca Boccassi <bluca@...ian.org>
---
 testsuite/tests/ip/tunnel/add_tunnel.t | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/testsuite/tests/ip/tunnel/add_tunnel.t b/testsuite/tests/ip/tunnel/add_tunnel.t
index 3f5a9d3c..76f8b011 100755
--- a/testsuite/tests/ip/tunnel/add_tunnel.t
+++ b/testsuite/tests/ip/tunnel/add_tunnel.t
@@ -4,6 +4,15 @@
 
 TUNNEL_NAME="tunnel_test_ip"
 
+# note that checkbashism reports command -v, but dash supports it and it's posix compliant
+if command -v lsmod >/dev/null 2>&1 && command -v rmmod >/dev/null 2>&1
+then
+    KMODS="ip6_gre ip6_tunnel ip_gre ip_tunnel gre"
+    COUNT_KMODS_BEFORE=$(lsmod | grep -c -e "^ip6_gre" -e "^ip6_tunnel" -e "^ip_gre" -e "^ip_tunnel" -e "^gre")
+else
+    KMODS=""
+fi
+
 ts_log "[Testing add/del tunnels]"
 
 ts_ip "$0" "Add GRE tunnel over IPv4" tunnel add name $TUNNEL_NAME mode gre local 1.1.1.1 remote 2.2.2.2
@@ -12,3 +21,18 @@ ts_ip "$0" "Del GRE tunnel over IPv4" tunnel del $TUNNEL_NAME
 ts_ip "$0" "Add GRE tunnel over IPv6" tunnel add name $TUNNEL_NAME mode ip6gre local dead:beef::1 remote dead:beef::2
 ts_ip "$0" "Del GRE tunnel over IPv6" tunnel del $TUNNEL_NAME
 
+
+if [ -n "$KMODS" ]
+then
+    # unload kernel modules to remove dummy interfaces only if they were not in use beforehand
+    COUNT_KMODS_AFTER=$(lsmod | grep -c -e "^ip6_gre" -e "^ip6_tunnel" -e "^ip_gre" -e "^ip_tunnel" -e "^gre")
+    if [ "$COUNT_KMODS_BEFORE" -eq 0 ] && [ "$COUNT_KMODS_AFTER" -gt 0 ]
+    then
+        for mod in $KMODS
+        do
+            sudo rmmod "$mod"
+        done
+    else
+        ts_log "[gre kernel module was loaded before test, not removing]"
+    fi
+fi
-- 
2.19.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ