Skip to contentSkip to conversation

selinux-testsuite: Add nftables to inet_socket and sctp tests

PATCH Superseded Richard Haines 2 participants 3 messages May 20, 2020 – May 21, 2020 SELinux security module

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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
V3 Change:
Use function
V4 Changes:
Add nftables to README for Debian
Use nft -c to determine if SECMARK supported

 README.md                        |  7 ++-
 tests/inet_socket/nftables-flush |  2 +
 tests/inet_socket/nftables-load  | 74 ++++++++++++++++++++++++
 tests/inet_socket/test           | 99 ++++++++++++++++++++------------
 tests/sctp/nftables-flush        |  2 +
 tests/sctp/nftables-load         | 68 ++++++++++++++++++++++
 tests/sctp/test                  | 90 ++++++++++++++++++-----------
 7 files changed, 270 insertions(+), 72 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 +5 -2
index 1f7e5d9..81475d7 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
 
@@ -118,7 +120,8 @@ command:
 		quota \
 		xfsprogs \
 		xfslibs-dev \
-		uuid-dev
+		uuid-dev \
+		nftables
 
 On Debian, you need to build and install netlabel_tools manually since
 it is not yet packaged for 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 +62 -37

132 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 +57 -33

127 lines not on this page · raw message

Signature · 1 line
2.25.3
#1 lore raw
Quoted 25 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
V3 Change:
Use function
V4 Changes:
Add nftables to README for Debian
Use nft -c to determine if SECMARK supported

 README.md                        |  7 ++-
 tests/inet_socket/nftables-flush |  2 +
 tests/inet_socket/nftables-load  | 74 ++++++++++++++++++++++++
 tests/inet_socket/test           | 99 ++++++++++++++++++++------------
 tests/sctp/nftables-flush        |  2 +
 tests/sctp/nftables-load         | 68 ++++++++++++++++++++++
 tests/sctp/test                  | 90 ++++++++++++++++++-----------
 7 files changed, 270 insertions(+), 72 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 13 lines
tests/inet_socket/test +5 -0
index 47ce106..6c82719 100755
@@ -27,6 +27,19 @@ BEGIN {
         $test_calipso_stream = 1;
     }
 
+    # Determine if nftables has secmark support and kernel >= 4.20
+    $test_nft = 0;
+
+    $rc = system("nft -c -f $basedir/nftables-load 2>/dev/null");
+    if ( $rc == 0 ) {

tests/inet_socket/test BEGIN { · line 44

Quoted 10 lines
tests/inet_socket/test +8 -0
+        $kverminstream = "4.20";
+        $rc            = `$basedir/../kvercmp $kvercur $kverminstream`;
+        if ( $rc > 0 ) {
+            $test_count += 8;
+            $test_nft = 1;
+        }
+    }
+
     plan tests => $test_count;
 }

Sorry for bothering you again, but I believe we can drop the kernel version check here as well (as I said in the previous reply). When I strace the nft -c -f ... command, I can see it actually sending netlink messages to the kernel, so it should be able to transparently detect missing kernel support as well. I just tried it on a RHEL-7 box with nftables v0.9.4 compiled from source and the command failed with many errors so I think that confirms it. I'd like us to avoid hard-coded kernel version checks (they may be unreliable on kernels with backports) when there is an easy way to detect support directly.

Thanks,

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
#2 lore raw
Quoted 58 lines · Ondrej Mosnacek
Quoted 28 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
V3 Change:
Use function
V4 Changes:
Add nftables to README for Debian
Use nft -c to determine if SECMARK supported

 README.md                        |  7 ++-
 tests/inet_socket/nftables-flush |  2 +
 tests/inet_socket/nftables-load  | 74 ++++++++++++++++++++++++
 tests/inet_socket/test           | 99 ++++++++++++++++++++------
------
 tests/sctp/nftables-flush        |  2 +
 tests/sctp/nftables-load         | 68 ++++++++++++++++++++++
 tests/sctp/test                  | 90 ++++++++++++++++++--------
---
 7 files changed, 270 insertions(+), 72 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 14 lines
tests/inet_socket/test +6 -0
index 47ce106..6c82719 100755
@@ -27,6 +27,19 @@ BEGIN {
         $test_calipso_stream = 1;
     }
 
+    # Determine if nftables has secmark support and kernel >= 4.20
+    $test_nft = 0;
+
+    $rc = system("nft -c -f $basedir/nftables-load 2>/dev/null");
+    if ( $rc == 0 ) {
+        $kverminstream = "4.20";

tests/inet_socket/test BEGIN { · line 45

Quoted 10 lines
tests/inet_socket/test +7 -0
+        $rc            = `$basedir/../kvercmp $kvercur
 $kverminstream`;
+        if ( $rc > 0 ) {
+            $test_count += 8;
+            $test_nft = 1;
+        }
+    }
+
     plan tests => $test_count;
 }

Sorry for bothering you again, but I believe we can drop the kernel version check here as well (as I said in the previous reply). When I

Quoted 9 lines

strace the nft -c -f ... command, I can see it actually sending netlink messages to the kernel, so it should be able to transparently detect missing kernel support as well. I just tried it on a RHEL-7 box
with nftables v0.9.4 compiled from source and the command failed with many errors so I think that confirms it. I'd like us to avoid hard-coded kernel version checks (they may be unreliable on kernels with backports) when there is an easy way to detect support directly.

No problem, I should read, digest and take note etc. !!!!

Quoted 2 lines

Thanks,