Skip to contentSkip to conversation

selinux-testsuite: Add nftables to inet_socket and sctp tests

PATCH Superseded Richard Haines 2 participants 2 messages May 15, 2020 SELinux security module

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selinux-testsuite: Add nftables to inet_socket and sctp tests

Support secmark tests that require nftables version 9.3 or greater and kernel 4.20 or greater.

---
V2 Change:
Use common tests for iptables/nftables

 README.md                        |   4 +-
 tests/inet_socket/nftables-flush |   2 +
 tests/inet_socket/nftables-load  |  74 +++++++++++++++++++++
 tests/inet_socket/test           | 108 ++++++++++++++++++++-----------
 tests/sctp/nftables-flush        |   2 +
 tests/sctp/nftables-load         |  68 +++++++++++++++++++
 tests/sctp/test                  |  96 +++++++++++++++++----------
 7 files changed, 281 insertions(+), 73 deletions(-)
 create mode 100644 tests/inet_socket/nftables-flush
 create mode 100644 tests/inet_socket/nftables-load
 create mode 100644 tests/sctp/nftables-flush
 create mode 100644 tests/sctp/nftables-load
README.md +3 -1
index 1f7e5d9..d65e9b8 100644
@@ -57,6 +57,7 @@ similar dependencies):
 * keyutils-libs-devel _(tools used by the keys tests)_
 * kernel-devel _(used by the kernel module tests)_
 * quota, xfsprogs-devel and libuuid-devel _(used by the filesystem tests)_
+* nftables _(used by inet_socket and sctp tests if ver >= 9.3 for secmark testing )_
 
 On a modern Fedora system you can install these dependencies with the
 following command:
@@ -77,7 +78,8 @@ following command:
 		kernel-devel \
 		quota \
 		xfsprogs-devel \
-		libuuid-devel
+		libuuid-devel \
+		nftables
 
 #### Debian
 
tests/inet_socket/nftables-flush new file +2 -0
new file mode 100644
index 0000000..7d62b8d
@@ -0,0 +1,2 @@
+delete table ip security
+delete table ip6 security
tests/inet_socket/nftables-load new file +74 -0

74 lines not on this page · raw message

tests/inet_socket/test +70 -38

139 lines not on this page · raw message

tests/sctp/nftables-flush new file +2 -0
new file mode 100644
index 0000000..7d62b8d
@@ -0,0 +1,2 @@
+delete table ip security
+delete table ip6 security
tests/sctp/nftables-load new file +68 -0

68 lines not on this page · raw message

tests/sctp/test +62 -34

132 lines not on this page · raw message

Signature · 1 line
2.25.3
#1 lore raw
Quoted 21 lines · Richard Haines

Support secmark tests that require nftables version 9.3 or greater and kernel 4.20 or greater.

---
V2 Change:
Use common tests for iptables/nftables

 README.md                        |   4 +-
 tests/inet_socket/nftables-flush |   2 +
 tests/inet_socket/nftables-load  |  74 +++++++++++++++++++++
 tests/inet_socket/test           | 108 ++++++++++++++++++++-----------
 tests/sctp/nftables-flush        |   2 +
 tests/sctp/nftables-load         |  68 +++++++++++++++++++
 tests/sctp/test                  |  96 +++++++++++++++++----------
 7 files changed, 281 insertions(+), 73 deletions(-)
 create mode 100644 tests/inet_socket/nftables-flush
 create mode 100644 tests/inet_socket/nftables-load
 create mode 100644 tests/sctp/nftables-flush
 create mode 100644 tests/sctp/nftables-load

[...]

Quoted 38 lines
tests/inet_socket/test +21 -2
index 47ce106..ce9bd7f 100755
@@ -27,6 +27,19 @@ BEGIN {
         $test_calipso_stream = 1;
     }
 
+    # Determine nftables version, must be >= 0.9.3 for secmark support
+    # with kernel >= 4.20
+    $test_nft = 0;
+    $nft      = `nft -v`;
+    $nft =~ s/\D//g;
+    $kverminstream = "4.20";
+
+    $rc = `$basedir/../kvercmp $kvercur $kverminstream`;
+    if ( $nft gt "092" and $rc > 0 ) {
+        $test_count += 8;
+        $test_nft = 1;
+    }
+
     plan tests => $test_count;
 }
 
@@ -348,63 +361,82 @@ if ($test_ipsec) {
     system "/bin/sh $basedir/ipsec-flush";
 }
 
-# Load iptables (IPv4 & IPv6) configuration.
-system "/bin/sh $basedir/iptables-load";
+#
+################## Test iptables/nftables configuration ######################
+#
+$test_msg = "Testing iptables (IPv4/IPv6).\n";
+$cmd      = "/bin/sh";
+$table    = "iptables";
+$i        = 0;
+$loop     = 1;

tests/inet_socket/test if ($test_ipsec) { · line 379

Quoted 10 lines
tests/inet_socket/test +7 -2
+
+if ($test_nft) {
+    $loop = 2;
+}
 
-# Start the stream server.
-$pid = server_start( "-t test_inet_server_t", "-n stream 65535" );
+while ( $i < $loop ) {
+    print "$test_msg";
+    system "$cmd $basedir/$table-load";

Ugh, that is ugly... Why not just do something like:

sub test_tables {

    # run the tests...
}
[...]
print "Testing iptables (IPv4/IPv6).\n";
system "/bin/sh $basedir/iptables-load";
test_tables();
system "/bin/sh $basedir/iptables-flush";

print "Testing nftables (IPv4/IPv6).\n";
system "nft -f $basedir/nftables-load";
test_tables();
system "nft -f $basedir/nftables-flush";
[...]

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.