Skip to contentSkip to conversation

Make SCTP and Bluetooth support optional

PATCH Applied Ondrej Mosnacek 1 participant 4 messages Apr 13, 2022 – Apr 20, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

cover Make SCTP and Bluetooth support optional

SCTP support is already partially auto-detected - improve it to be more robust. Bluetooth is often disabled on architectures where it couldn't be used, so add checks for it and skip relevant subtests if it's disabled.

Ondrej Mosnacek (2):
tests/extended_socket_class: make Bluetooth support optional
tests: check more thoroughly for SCTP support

 tests/extended_socket_class/test | 107 +++++++++++++++++++------------
 tests/sctp/test                  |   4 +-
 2 files changed, 68 insertions(+), 43 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/2 tests/extended_socket_class: make Bluetooth support optional

CONFIG_BT is commonly disabled on some architectures due to lack of relevant HW - for example s390x on Fedora/RHEL and aarch64 on RHEL. Make the testsuite work without it to make testing easier in such environments.

---
 tests/extended_socket_class/test | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)
tests/extended_socket_class/test +23 -9
index 6e334d1..022993d 100755
@@ -1,7 +1,18 @@
 #!/usr/bin/perl
 
 use Test;
-BEGIN { plan tests => 16 }
+
+BEGIN {
+    $test_count     = 14;
+    $test_bluetooth = 0;
+
+    # check if Bluetooth is supported (commonly disabled e.g. on s390x)
+    if ( system("modprobe bluetooth 2>/dev/null") eq 0 ) {
+        $test_count += 2;
+        $test_bluetooth = 1;
+    }
+    plan tests => $test_count;
+}
 
 $basedir = $0;
 $basedir =~ s|(.*)/[^/]*|$1|;
@@ -83,17 +94,20 @@ $result = system(
 );
 ok($result);
 
-# Verify that test_bluetooth_socket_t can create a Bluetooth socket.
-$result = system(
+if ($test_bluetooth) {
+
+    # Verify that test_bluetooth_socket_t can create a Bluetooth socket.
+    $result = system(
 "runcon -t test_bluetooth_socket_t -- $basedir/sockcreate bluetooth stream default 2>&1"
-);
-ok( $result, 0 );
+    );
+    ok( $result, 0 );
 
-# Verify that test_no_bluetooth_socket_t cannot create a Bluetooth socket.
-$result = system(
+    # Verify that test_no_bluetooth_socket_t cannot create a Bluetooth socket.
+    $result = system(
 "runcon -t test_no_bluetooth_socket_t -- $basedir/sockcreate bluetooth stream default 2>&1"
-);
-ok($result);
+    );
+    ok($result);
+}
 
 # Verify that test_alg_socket_t can create a Crypto API socket.
 $result = system(
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/2 tests: check more thoroughly for SCTP support

In reply to Ondrej Mosnacek

1. Add SCTP support checking also to extended_socket_class test, where it was missing previously.
2. Attempt to explicitly load the 'sctp' module as part of the check to ensure that SCTP support is activated and detected also when it is excluded from autoloading (as is the case e.g. on RHEL 8+).

---
 tests/extended_socket_class/test | 77 ++++++++++++++++++--------------
 tests/sctp/test                  |  4 +-
 2 files changed, 46 insertions(+), 35 deletions(-)
tests/extended_socket_class/test +44 -33
index 022993d..86c706b 100755
@@ -3,14 +3,22 @@
 use Test;
 
 BEGIN {
-    $test_count     = 14;
+    $test_count     = 6;
     $test_bluetooth = 0;
+    $test_sctp      = 0;
+
+    # check if SCTP is enabled
+    if ( system("modprobe sctp 2>/dev/null && checksctp 2>/dev/null") eq 0 ) {
+        $test_count += 8;
+        $test_sctp = 1;
+    }
 
     # check if Bluetooth is supported (commonly disabled e.g. on s390x)
     if ( system("modprobe bluetooth 2>/dev/null") eq 0 ) {
         $test_count += 2;
         $test_bluetooth = 1;
     }
+
     plan tests => $test_count;
 }
 
@@ -46,53 +54,56 @@ ok($result);
 # Restore to the kernel defaults - no one allowed to create ICMP sockets.
 system("echo 1 0 > /proc/sys/net/ipv4/ping_group_range");
 
-# Verify that test_sctp_socket_t can create an IPv4 stream SCTP socket.
-$result = system(
-    "runcon -t test_sctp_socket_t -- $basedir/sockcreate inet stream sctp 2>&1"
-);
-ok( $result, 0 );
+if ($test_sctp) {
 
-# Verify that test_no_sctp_socket_t cannot create an IPv4 stream SCTP socket.
-$result = system(
+    # Verify that test_sctp_socket_t can create an IPv4 stream SCTP socket.
+    $result = system(
+"runcon -t test_sctp_socket_t -- $basedir/sockcreate inet stream sctp 2>&1"
+    );
+    ok( $result, 0 );
+
+   # Verify that test_no_sctp_socket_t cannot create an IPv4 stream SCTP socket.
+    $result = system(
 "runcon -t test_no_sctp_socket_t -- $basedir/sockcreate inet stream sctp 2>&1"
-);
-ok($result);
+    );
+    ok($result);
 
-# Verify that test_sctp_socket_t can create an IPv4 seqpacket SCTP socket.
-$result = system(
+    # Verify that test_sctp_socket_t can create an IPv4 seqpacket SCTP socket.
+    $result = system(
 "runcon -t test_sctp_socket_t -- $basedir/sockcreate inet seqpacket sctp 2>&1"
-);
-ok( $result, 0 );
+    );
+    ok( $result, 0 );
 
 # Verify that test_no_sctp_socket_t cannot create an IPv4 seqpacket SCTP socket.
-$result = system(
+    $result = system(
 "runcon -t test_no_sctp_socket_t -- $basedir/sockcreate inet seqpacket sctp 2>&1"
-);
-ok($result);
+    );
+    ok($result);
 
-# Verify that test_sctp_socket_t can create an IPv6 stream SCTP socket.
-$result = system(
-    "runcon -t test_sctp_socket_t -- $basedir/sockcreate inet6 stream sctp 2>&1"
-);
-ok( $result, 0 );
+    # Verify that test_sctp_socket_t can create an IPv6 stream SCTP socket.
+    $result = system(
+"runcon -t test_sctp_socket_t -- $basedir/sockcreate inet6 stream sctp 2>&1"
+    );
+    ok( $result, 0 );
 
-# Verify that test_no_sctp_socket_t cannot create an IPv6 stream SCTP socket.
-$result = system(
+   # Verify that test_no_sctp_socket_t cannot create an IPv6 stream SCTP socket.
+    $result = system(
 "runcon -t test_no_sctp_socket_t -- $basedir/sockcreate inet6 stream sctp 2>&1"
-);
-ok($result);
+    );
+    ok($result);
 
-# Verify that test_sctp_socket_t can create an IPv6 seqpacket SCTP socket.
-$result = system(
+    # Verify that test_sctp_socket_t can create an IPv6 seqpacket SCTP socket.
+    $result = system(
 "runcon -t test_sctp_socket_t -- $basedir/sockcreate inet6 seqpacket sctp 2>&1"
-);
-ok( $result, 0 );
+    );
+    ok( $result, 0 );
 
 # Verify that test_no_sctp_socket_t cannot create an IPv6 seqpacket SCTP socket.
-$result = system(
+    $result = system(
 "runcon -t test_no_sctp_socket_t -- $basedir/sockcreate inet6 seqpacket sctp 2>&1"
-);
-ok($result);
+    );
+    ok($result);
+}
 
 if ($test_bluetooth) {
 
tests/sctp/test +2 -2
index 0f017e8..1258de4 100755
@@ -28,8 +28,8 @@ BEGIN {
         $v = " ";
     }
 
-    # check if sctp enabled
-    if ( system("checksctp 2> /dev/null") != 0 ) {
+    # check if SCTP is enabled
+    if ( system("modprobe sctp 2>/dev/null && checksctp 2>/dev/null") != 0 ) {
         plan skip_all => "SCTP not supported";
     }
     else {
Signature · 1 line
2.35.1
author Applied
#3 lore raw
In reply to Ondrej Mosnacek
Quoted 9 lines · Ondrej Mosnacek

SCTP support is already partially auto-detected - improve it to be more robust. Bluetooth is often disabled on architectures where it couldn't be used, so add checks for it and skip relevant subtests if it's disabled.

Ondrej Mosnacek (2):
tests/extended_socket_class: make Bluetooth support optional
tests: check more thoroughly for SCTP support

Quoted 6 lines
 tests/extended_socket_class/test | 107 +++++++++++++++++++------------
 tests/sctp/test                  |   4 +-
 2 files changed, 68 insertions(+), 43 deletions(-)

--
2.35.1

Applied.

Signature · 3 lines
Ondrej Mosnacek
Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.