Skip to contentSkip to conversation

selinux-testsuite: Add tests for prlimit(2) permission checks

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux-testsuite: Add tests for prlimit(2) permission checks

Add tests for prlimit(2) permission checks for getting and setting resource limits of other processes. The tests are only executed if the new getrlimit permission is defined by the base policy.

---
 policy/Makefile        |   4 ++
 policy/test_prlimit.te |  52 ++++++++++++++++
 tests/Makefile         |   4 ++
 tests/prlimit/Makefile |   7 +++
 tests/prlimit/child.c  |  22 +++++++
 tests/prlimit/parent.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/prlimit/test     |  30 +++++++++
 7 files changed, 283 insertions(+)
 create mode 100644 policy/test_prlimit.te
 create mode 100644 tests/prlimit/Makefile
 create mode 100644 tests/prlimit/child.c
 create mode 100644 tests/prlimit/parent.c
 create mode 100755 tests/prlimit/test
policy/Makefile +4 -0
index de7b950..6537b68 100644
@@ -38,6 +38,10 @@ ifeq ($(shell grep -q netlink_iscsi_socket $(POLDEV)/include/support/all_perms.s
 TARGETS += test_netlink_socket.te
 endif
 
+ifeq ($(shell grep -q getrlimit $(POLDEV)/include/support/all_perms.spt && echo true),true)
+TARGETS += test_prlimit.te
+endif
+
 ifeq (x$(DISTRO),$(filter x$(DISTRO),xRHEL4 xRHEL5 xRHEL6))
 TARGETS:=$(filter-out test_overlayfs.te test_mqueue.te, $(TARGETS))
 endif
policy/test_prlimit.te new file +52 -0

52 lines not on this page · raw message

tests/Makefile +4 -0
index bb5868d..1311234 100644
@@ -24,6 +24,10 @@ ifeq ($(shell grep -q netlink_iscsi_socket $(POLDEV)/include/support/all_perms.s
 SUBDIRS += netlink_socket
 endif
 
+ifeq ($(shell grep -q getrlimit $(POLDEV)/include/support/all_perms.spt && echo true),true)
+SUBDIRS += prlimit
+endif
+
 ifeq ($(DISTRO),RHEL4)
     SUBDIRS:=$(filter-out bounds dyntrace dyntrans inet_socket mmap nnp overlay unix_socket, $(SUBDIRS))
 endif
tests/prlimit/Makefile new file +7 -0
new file mode 100644
index 0000000..f11debe
@@ -0,0 +1,7 @@
+TARGETS=parent child
+
+LDLIBS += -lselinux
+
+all: $(TARGETS)
+clean:
+	rm -f $(TARGETS)
tests/prlimit/child.c new file +22 -0
new file mode 100644
index 0000000..0c385d6
@@ -0,0 +1,22 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(void)
+{
+	char buf[1];
+	int rc;
+
+	buf[0] = 0;
+	rc = write(1, buf, sizeof buf);
+	if (rc < 0) {
+		perror("write");
+		exit(-1);
+	}
+	rc = read(0, buf, sizeof buf);
+	if (rc < 0) {
+		perror("read");
+		exit(-1);
+	}
+	exit(0);
+}
tests/prlimit/parent.c new file +164 -0

164 lines not on this page · raw message

tests/prlimit/test new file +30 -0
new file mode 100755
index 0000000..5456ad5
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+use Test;
+BEGIN { plan tests => 6}
+
+$basedir = $0;  $basedir =~ s|(.*)/[^/]*|$1|;
+
+# Verify that test_setrlimit_t can set soft limit of test_setrlimit_child_t
+$result = system ("runcon -t test_setrlimit_t $basedir/parent -s soft test_setrlimit_child_t $basedir/child 2>&1");
+ok($result, 0); # we expect this to succeed.
+
+# Verify that test_no_setrlimit_t cannot set soft limit of test_setrlimit_child_t
+$result = system ("runcon -t test_no_setrlimit_t $basedir/parent -s soft test_setrlimit_child_t $basedir/child 2>&1");
+ok($result); # we expect this to fail.
+
+# Verify that test_setrlimit_t can set hard limit of test_setrlimit_child_t
+$result = system ("runcon -t test_setrlimit_t $basedir/parent -s hard test_setrlimit_child_t $basedir/child 2>&1");
+ok($result, 0); # we expect this to succeed.
+
+# Verify that test_no_setrlimit_t cannot set hard limit of test_setrlimit_child_t
+$result = system ("runcon -t test_no_setrlimit_t $basedir/parent -s hard test_setrlimit_child_t $basedir/child 2>&1");
+ok($result); # we expect this to fail.
+
+# Verify that test_getrlimit_t can get limits of test_setrlimit_child_t
+$result = system ("runcon -t test_getrlimit_t $basedir/parent -g test_getrlimit_child_t $basedir/child 2>&1");
+ok($result, 0); # we expect this to succeed.
+
+# Verify that test_no_getrlimit_t cannot get limit of test_setrlimit_child_t
+$result = system ("runcon -t test_no_getrlimit_t $basedir/parent -g test_getrlimit_child_t $basedir/child 2>&1");
+ok($result); # we expect this to fail.
Signature · 1 line
2.7.4