Skip to contentSkip to conversation

selinux-testsuite: update socket tests

PATCH In review Stephen Smalley 3 participants 3 messages Jun 10, 2015 – Jun 12, 2015 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux-testsuite: update socket tests

The socket, unix_socket, and unix_secure tests were all for the original SELinux implementation (before Linux 2.6.0), and never worked for SELinux in mainline.
Delete these legacy tests and their associated policy as they neither build nor work and embody many assumptions that are no longer true of SELinux (e.g. permissions that are no longer used, automatic propagation of security contexts for INET over loopback).

Add a new set of unix_socket tests that exercise the Unix domain socket connectto (stream) and sendto (datagram) permission checks and the SO_PEERSEC (stream) and SCM_SECURITY (datagram) functionality. These tests use the abstract name space as the purpose is to test the socket layer hooks, not the file/inode hooks. We currently only test SCM_SECURITY for datagram sockets but this can be extended to also test with stream sockets if/when that functionality is accepted into the kernel.

Possibly we could add similar tests for INET over loopback if we were to also add support for loading netlabel configuration in addition to policy configuration, but that is left to a future change.

---
 policy/Makefile                   |   2 +-
 policy/test_socket.te             |  92 ---------------------
 policy/test_unix_socket.te        |  37 +++++++++
 tests/Makefile                    |   2 +-
 tests/socket/Makefile             |   4 -
 tests/socket/noaccept.c           |  91 ---------------------
 tests/socket/options.c            | 104 -----------------------
 tests/socket/sink.c               | 120 ---------------------------
 tests/socket/source.c             |  95 ---------------------
 tests/socket/test                 |  88 --------------------
 tests/unix_secure/Makefile        |  11 ---
 tests/unix_secure/checksyscalls.c |  28 -------
 tests/unix_secure/client.c        | 126 ----------------------------
 tests/unix_secure/client.pl       |  68 ---------------
 tests/unix_secure/client2.pl      |  79 ------------------
 tests/unix_secure/server.c        | 168 --------------------------------------
 tests/unix_secure/test            |  64 ---------------
 tests/unix_socket/Makefile        |   9 +-
 tests/unix_socket/client.c        | 105 ++++++++++++++++++++++++
 tests/unix_socket/server.c        | 164 +++++++++++++++++++++++++++++++++++++
 tests/unix_socket/test            |  64 +++++----------
 tests/unix_socket/unix_options.c  | 106 ------------------------
 tests/unix_socket/unix_sink.c     | 126 ----------------------------
 tests/unix_socket/unix_source.c   |  99 ----------------------
 24 files changed, 336 insertions(+), 1516 deletions(-)
 delete mode 100644 policy/test_socket.te
 create mode 100644 policy/test_unix_socket.te
 delete mode 100644 tests/socket/Makefile
 delete mode 100644 tests/socket/noaccept.c
 delete mode 100644 tests/socket/options.c
 delete mode 100644 tests/socket/sink.c
 delete mode 100644 tests/socket/source.c
 delete mode 100755 tests/socket/test
 delete mode 100644 tests/unix_secure/Makefile
 delete mode 100644 tests/unix_secure/checksyscalls.c
 delete mode 100644 tests/unix_secure/client.c
 delete mode 100644 tests/unix_secure/client.pl
 delete mode 100644 tests/unix_secure/client2.pl
 delete mode 100644 tests/unix_secure/server.c
 delete mode 100755 tests/unix_secure/test
 create mode 100644 tests/unix_socket/client.c
 create mode 100644 tests/unix_socket/server.c
 delete mode 100644 tests/unix_socket/unix_options.c
 delete mode 100644 tests/unix_socket/unix_sink.c
 delete mode 100644 tests/unix_socket/unix_source.c
policy/Makefile +1 -1
index 683f454..25777bb 100644
@@ -19,7 +19,7 @@ TARGETS = \
 	test_setnice.te test_sigkill.te test_stat.te test_sysctl.te \
 	test_task_create.te test_task_getpgid.te test_task_getsched.te \
 	test_task_getsid.te test_task_setpgid.te test_task_setsched.te \
-	test_transition.te test_wait.te
+	test_transition.te test_unix_socket.te test_wait.te
 
 ifeq ($(shell [ $(POL_VERS) -ge 24 ] && echo true),true)
 TARGETS += test_bounds.te
policy/test_socket.te deleted +0 -92

92 lines not on this page · raw message

policy/test_unix_socket.te new file +37 -0
new file mode 100644
index 0000000..cf3df35
@@ -0,0 +1,37 @@
+#################################
+#
+# Policy for testing Unix/local domain sockets.
+#
+
+attribute unixsocketdomain;
+
+# Domain for server process.
+type test_unix_server_t;
+domain_type(test_unix_server_t)
+unconfined_runs_test(test_unix_server_t)
+typeattribute test_unix_server_t testdomain;
+typeattribute test_unix_server_t unixsocketdomain;
+
+# Domain for stream client process.
+type test_unix_stream_client_t;
+domain_type(test_unix_stream_client_t)
+unconfined_runs_test(test_unix_stream_client_t)
+typeattribute test_unix_stream_client_t testdomain;
+typeattribute test_unix_stream_client_t unixsocketdomain;
+# It can connectto the server.
+allow test_unix_stream_client_t test_unix_server_t:unix_stream_socket connectto;
+
+# Domain for dgram client process.
+type test_unix_dgram_client_t;
+domain_type(test_unix_dgram_client_t)
+unconfined_runs_test(test_unix_dgram_client_t)
+typeattribute test_unix_dgram_client_t testdomain;
+typeattribute test_unix_dgram_client_t unixsocketdomain;
+# It can sendto the server.
+allow test_unix_dgram_client_t test_unix_server_t:unix_dgram_socket sendto;
+# And the server can sendto it in order to reply.
+allow test_unix_server_t test_unix_dgram_client_t:unix_dgram_socket sendto;
+
+# Allow all of these domains to be entered from the sysadm domain.
+miscfiles_domain_entry_test_files(unixsocketdomain)
+userdom_sysadm_entry_spec_domtrans_to(unixsocketdomain)
tests/Makefile +1 -1
index b679137..5e45bf9 100644
@@ -3,7 +3,7 @@ export CFLAGS+=-g -O0 -Wall -D_GNU_SOURCE
 
 DISTRO=$(shell ./os_detect)
 
-SUBDIRS_COMMON:=domain_trans entrypoint execshare exectrace execute_no_trans fdreceive inherit link mkdir msg open ptrace readlink relabel rename rxdir sem setattr setnice shm sigkill stat sysctl task_create task_setnice task_setscheduler task_getscheduler task_getsid task_getpgid task_setpgid wait file ioctl capable_file capable_net capable_sys
+SUBDIRS_COMMON:=domain_trans entrypoint execshare exectrace execute_no_trans fdreceive inherit link mkdir msg open ptrace readlink relabel rename rxdir sem setattr setnice shm sigkill stat sysctl task_create task_setnice task_setscheduler task_getscheduler task_getsid task_getpgid task_setpgid wait file ioctl capable_file capable_net capable_sys unix_socket
 
 SUBDIRS:= $(SUBDIRS_COMMON) dyntrans dyntrace bounds nnp
 
tests/socket/Makefile deleted +0 -4
deleted file mode 100644
index fd017cf..0000000
@@ -1,4 +0,0 @@
-CFLAGS+=-Wall
-all: $(ctargets)
-clean:
-	rm -f $(ctargets) *.o *~
tests/socket/noaccept.c deleted +0 -91

91 lines not on this page · raw message

tests/socket/options.c deleted +0 -104

104 lines not on this page · raw message

tests/socket/sink.c deleted +0 -120

120 lines not on this page · raw message

tests/socket/source.c deleted +0 -95

95 lines not on this page · raw message

tests/socket/test deleted +0 -88

88 lines not on this page · raw message

tests/unix_secure/Makefile deleted +0 -11
deleted file mode 100644
index 630c0b2..0000000
@@ -1,11 +0,0 @@
-ctargets = server client checksyscalls
-
-selinuxhome = /usr/local/selinux
-LDFLAGS = -L$(selinuxhome)/lib
-LDLIBS = -lsecure
-CFLAGS = -I$(selinuxhome)/include
-CFLAGS+=-Wall
-
-all: $(ctargets)
-clean:
-	rm -f $(ctargets) *.o *~
tests/unix_secure/checksyscalls.c deleted +0 -28
deleted file mode 100644
index face8c4..0000000
@@ -1,28 +0,0 @@
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdio.h>
-
-#include <socket_secure.h>
-
-int
-main(int argc, char **argv)
-{
-	int sock;
-	security_id_t socket_sid = 0;
-
-	sock = socket_secure(AF_INET, SOCK_STREAM, 0, socket_sid);
-
-	if (sock < 0) {
-		perror("socket");
-		if (errno == ENOSYS) {
-			printf("Extended socket system calls are unimplemented\n");
-			return -1;
-		}
-		return -2;
-	}
-	close(sock);
-	printf("Extended socket syscalls present.\n");
-	return (0);
-}
tests/unix_secure/client.c deleted +0 -126

126 lines not on this page · raw message

tests/unix_secure/client.pl deleted +0 -68

68 lines not on this page · raw message

tests/unix_secure/client2.pl deleted +0 -79

79 lines not on this page · raw message

tests/unix_secure/server.c deleted +0 -168

168 lines not on this page · raw message

tests/unix_secure/test deleted +0 -64

64 lines not on this page · raw message

tests/unix_socket/Makefile +6 -3
index fd017cf..5266096 100644
@@ -1,4 +1,7 @@
-CFLAGS+=-Wall
-all: $(ctargets)
+TARGETS=client server
+
+LDLIBS+= -lselinux
+
+all: $(TARGETS)
 clean:
-	rm -f $(ctargets) *.o *~
+	rm -f $(TARGETS)
tests/unix_socket/client.c new file +105 -0

105 lines not on this page · raw message

tests/unix_socket/server.c new file +164 -0

164 lines not on this page · raw message

tests/unix_socket/test +22 -42

86 lines not on this page · raw message

tests/unix_socket/unix_options.c deleted +0 -106

106 lines not on this page · raw message

tests/unix_socket/unix_sink.c deleted +0 -126

126 lines not on this page · raw message

tests/unix_socket/unix_source.c deleted +0 -99

99 lines not on this page · raw message

Signature · 1 line
2.1.0
Acked-by Serge Hallyn on v1 1/1
#1 lore raw
Quoted 17 lines · Stephen Smalley

The socket, unix_socket, and unix_secure tests were all for the original SELinux implementation (before Linux 2.6.0), and never worked for SELinux in mainline.
Delete these legacy tests and their associated policy as they neither build nor work and embody many assumptions that are no longer true of SELinux (e.g. permissions that are no longer used, automatic propagation of security contexts for INET over loopback).

Add a new set of unix_socket tests that exercise the Unix domain socket connectto (stream) and sendto (datagram) permission checks and the SO_PEERSEC (stream) and SCM_SECURITY (datagram) functionality. These tests use the abstract name space as the purpose is to test the socket layer hooks, not the file/inode hooks. We currently only test SCM_SECURITY for datagram sockets but this can be extended to also test with stream sockets if/when that functionality is accepted into the kernel.

Quoted 5 lines

Possibly we could add similar tests for INET over loopback if we were to also add support for loading netlabel configuration in addition to policy configuration, but that is left to a future change.

Looks good to me.

maintainer
#2 lore raw
Quoted 22 lines · Serge E. Hallyn
Quoted 21 lines · Stephen Smalley

The socket, unix_socket, and unix_secure tests were all for the original SELinux implementation (before Linux 2.6.0), and never worked for SELinux in mainline.
Delete these legacy tests and their associated policy as they neither build nor work and embody many assumptions that are no longer true of SELinux (e.g. permissions that are no longer used, automatic propagation of security contexts for INET over loopback).

Add a new set of unix_socket tests that exercise the Unix domain socket connectto (stream) and sendto (datagram) permission checks and the SO_PEERSEC (stream) and SCM_SECURITY (datagram) functionality. These tests use the abstract name space as the purpose is to test the socket layer hooks, not the file/inode hooks. We currently only test SCM_SECURITY for datagram sockets but this can be extended to also test with stream sockets if/when that functionality is accepted into the kernel.

Possibly we could add similar tests for INET over loopback if we were to also add support for loading netlabel configuration in addition to policy configuration, but that is left to a future change.

Quoted 5 lines
Quoted 1 line

Looks good to me.

Me too. I sent mail to Stephen but didn't include the list - my mistake. Regardless, it's in the repo now.

Signature · 2 lines
paul moore
www.paul-moore.com