Skip to contentSkip to conversation

selinux-testsuite: add tests for new netlink socket classes

PATCH New Stephen Smalley 1 participant 1 message Feb 6, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux-testsuite: add tests for new netlink socket classes

Add tests for the new netlink socket classes introduced by kernel commit 6c6d2e9bde1c1c87a7ead806f8f5e2181d41a652 ("selinux:
update netlink socket classes") circa Linux 4.2.

A representative sampling of the new netlink socket classes are tested, including netlink_iscsi_socket, netlink_netfilter_socket, netlink_generic, and netlink_crypto. The tests verify that a domain can create a socket with the corresponding netlink protocol iff it has the necessary permissions to the corresponding new netlink socket class.

The tests are only run if the new netlink socket classes are defined in the base policy.

---
 policy/Makefile                      |  4 ++
 policy/test_netlink_socket.te        | 50 +++++++++++++++++++++++++
 tests/Makefile                       |  4 ++
 tests/netlink_socket/Makefile        |  4 ++
 tests/netlink_socket/netlinkcreate.c | 72 ++++++++++++++++++++++++++++++++++++
 tests/netlink_socket/test            | 38 +++++++++++++++++++
 6 files changed, 172 insertions(+)
 create mode 100644 policy/test_netlink_socket.te
 create mode 100644 tests/netlink_socket/Makefile
 create mode 100644 tests/netlink_socket/netlinkcreate.c
 create mode 100755 tests/netlink_socket/test
policy/Makefile +4 -0
index 6a9e6e4..de7b950 100644
@@ -34,6 +34,10 @@ ifeq ($(shell grep -q icmp_socket $(POLDEV)/include/support/all_perms.spt && ech
 TARGETS += test_extended_socket_class.te
 endif
 
+ifeq ($(shell grep -q netlink_iscsi_socket $(POLDEV)/include/support/all_perms.spt && echo true),true)
+TARGETS += test_netlink_socket.te
+endif
+
 ifeq (x$(DISTRO),$(filter x$(DISTRO),xRHEL4 xRHEL5 xRHEL6))
 TARGETS:=$(filter-out test_overlayfs.te test_mqueue.te, $(TARGETS))
 endif
policy/test_netlink_socket.te new file +50 -0

50 lines not on this page · raw message

tests/Makefile +4 -0
index 53f256a..bb5868d 100644
@@ -20,6 +20,10 @@ ifeq ($(shell grep -q icmp_socket $(POLDEV)/include/support/all_perms.spt && gre
 SUBDIRS += extended_socket_class
 endif
 
+ifeq ($(shell grep -q netlink_iscsi_socket $(POLDEV)/include/support/all_perms.spt && echo true),true)
+SUBDIRS += netlink_socket
+endif
+
 ifeq ($(DISTRO),RHEL4)
     SUBDIRS:=$(filter-out bounds dyntrace dyntrans inet_socket mmap nnp overlay unix_socket, $(SUBDIRS))
 endif
tests/netlink_socket/Makefile new file +4 -0
new file mode 100644
index 0000000..8dce555
@@ -0,0 +1,4 @@
+TARGETS=$(patsubst %.c,%,$(wildcard *.c))
+all: $(TARGETS)
+clean:
+	rm -f $(TARGETS)
tests/netlink_socket/netlinkcreate.c new file +72 -0

72 lines not on this page · raw message

tests/netlink_socket/test new file +38 -0
new file mode 100755
index 0000000..c38672e
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+use Test;
+BEGIN { plan tests => 8 };
+
+$basedir = $0;  $basedir =~ s|(.*)/[^/]*|$1|;
+
+# Verify that test_netlink_iscsi_socket_t can create a NETLINK_ISCSI socket.
+$result = system("runcon -t test_netlink_iscsi_socket_t -- $basedir/netlinkcreate iscsi 2>&1");
+ok($result, 0);
+
+# Verify that test_no_netlink_iscsi_socket_t cannot create a NETLINK_ISCSI socket.
+$result = system("runcon -t test_no_netlink_iscsi_socket_t -- $basedir/netlinkcreate iscsi 2>&1");
+ok($result);
+
+# Verify that test_netlink_netfilter_socket_t can create a NETLINK_NETFILTER socket.
+$result = system("runcon -t test_netlink_netfilter_socket_t -- $basedir/netlinkcreate netfilter 2>&1");
+ok($result, 0);
+
+# Verify that test_no_netlink_netfilter_socket_t cannot create a NETLINK_NETFILTER socket.
+$result = system("runcon -t test_no_netlink_netfilter_socket_t -- $basedir/netlinkcreate netfilter 2>&1");
+ok($result);
+
+# Verify that test_netlink_generic_socket_t can create a NETLINK_GENERIC socket.
+$result = system("runcon -t test_netlink_generic_socket_t -- $basedir/netlinkcreate generic 2>&1");
+ok($result, 0);
+
+# Verify that test_no_netlink_generic_socket_t cannot create a NETLINK_GENERIC socket.
+$result = system("runcon -t test_no_netlink_generic_socket_t -- $basedir/netlinkcreate generic 2>&1");
+ok($result);
+
+# Verify that test_netlink_crypto_socket_t can create a NETLINK_CRYPTO socket.
+$result = system("runcon -t test_netlink_crypto_socket_t -- $basedir/netlinkcreate crypto 2>&1");
+ok($result, 0);
+
+# Verify that test_no_netlink_crypto_socket_t cannot create a NETLINK_CRYPTO socket.
+$result = system("runcon -t test_no_netlink_crypto_socket_t -- $basedir/netlinkcreate crypto 2>&1");
+ok($result);
Signature · 1 line
2.7.4