Skip to contentSkip to conversation

selinux-testsuite: add inet_socket tests

PATCH Superseded Stephen Smalley 1 participant 1 message Jun 16, 2015 SELinux security module

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux-testsuite: add inet_socket tests

Add a set of tests for INET sockets that exercise the SO_PEERSEC and SCM_SECURITY functionality and test the peer recv permission check. Load a NetLabel configuration during testing to enable full SELinux labeling over loopback.

Other candidates for future tests:
- Test other INET socket permission checks, such as socket name_bind, node_bind, name_connect, netif ingress/egress, and node recvfrom/sendto,
- Test SECMARK packet labeling and packet permission checks,
- Test labeled IPSEC peer labeling (over loopback possible?),
- Optionally test cross-machine peer labeling via NetLabel or labeled IPSEC (requires more complex test setup).

Presently this test does not work on F22 due to a problem with netlabel_tools, but it did pass on F21 for me.

---
 policy/Makefile                  |   2 +-
 policy/test_inet_socket.te       |  60 +++++++++++++
 tests/Makefile                   |   2 +-
 tests/inet_socket/Makefile       |   7 ++
 tests/inet_socket/client.c       | 102 +++++++++++++++++++++++
 tests/inet_socket/netlabel-flush |   8 ++
 tests/inet_socket/netlabel-load  |  11 +++
 tests/inet_socket/server.c       | 176 +++++++++++++++++++++++++++++++++++++++
 tests/inet_socket/test           |  50 +++++++++++
 9 files changed, 416 insertions(+), 2 deletions(-)
 create mode 100644 policy/test_inet_socket.te
 create mode 100644 tests/inet_socket/Makefile
 create mode 100644 tests/inet_socket/client.c
 create mode 100755 tests/inet_socket/netlabel-flush
 create mode 100755 tests/inet_socket/netlabel-load
 create mode 100644 tests/inet_socket/server.c
 create mode 100755 tests/inet_socket/test
policy/Makefile +1 -1
index 25777bb..742fd03 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_unix_socket.te test_wait.te
+	test_transition.te test_inet_socket.te test_unix_socket.te test_wait.te
 
 ifeq ($(shell [ $(POL_VERS) -ge 24 ] && echo true),true)
 TARGETS += test_bounds.te
policy/test_inet_socket.te new file +60 -0

60 lines not on this page · raw message

tests/Makefile +1 -1
index 5e45bf9..507123b 100644
@@ -5,7 +5,7 @@ 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 unix_socket
 
-SUBDIRS:= $(SUBDIRS_COMMON) dyntrans dyntrace bounds nnp
+SUBDIRS:= $(SUBDIRS_COMMON) dyntrans dyntrace bounds nnp inet_socket
 
 ifeq ($(DISTRO),RHEL4)
     SUBDIRS:=$(SUBDIRS_COMMON)
tests/inet_socket/Makefile new file +7 -0
new file mode 100644
index 0000000..5266096
@@ -0,0 +1,7 @@
+TARGETS=client server
+
+LDLIBS+= -lselinux
+
+all: $(TARGETS)
+clean:
+	rm -f $(TARGETS)
tests/inet_socket/client.c new file +102 -0

102 lines not on this page · raw message

tests/inet_socket/netlabel-flush new file +8 -0
new file mode 100755
index 0000000..32a5b73
@@ -0,0 +1,8 @@
+#!/bin/sh
+# Reset NetLabel configuration to unlabeled for all.
+netlabelctl map del default
+netlabelctl cipsov4 del doi:1
+netlabelctl map add default protocol:unlbl
+# Display the configuration.
+netlabelctl -p map list
+netlabelctl -p cipsov4 list
tests/inet_socket/netlabel-load new file +11 -0
new file mode 100755
index 0000000..8110d18
@@ -0,0 +1,11 @@
+#!/bin/sh
+# Define a localhost/loopback doi and apply it to the loopback address
+# so that we get full SELinux labels over loopback connections.
+netlabelctl cipsov4 add local doi:1
+netlabelctl map del default
+netlabelctl map add default address:0.0.0.0/0 protocol:unlbl
+netlabelctl map add default address:::/0 protocol:unlbl
+netlabelctl map add default address:127.0.0.1 protocol:cipsov4,1
+# Display the configuration.
+netlabelctl -p cipsov4 list
+netlabelctl -p map list
tests/inet_socket/server.c new file +176 -0

176 lines not on this page · raw message

tests/inet_socket/test new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.1.0