selinux-testsuite: Add tests for transitions under NNP/nosuid
PATCH v3 1/1 selinux-testsuite: Add tests for transitions under NNP/nosuid
Duplicate the existing tests for transitions under NNP for transitions on a nosuid mount, and then augment both the NNP and nosuid tests to also test the new support for allowing transitions based on nnp_transition and/or nosuid_transition permission if the nnp_nosuid_transition policy capability is enabled. Test NNP and nosuid independently and together.
Signed-off-by Stephen Smalley <[email protected]>
---
v3 fixes a few bugs in the test policy and code, and adds one further test.
policy/Makefile | 6 +-
policy/test_nnp.te | 34 -------
policy/test_nnp_nosuid.te | 85 ++++++++++++++++
tests/Makefile | 10 +-
tests/nnp/test | 44 --------
tests/{nnp => nnp_nosuid}/Makefile | 0
tests/{nnp => nnp_nosuid}/checkcon.c | 0
tests/{nnp => nnp_nosuid}/execnnp.c | 40 ++++++--
tests/nnp_nosuid/test | 189 +++++++++++++++++++++++++++++++++++
9 files changed, 314 insertions(+), 94 deletions(-)
delete mode 100644 policy/test_nnp.te
create mode 100644 policy/test_nnp_nosuid.te
delete mode 100755 tests/nnp/test
rename tests/{nnp => nnp_nosuid}/Makefile (100%)
rename tests/{nnp => nnp_nosuid}/checkcon.c (100%)
rename tests/{nnp => nnp_nosuid}/execnnp.c (57%)
create mode 100755 tests/nnp_nosuid/testpolicy/Makefile +5 -1
@@ -16,7 +16,7 @@ TARGETS = \ test_entrypoint.te test_execshare.te test_exectrace.te \ test_execute_no_trans.te test_fdreceive.te test_file.te \ test_inherit.te test_ioctl.te test_ipc.te test_link.te test_mkdir.te \ - test_nnp.te test_open.te test_ptrace.te test_readlink.te \ + test_nnp_nosuid.te test_open.te test_ptrace.te test_readlink.te \ test_relabel.te test_rename.te test_rxdir.te test_setattr.te \ test_setnice.te test_sigkill.te test_stat.te test_sysctl.te \ test_task_create.te test_task_getpgid.te test_task_getsched.te \
@@ -57,6 +57,10 @@ ifeq ($(shell grep -q all_file_perms.*map $(POLDEV)/include/support/all_perms.sp export M4PARAM = -Dmap_permission_defined endif +ifeq ($(shell grep -q nnp_transition $(POLDEV)/include/support/all_perms.spt && echo true),true) +export M4PARAM += -Dnnp_nosuid_transition_permission_defined +endif + ifeq (x$(DISTRO),$(filter x$(DISTRO),xRHEL4 xRHEL5 xRHEL6)) TARGETS:=$(filter-out test_overlayfs.te test_mqueue.te, $(TARGETS)) endif
policy/test_nnp.te deleted +0 -34
@@ -1,34 +0,0 @@ -################################# -# -# Policy for testing NO_NEW_PRIVS transitions. -# - -# A domain bounded by the unconfined domain. -type test_nnp_bounded_t; -domain_type(test_nnp_bounded_t) -typeattribute test_nnp_bounded_t testdomain; -typebounds unconfined_t test_nnp_bounded_t; - -# The entrypoint type for this domain. -type test_nnp_bounded_exec_t; -files_type(test_nnp_bounded_exec_t) -domain_entry_file(test_nnp_bounded_t, test_nnp_bounded_exec_t) -domain_entry_file(unconfined_t, test_nnp_bounded_exec_t) - -# Run it! This should succeed on v3.18 or later, fail on older kernels. -unconfined_runs_test(test_nnp_bounded_t) -unconfined_run_to(test_nnp_bounded_t, test_nnp_bounded_exec_t) - -# A domain that is not bounded by the unconfined domain. -type test_nnp_notbounded_t; -domain_type(test_nnp_notbounded_t) -typeattribute test_nnp_notbounded_t testdomain; - -# The entrypoint type for this domain. -type test_nnp_notbounded_exec_t; -files_type(test_nnp_notbounded_exec_t) -domain_entry_file(test_nnp_notbounded_t, test_nnp_notbounded_exec_t) - -# Run it! This should fail always. -unconfined_runs_test(test_nnp_notbounded_t) -unconfined_run_to(test_nnp_notbounded_t, test_nnp_notbounded_exec_t)
policy/test_nnp_nosuid.te new file +85 -0
85 lines not on this page · raw message
tests/Makefile +5 -5
@@ -9,8 +9,8 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \ rxdir sem setattr setnice shm sigkill stat sysctl task_create \ task_setnice task_setscheduler task_getscheduler task_getsid \ task_getpgid task_setpgid file ioctl capable_file capable_net \ - capable_sys dyntrans dyntrace bounds nnp mmap unix_socket inet_socket \ - overlay checkreqprot mqueue mac_admin infiniband_pkey \ + capable_sys dyntrans dyntrace bounds nnp_nosuid mmap unix_socket \ + inet_socket overlay checkreqprot mqueue mac_admin infiniband_pkey \ infiniband_endport atsecure ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true)
@@ -32,15 +32,15 @@ SUBDIRS += prlimit endif ifeq ($(DISTRO),RHEL4) - SUBDIRS:=$(filter-out bounds dyntrace dyntrans inet_socket mmap nnp overlay unix_socket, $(SUBDIRS)) + SUBDIRS:=$(filter-out bounds dyntrace dyntrans inet_socket mmap nnp_nosuid overlay unix_socket, $(SUBDIRS)) endif ifeq ($(DISTRO),RHEL5) - SUBDIRS:=$(filter-out bounds inet_socket mmap nnp overlay unix_socket, $(SUBDIRS)) + SUBDIRS:=$(filter-out bounds inet_socket mmap nnp_nosuid overlay unix_socket, $(SUBDIRS)) endif ifeq ($(DISTRO),RHEL6) - SUBDIRS:=$(filter-out nnp overlay, $(SUBDIRS)) + SUBDIRS:=$(filter-out nnp_nosuid overlay, $(SUBDIRS)) endif ifeq ($(DISTRO),RHEL7)
tests/nnp/test deleted +0 -44
44 lines not on this page · raw message
tests/nnp_nosuid/Makefile renamed from tests/nnp/Makefile +0 -0
tests/nnp_nosuid/checkcon.c renamed from tests/nnp/checkcon.c +0 -0
tests/nnp_nosuid/execnnp.c renamed from tests/nnp/execnnp.c +30 -10
@@ -2,36 +2,56 @@#include <stdlib.h> #include <string.h> #include <stdbool.h> +#include <getopt.h> #include <unistd.h> #include <sys/utsname.h> #include <sys/prctl.h> #include <sys/types.h> #include <sys/wait.h> +static void usage (const char *progname) +{ +fprintf (stderr,"usage: %s [-n] command [args...]\n" , progname); +exit (-1 ); +} +int main (int argc,char **argv) {bool nobounded;struct utsname uts;pid_t pid;int rc, status; +int opt; +bool nnp = false; -if (argc <2 ) { -fprintf (stderr,"usage: %s command [args...]\n" , argv[0 ]); -exit (-1 ); +while ((opt =getopt (argc, argv,"n" )) !=-1 ) { +switch (opt) { +case 'n' : + nnp = true; +break ; +default : +usage (argv[0 ]); +break ; + } } +if ((argc - optind) <2 ) +usage (argv[0 ]); +if (uname (&uts) <0 ) {perror ("uname" );exit (-1 ); } - nobounded = ((strcmp (argv[argc -1 ],"test_nnp_bounded_t" ) ==0 ) && + nobounded = ((strcmp (argv[argc -1 ],"test_bounded_t" ) ==0 ) && (strverscmp (uts.release,"3.18" ) <0 )); - rc =prctl (PR_SET_NO_NEW_PRIVS ,1 ,0 ,0 ,0 ); -if (rc <0 ) { -perror ("prctl PR_SET_NO_NEW_PRIVS" ); -exit (-1 ); +if (nnp) { + rc =prctl (PR_SET_NO_NEW_PRIVS ,1 ,0 ,0 ,0 ); +if (rc <0 ) { +perror ("prctl PR_SET_NO_NEW_PRIVS" ); +exit (-1 ); + } } pid =fork ();
@@ -41,8 +61,8 @@ int main(int argc, char **argv) }if (pid ==0 ) { -execvp (argv[1 ], &argv[1 ]); -perror (argv[1 ]); +execvp (argv[optind], &argv[optind]); +perror (argv[optind]);exit (-1 ); }
tests/nnp_nosuid/test new file +189 -0
189 lines not on this page · raw message
Signature · 1 line
2.9.4