Skip to contentSkip to conversation

selinux-testsuite: add labeled ipsec tests

PATCH New Stephen Smalley 1 participant 1 message Jun 25, 2015 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux-testsuite: add labeled ipsec tests

Add tests for labeled IPSEC. These are identical to the tests for NetLabel, i.e. they exercise labeled networking over loopback, including testing of SO_PEERSEC, SCM_SECURITY, and peer recv permission.

One issue with these tests is that even after flushing the ipsec SAD and SPD entries, the kernel continues to perform the peer checks which can cause denials for e.g. NFS once the test policy is unloaded. This suggests some problem with the selinux xfrm ref counting or perhaps delayed freeing of the entries. To compensate, we allow peer permissions for the existing connect tests so that they do not fail if we run the testsuite a second time without an intervening reboot.

Another issue is that unlike the NetLabel case, we do not get an ICMP error back upon the peer recv denial so the client has to wait for a connection timeout, although it does ultimately fail and therefore the test does pass. To avoid hanging for a while on this test, we explicitly set the timeout value for the connect() call.

---
 README                            |  7 +++---
 policy/test_inet_socket.te        | 29 ++++++++++++++++++++++
 tests/inet_socket/client.c        | 10 ++++++++
 tests/inet_socket/ipsec-flush     |  5 ++++
 tests/inet_socket/ipsec-load      |  4 +++
 tests/inet_socket/ipsec_manual_SA | 51 +++++++++++++++++++++++++++++++++++++++
 tests/inet_socket/test            | 44 ++++++++++++++++++++++++++++++++-
 7 files changed, 146 insertions(+), 4 deletions(-)
 create mode 100755 tests/inet_socket/ipsec-flush
 create mode 100755 tests/inet_socket/ipsec-load
 create mode 100644 tests/inet_socket/ipsec_manual_SA
README +4 -3
index bbca997..6d54fcc 100644
@@ -18,6 +18,7 @@ CONFIG_NET=y
 CONFIG_INET=y
 CONFIG_SECURITY=y
 CONFIG_SECURITY_NETWORK=y
+CONFIG_SECURITY_NETWORK_XFRM=y
 CONFIG_SECURITY_SELINUX=y
 CONFIG_NETLABEL=y
 
@@ -33,7 +34,6 @@ CONFIG_JFFS2_FS_SECURITY=y
 
 The following config options are not required by the tests but
 are typical settings for SELinux kernel configuration:
-CONFIG_SECURITY_NETWORK_XFRM=y
 CONFIG_SECURITY_SELINUX_BOOTPARAM=y
 CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=1
 CONFIG_SECURITY_SELINUX_DISABLE=y
@@ -70,8 +70,9 @@ rely upon the SELinux extensions being integrated into the coreutils
 package, with support for the chcon and runcon commands as well as the
 SELinux options to existing utilities such as ls and mkdir.
 
-The inet_socket test depends on netlabel_tools being installed in
-order to load NetLabel configuration.
+The inet_socket tests depend on netlabel_tools being installed in
+order to load NetLabel configuration, and on ipsec-tools being installed
+in order to load labeled IPSEC configuration.
 
 In addition to the libselinux shared library, the libselinux headers
 are required in order to build certain testcases.  These can be found in 
policy/test_inet_socket.te +29 -0
index f652925..25b4f34 100644
@@ -55,6 +55,10 @@ corenet_tcp_connect_generic_port(test_inet_bad_client_t)
 corenet_inout_generic_if(test_inet_bad_client_t)
 corenet_inout_generic_node(test_inet_bad_client_t)
 
+#
+# Policy for testing bind(2) and connect(2) checks.
+#
+
 # Domain for a process allowed to bind(2).
 type test_inet_bind_t;
 domain_type(test_inet_bind_t)
@@ -101,6 +105,8 @@ allow test_inet_connect_t self:udp_socket create_socket_perms;
 corenet_tcp_connect_generic_port(test_inet_connect_t)
 corenet_tcp_bind_generic_port(test_inet_connect_t)
 corenet_tcp_bind_all_nodes(test_inet_connect_t)
+corenet_inout_generic_if(test_inet_connect_t)
+corenet_inout_generic_node(test_inet_connect_t)
 
 # Domain for a process not allowed name_connect permission.
 type test_inet_no_name_connect_t;
@@ -112,6 +118,29 @@ allow test_inet_no_name_connect_t self:tcp_socket create_stream_socket_perms;
 allow test_inet_no_name_connect_t self:udp_socket create_socket_perms;
 corenet_tcp_bind_generic_port(test_inet_no_name_connect_t)
 corenet_tcp_bind_all_nodes(test_inet_no_name_connect_t)
+corenet_inout_generic_if(test_inet_no_name_connect_t)
+corenet_inout_generic_node(test_inet_no_name_connect_t)
+
+#
+# Labeled IPSEC-specific policy.
+#
+
+# For ipsec-load/ipsec-flush.
+gen_require(`
+	type unconfined_t;
+')
+type test_spd_t;
+allow unconfined_t inetsocketdomain:association setcontext;
+allow unconfined_t test_spd_t:association setcontext;
+
+# Each of the test client domains must match against the SPD entry
+# in order to use labeled IPSEC.
+allow test_inet_client_t test_spd_t:association polmatch;
+allow test_inet_bad_client_t test_spd_t:association polmatch;
+
+#
+# Common rules for all inet socket test domains.
+#
 
 # Allow all of these domains to be entered from the sysadm domain.
 miscfiles_domain_entry_test_files(inetsocketdomain)
tests/inet_socket/client.c +10 -0
index 3e3d150..bb721c5 100644
@@ -1,4 +1,5 @@
 #include <sys/types.h>
+#include <sys/time.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -32,6 +33,7 @@ main(int argc, char **argv)
 	int type;
 	char *mycon;
 	unsigned short port;
+	struct timeval tm;
 
 	if (argc != 3)
 		usage(argv[0]);
@@ -53,6 +55,14 @@ main(int argc, char **argv)
 		exit(1);
 	}
 
+	tm.tv_sec = 5;
+	tm.tv_usec = 0;
+	result = setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tm, sizeof tm);
+	if (result < 0) {
+		perror("setsockopt: SO_SNDTIMEO");
+		exit(1);
+	}
+
 	bzero(&sin, sizeof(struct sockaddr_in));
 	sin.sin_family = AF_INET;
 	sin.sin_port = htons(port);
tests/inet_socket/ipsec-flush new file +5 -0
new file mode 100755
index 0000000..31467c6
@@ -0,0 +1,5 @@
+#!/bin/sh
+echo 1 > /proc/sys/net/ipv4/conf/lo/disable_xfrm
+echo 1 > /proc/sys/net/ipv4/conf/lo/disable_policy
+setkey -FP
+setkey -F
tests/inet_socket/ipsec-load new file +4 -0
new file mode 100755
index 0000000..deb8cbd
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo 0 > /proc/sys/net/ipv4/conf/lo/disable_xfrm
+echo 0 > /proc/sys/net/ipv4/conf/lo/disable_policy
+setkey -f $1
tests/inet_socket/ipsec_manual_SA new file +51 -0

51 lines not on this page · raw message

tests/inet_socket/test +43 -1

54 lines not on this page · raw message

Signature · 1 line
2.1.0