Selinux tests for Infinfiband
cover Selinux tests for Infinfiband
From: Daniel Jurgens <[email protected]>
Implements new tests for Infiniband pkeys and endports. Because infiniband isn't widely used, and when it is the configuration is site specific, configuration files are used to enable the tests and set environment specific settings. When the tests are disable they always show as passed.
If enabled, the tests require correstponding updates to selinux, refpolicy, and the linux kernel.
---
v1:
- Synchronize intefrace names with changes to refpolicy.
- Change tests to not assume that default pkey is labeled.
- See patches v1 notes for more detail.
Daniel Jurgens (2):
selinux-testsuite: Infiniband pkey tests
selinux-testsuite: Infiniband endport tests
README | 14 +++ policy/Makefile | 3 +- policy/test_ibendport.te | 35 +++++++ policy/test_ibpkey.te | 25 +++++ tests/Makefile | 8 +- tests/infiniband_endport/ibendport_test.conf | 14 +++ tests/infiniband_endport/test | 49 +++++++++ tests/infiniband_pkey/Makefile | 7 ++ tests/infiniband_pkey/create_modify_qp.c | 144 +++++++++++++++++++++++++++ tests/infiniband_pkey/ibpkey_test.conf | 18 ++++ tests/infiniband_pkey/test | 84 ++++++++++++++++ 11 files changed, 397 insertions(+), 4 deletions(-) create mode 100644 policy/test_ibendport.te create mode 100644 policy/test_ibpkey.te create mode 100644 tests/infiniband_endport/ibendport_test.conf create mode 100644 tests/infiniband_endport/test create mode 100644 tests/infiniband_pkey/Makefile create mode 100644 tests/infiniband_pkey/create_modify_qp.c create mode 100644 tests/infiniband_pkey/ibpkey_test.conf create mode 100755 tests/infiniband_pkey/test
Signature · 1 line
2.12.2
PATCH 1/2 selinux-testsuite: Infiniband pkey tests
From: Daniel Jurgens <[email protected]>
New tests for infiniband pkeys. Most users don't have Infiniband hardware, and if they do the pkey configuration is not standardized. There is a configuration file for enabling the test and setting environment specific test configurations. If the tests are disabled they will always show as passed.
---
v1:
- Synchronized interface names with refpolicy changes.
- Changed pkey test to not assume the default pkey is labeled, instead it take a list of indexes with labeled and unlabeled pkeys. It checks that the labeled aren't allowed, unlabeled are allowed, and it labels the unlabeled ones to make sure they aren't allowed when labeled.
--- README | 9 ++ policy/Makefile | 3 +- policy/test_ibpkey.te | 25 ++++++ tests/Makefile | 4 +- tests/infiniband_pkey/Makefile | 7 ++ tests/infiniband_pkey/create_modify_qp.c | 144 +++++++++++++++++++++++++++++++ tests/infiniband_pkey/ibpkey_test.conf | 18 ++++ tests/infiniband_pkey/test | 84 ++++++++++++++++++ 8 files changed, 291 insertions(+), 3 deletions(-) create mode 100644 policy/test_ibpkey.te create mode 100644 tests/infiniband_pkey/Makefile create mode 100644 tests/infiniband_pkey/create_modify_qp.c create mode 100644 tests/infiniband_pkey/ibpkey_test.conf create mode 100755 tests/infiniband_pkey/test
README +9 -0
@@ -195,3 +195,12 @@ establish a base directory (based on the path of the script executable). This won't always be accurate, but will work for this test harness/configuration. $basedir = $0; $basedir =~ s|(.*)/[^/]*|$1|; + +INFINIBAND TESTS +---------------- +Because running Infiniband tests requires specialized hardware you must +set up a configuration file for these tests. The tests are disabled by +default. See comments in the configuration file for info. + +Infiniband PKey test conf file: +tests/infiniband_pkey/ibpkey_test.conf
policy/Makefile +2 -1
@@ -22,7 +22,8 @@ TARGETS = \ 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_inet_socket.te test_unix_socket.te \ - test_mmap.te test_overlayfs.te test_mqueue.te test_mac_admin.te + test_mmap.te test_overlayfs.te test_mqueue.te test_mac_admin.te \ + test_ibpkey.te ifeq ($(shell [ $(POL_VERS) -ge 24 ] && echo true),true) TARGETS += test_bounds.te
policy/test_ibpkey.te new file +25 -0
@@ -0,0 +1,25 @@ +################################# +# +# Policy for testing Infiniband Pkey access. +# + +attribute ibpkeydomain; + +# Domain for process. +type test_ibpkey_access_t; +domain_type(test_ibpkey_access_t) +unconfined_runs_test(test_ibpkey_access_t) +typeattribute test_ibpkey_access_t testdomain; +typeattribute test_ibpkey_access_t ibpkeydomain; + +dev_rw_infiniband_dev(test_ibpkey_access_t) +dev_rw_sysfs(test_ibpkey_access_t) + +# Define a pkey type for labeling pkeys during the test. +type test_ibpkey_t; +corenet_ib_pkey(test_ibpkey_t) +corenet_ib_access_unlabeled_pkeys(test_ibpkey_access_t) + +# Allow all of these domains to be entered from the sysadm domain. +miscfiles_domain_entry_test_files(ibpkeydomain) +userdom_sysadm_entry_spec_domtrans_to(ibpkeydomain)
tests/Makefile +2 -2
@@ -4,13 +4,13 @@ export CFLAGS+=-g -O0 -Wall -D_GNU_SOURCE DISTRO=$(shell ./os_detect) -SUBDIRS:=domain_trans entrypoint execshare exectrace execute_no_trans \ +SUBDIRS:= 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 file ioctl capable_file capable_net \ capable_sys dyntrans dyntrace bounds nnp mmap unix_socket inet_socket \ - overlay checkreqprot mqueue mac_admin + overlay checkreqprot mqueue mac_admin infiniband_pkey ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true) ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1)
tests/infiniband_pkey/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +TARGETS=create_modify_qp + +LDLIBS+= -libverbs + +all: $(TARGETS) +clean: + rm -f $(TARGETS)
tests/infiniband_pkey/create_modify_qp.c new file +144 -0
144 lines not on this page · raw message
tests/infiniband_pkey/ibpkey_test.conf new file +18 -0
@@ -0,0 +1,18 @@ +# Enable(1)/Disable these tests +SELINUX_INFINIBAND_PKEY_TEST=0 + +# Infiniband device to use. +SELINUX_INFINIBAND_PKEY_TEST_DEV=mlx5_3 + +# Physical port on the device to use. +SELINUX_INFINIBAND_PKEY_TEST_PORT=1 + +# CSV list of pkey table indexes containing labeled PKeys +# These will not be allowed. +SELINUX_INFINIBAND_TEST_LABELED_PKEYS= + +# CSV list of pkey table indexes containing unlabelde PKeys +# This will be allowed, then temporarily labeled to see that +# they are disallowed. +SELINUX_INFINIBAND_TEST_UNLABELED_PKEYS=0 +
tests/infiniband_pkey/test new file +84 -0
84 lines not on this page · raw message
Signature · 1 line
2.12.2
Re: [PATCH v1 1/2] selinux-testsuite: Infiniband pkey tests
Quoted 92 lines · Dan Jurgens
From: Daniel Jurgens <[email protected]>
New tests for infiniband pkeys. Most users don't have Infiniband hardware, and if they do the pkey configuration is not standardized. There is a configuration file for enabling the test and setting environment specific test configurations. If the tests are disabled they
will always show as passed.Signed-off-by Daniel Jurgens <[email protected]>---
v1:
- Synchronized interface names with refpolicy changes.
- Changed pkey test to not assume the default pkey is labeled, instead
it take a list of indexes with labeled and unlabeled pkeys. It checks
that the labeled aren't allowed, unlabeled are allowed, and it labels the unlabeled ones to make sure they aren't allowed when labeled.
---
README | 9 ++ policy/Makefile | 3 +- policy/test_ibpkey.te | 25 ++++++ tests/Makefile | 4 +- tests/infiniband_pkey/Makefile | 7 ++tests/infiniband_pkey/create_modify_qp.c| 144
+++++++++++++++++++++++++++++++
tests/infiniband_pkey/ibpkey_test.conf | 18 ++++ tests/infiniband_pkey/test | 84 ++++++++++++++++++8 files changed, 291 insertions(+), 3 deletions(-)create mode 100644 policy/test_ibpkey.te
create mode 100644 tests/infiniband_pkey/Makefile create mode 100644tests/infiniband_pkey/create_modify_qp.ccreate mode 100644tests/infiniband_pkey/ibpkey_test.confcreate mode 100755 tests/infiniband_pkey/testREADME +0
-0@@ -195,3 +195,12 @@ establish a base directory (based on the path ofthe script
executable). This won't always be accurate, but will work for this test harness/configuration.
$basedir = $0; $basedir =~ s|(.*)/[^/]*|$1|;README +4
-0+ +INFINIBAND TESTS +---------------- +Because running Infiniband tests requires specialized hardware youmust
+set up a configuration file for these tests. The tests are disabled byREADME +4
-0+default. See comments in the configuration file for info. + +Infiniband PKey test conf file: +tests/infiniband_pkey/ibpkey_test.confpolicy/Makefile +0
-0@@ -22,7 +22,8 @@ TARGETS = \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_inet_socket.te test_unix_socket.te \policy/Makefile +0
-1- test_mmap.te test_overlayfs.te test_mqueue.tetest_mac_admin.te
policy/Makefile +1
-0+ test_mmap.te test_overlayfs.te test_mqueue.tetest_mac_admin.te \
policy/Makefile +1
-0+ test_ibpkey.te
ifeq ($(shell [ $(POL_VERS) -ge 24 ] && echo true),true) TARGETS += test_bounds.tepolicy/test_ibpkey.te new file +11
-0@@ -0,0 +1,25 @@ +################################# +# +# Policy for testing Infiniband Pkey access. +# + +attribute ibpkeydomain; + +# Domain for process. +type test_ibpkey_access_t; +domain_type(test_ibpkey_access_t) +unconfined_runs_test(test_ibpkey_access_t)
policy/test_ibpkey.te line 21
Quoted 10 lines
policy/test_ibpkey.te new file +10
-0+typeattribute test_ibpkey_access_t testdomain; +typeattribute test_ibpkey_access_t ibpkeydomain; + +dev_rw_infiniband_dev(test_ibpkey_access_t) +dev_rw_sysfs(test_ibpkey_access_t) + +# Define a pkey type for labeling pkeys during the test. +type test_ibpkey_t; +corenet_ib_pkey(test_ibpkey_t) +corenet_ib_access_unlabeled_pkeys(test_ibpkey_access_t)
This will break the build on current Fedora and RHEL.
So, you can either conditionalize inclusion of test_ibpkey.te in the Makefile (see other examples already there) so that it is omitted entirely if refpolicy lacks the requisite support, or wrap these interface calls with suitable ifdefs, e.g. ifdef(corenet_ib_pkey', corenet_ib_pkey(test_ibpkey_t)
')
...
Probably the latter is best so that we get at least some build testing.
Quoted 12 lines
policy/test_ibpkey.te new file +4
-0+ +# Allow all of these domains to be entered from the sysadm domain. +miscfiles_domain_entry_test_files(ibpkeydomain) +userdom_sysadm_entry_spec_domtrans_to(ibpkeydomain)tests/infiniband_pkey/Makefile new file +0
-0
tests/infiniband_pkey/Makefile line 3
Quoted 3 lines
tests/infiniband_pkey/Makefile new file +3
-0@@ -0,0 +1,7 @@ +TARGETS=create_modify_qp + +LDLIBS+= -libverbs
This is a new build dependency (libibverbs-devel), which should be listed in the README.
Quoted 38 lines
tests/infiniband_pkey/Makefile new file +4
-0+ +all: $(TARGETS) +clean: + rm -f $(TARGETS)tests/infiniband_pkey/create_modify_qp.c new file +27
-0@@ -0,0 +1,144 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <assert.h> +#include <unistd.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <infiniband/verbs.h> + +struct ibv_qp *qp; +struct ibv_context *context; +struct ibv_pd *pd; +struct ibv_cq *cq; +struct ibv_srq *srq; + +void cleanup_ib_rsrc () +{ +ibv_destroy_qp (qp); +ibv_destroy_srq (srq); +ibv_destroy_cq (cq); +ibv_dealloc_pd (pd); +ibv_close_device (context); +} + +int init_ib_rsrc (char * deviceName)
tests/infiniband_pkey/create_modify_qp.c line 37
Quoted 10 lines
tests/infiniband_pkey/create_modify_qp.c new file +10
-0+{ + int ndev = 0; + struct ibv_device **dlist = ibv_get_device_list(&ndev); + struct ibv_device *device = NULL;; +struct ibv_srq_init_attr srqiattr; +struct ibv_qp_init_attr qpiattr; +int i; + +if (!ndev) + {
Can you run these test programs through
astyle --options=none --lineend=linux --mode=c --style=linux -- indent=force-tab=8 --indent-preprocessor --indent-col1-comments --min- conditional-indent=0 --max-instatement-indent=80 --pad-oper --align- pointer=name --align-reference=name --max-code-length=80 --break-after- logical
Quoted 211 lines
tests/infiniband_pkey/create_modify_qp.c new file +11
-0+fprintf (stderr,"No IB devices found.\n" ); +exit (1 ); + } + +for (i =0 ; i < ndev; i++) +if (!strcmp (deviceName, dlist[i]->name)) + device = dlist[i]; + +if (!device) + { + fprintf(stderr, "Couldn't find device %s\n",deviceName);
tests/infiniband_pkey/create_modify_qp.c new file +85
-0+exit (1 ); + } +/* Open context */ + context =ibv_open_device (device); +if (NULL == context) + { +fprintf (stderr,"Unable to open device.\n" ); +exit (1 ); + } + +/* Allocate PD */ + pd =ibv_alloc_pd (context); +if (!pd) + { +fprintf (stderr,"Unable to allocate PD.\n" ); +exit (1 ); + } + +/* Create CQ */ + cq =ibv_create_cq (context,2048 ,NULL ,NULL ,0 ); +if (!cq) + { +fprintf (stderr,"Unable to create cq.\n" ); +exit (1 ); + } + +/* Create SRQ */ +memset (&srqiattr,0 ,sizeof (srqiattr)); + srqiattr.attr.max_wr = 2048; + srqiattr.attr.max_sge = 4; + srqiattr.attr.srq_limit =1024 ; + srq =ibv_create_srq (pd, &srqiattr); +if (NULL == srq) + { +fprintf (stderr,"Unable to create sreq.\n" ); +exit (1 ); + } + +memset (&qpiattr,0 ,sizeof (qpiattr)); + qpiattr.send_cq = cq; + qpiattr.recv_cq = cq; + qpiattr.srq = srq; + qpiattr.cap.max_send_wr =128 ; + qpiattr.cap.max_recv_wr =4 ; + qpiattr.cap.max_send_sge =5 ; + qpiattr.cap.max_recv_sge =4 ; + qpiattr.cap.max_inline_data =512 ; + qpiattr.qp_type =IBV_QPT_RC ; + qpiattr.sq_sig_all =1 ; + qp =ibv_create_qp (pd, &qpiattr); + +if (!qp) + { +fprintf (stderr,"Unable to create QP %d.\n" , i); +exit (1 ); + } + +return 0 ; +} + +int init_rc_qp (uint8_t port,uint16_t pkey_index) +{ +struct ibv_qp_attr attr = { + .qp_state = IBV_QPS_INIT, + .pkey_index = pkey_index, + .port_num = port, + .qp_access_flags = 0 + }; + +return ibv_modify_qp (qp, &attr, + IBV_QP_STATE | + IBV_QP_PKEY_INDEX | + IBV_QP_PORT | + IBV_QP_ACCESS_FLAGS); +} + +int main (int argc,char *argv[]) +{ +uint16_t pkey_index; +uint8_t port; +int ret; + +if (argc !=4 ) + { + printf("Please enter <ib device name> <port number><pkey index>\n");
tests/infiniband_pkey/create_modify_qp.c new file +11
-0+exit (1 ); + } + port =atoi (argv[2 ]); + pkey_index =atoi (argv[3 ]); + +init_ib_rsrc (argv[1 ]); + + ret =init_rc_qp (port, pkey_index); +cleanup_ib_rsrc (); +exit (ret); +}tests/infiniband_pkey/test new file +25
-0@@ -0,0 +1,84 @@ +#!/usr/bin/perl + +use Test; + +BEGIN { plan tests => 3} + +$basedir = $0; $basedir =~ s|(.*)/[^/]*|$1|; + +my %conf; +$confpath = $basedir."/ibpkey_test.conf"; +open($f, $confpath) or die ("Couldn't open $confpath"); +while($r = <$f>) { + if ($r =~ /^\s*#/ || $r =~ /^\s*$/) { next; } + chomp $r; + ($k,$v) = split(/=/, $r); + $conf{$k} = $v; +} +close($f); + +if ($conf{SELINUX_INFINIBAND_PKEY_TEST} eq 1) { + $device = $conf{SELINUX_INFINIBAND_PKEY_TEST_DEV}; + $port = $conf{SELINUX_INFINIBAND_PKEY_TEST_PORT}; + + # Read GID 0, to get the subnet prefix. + $gid_path ="/sys/class/infiniband/".$device."/ports/".$port."/gids/0";
tests/infiniband_pkey/test new file +4
-0+ open($f, $gid_path) or die ("Couldn't open $gid_path"); + $gid = <$f>; + close($f); + # The gid sysfs shows a fully expanded ipv6 address, justtake the
tests/infiniband_pkey/test new file +5
-0+ # top half. + @tmp = unpack('(a20)*', $gid); + $subnet_prefix = $tmp[0].":"; + + @labeled_pkeys = split(/,/,$conf{SELINUX_INFINIBAND_TEST_LABELED_PKEYS});
tests/infiniband_pkey/test new file +1
-0+ @unlabeled_pkeys = split(/,/,$conf{SELINUX_INFINIBAND_TEST_UNLABELED_PKEYS});
tests/infiniband_pkey/test new file +3
-0+ + foreach (@unlabeled_pkeys) { + $result = system "runcon -t test_ibpkey_access_t$basedir/create_modify_qp $device $port $_";
tests/infiniband_pkey/test new file +12
-0+ if($result ne 0) { + last; + } + } + if (@unlabeled_pkeys) { + ok($result, 0); + } else { + ok(1); + } + + foreach (@unlabeled_pkeys) { + $pkey_path ="/sys/class/infiniband/".$device."/ports/".$port."/pkeys/".$_;
tests/infiniband_pkey/test new file +1
-0+ open($f, $pkey_path) or die ("Couldn't open$pkey_path");
tests/infiniband_pkey/test new file +4
-0+ $pkey_val = <$f>; + close($f); + + system "semanage ibpkey -a -t test_ibpkey_t -x$subnet_prefix $pkey_val";
tests/infiniband_pkey/test new file +1
-0+ $result = system "runcon -t test_ibpkey_access_t$basedir/create_modify_qp $device $port $_";
tests/infiniband_pkey/test new file +1
-0+ system "semanage ibpkey -d -t test_ibpkey_t -x$subnet_prefix $pkey_val";
tests/infiniband_pkey/test new file +12
-0+ if ($result>>8 ne 13) { + last; + } + } + if (@unlabeled_pkeys) { + ok($result>>8, 13); + } else { + ok(1); + } + + foreach (@labeled_pkeys) { + $result = system "runcon -t test_ibpkey_access_t$basedir/create_modify_qp $device $port $_";
tests/infiniband_pkey/test new file +15
-0+ if ($result>>8 ne 13) { + last; + } + } + if (@labeled_pkeys) { + ok($result>>8, 13); + } else { + ok(1); + } +} else { + ok(1); + ok(1); + ok(1); +} +exit;
Paul Moore
maintainerRe: [PATCH v1 1/2] selinux-testsuite: Infiniband pkey tests
Quoted 11 lines · Stephen Smalley
Quoted 10 lines · Dan Jurgens
From: Daniel Jurgens <[email protected]>
New tests for infiniband pkeys. Most users don't have Infiniband hardware, and if they do the pkey configuration is not standardized. There is a configuration file for enabling the test and setting environment specific test configurations. If the tests are disabled they
will always show as passed.Signed-off-by Daniel Jurgens <[email protected]>
...
Quoted 43 lines
Quoted 43 lines
tests/infiniband_pkey/create_modify_qp.c new file +36
-0@@ -0,0 +1,144 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <assert.h> +#include <unistd.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <infiniband/verbs.h> + +struct ibv_qp *qp; +struct ibv_context *context; +struct ibv_pd *pd; +struct ibv_cq *cq; +struct ibv_srq *srq; + +void cleanup_ib_rsrc () +{ +ibv_destroy_qp (qp); +ibv_destroy_srq (srq); +ibv_destroy_cq (cq); +ibv_dealloc_pd (pd); +ibv_close_device (context); +} + +int init_ib_rsrc (char * deviceName) +{ +int ndev =0 ; +struct ibv_device **dlist =ibv_get_device_list (&ndev); +struct ibv_device *device =NULL ;; +struct ibv_srq_init_attr srqiattr; +struct ibv_qp_init_attr qpiattr; +int i; + +if (!ndev)
Quoted 8 lines
tests/infiniband_pkey/create_modify_qp.c line 37
Quoted 1 line
tests/infiniband_pkey/create_modify_qp.c new file +1
-0+ {Can you run these test programs through
astyle --options=none --lineend=linux --mode=c --style=linux -- indent=force-tab=8 --indent-preprocessor --indent-col1-comments --min- conditional-indent=0 --max-instatement-indent=80 --pad-oper --align- pointer=name --align-reference=name --max-code-length=80 --break-after- logical
FYI, the tools/check-syntax should be able to fixup the sources for you.
Signature · 2 lines
paul moore www.paul-moore.com
Re: [PATCH v1 1/2] selinux-testsuite: Infiniband pkey tests
In reply to Stephen SmalleyQuoted 15 lines · Stephen Smalley
policy/test_ibpkey.te line 21
Quoted 4 lines · Dan Jurgens
From: Daniel Jurgens <[email protected]>
policy/test_ibpkey.te new file +2
-0+corenet_ib_pkey(test_ibpkey_t) +corenet_ib_access_unlabeled_pkeys(test_ibpkey_access_t)This will break the build on current Fedora and RHEL.
So, you can either conditionalize inclusion of test_ibpkey.te in theMakefile(see other examples already there) so that it is omitted entirely if refpolicy lacks the requisite support, or wrap these interface calls with suitable ifdefs, e.g. ifdef(corenet_ib_pkey',corenet_ib_pkey(test_ibpkey_t)
')
...
Quoted 1 line
Probably the latter is best so that we get at least some build testing.
Done, with ifdefs.
Quoted 7 lines
tests/infiniband_pkey/Makefile line 3
Quoted 5 lines
tests/infiniband_pkey/Makefile new file +4
-0+ +TARGETS=create_modify_qp + +LDLIBS+= -libverbsThis is a new build dependency (libibverbs-devel), which should be listed in the README.
Done
Quoted 10 lines
Quoted 10 lines
tests/infiniband_pkey/create_modify_qp.c new file +9
-0+int init_ib_rsrc (char * deviceName) +{ +int ndev =0 ; +struct ibv_device **dlist =ibv_get_device_list (&ndev); +struct ibv_device *device =NULL ;; +struct ibv_srq_init_attr srqiattr; +struct ibv_qp_init_attr qpiattr; +int i; +
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!ndev) + {Can you run these test programs through
astyle --options=none --lineend=linux --mode=c --style=linux -- indent=force-tab=8 --indent-preprocessor --indent-col1-comments --min- conditional-indent=0 --max-instatement-indent=80 --pad-oper --align- pointer=name --align-reference=name --max-code-length=80 --break-after- logical
Done.
PATCH 2/2 selinux-testsuite: Infiniband endport tests
In reply to Dan JurgensFrom: Daniel Jurgens <[email protected]>
New tests for Infiniband endports. Most users do not have infiniband hardware, and if they do the device names can vary. There is a configuration file for enabling the tests and setting environment specific configurations. If the tests are disabled they always show as passed.
A special test application was unnecessary, a standard diagnostic application is used instead. This required a change to the make file to avoid trying to build an application in the new subdir.
---
v1:
- Synchronize interface names with refpolicy changes.
- Allowed access to unlabeled pkeys vs default pkey, default pkey is no longer labeled in the refpolicy.
--- README | 7 +++- policy/Makefile | 2 +- policy/test_ibendport.te | 35 ++++++++++++++++++++ tests/Makefile | 4 ++- tests/infiniband_endport/ibendport_test.conf | 14 ++++++++ tests/infiniband_endport/test | 49 ++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 policy/test_ibendport.te create mode 100644 tests/infiniband_endport/ibendport_test.conf create mode 100644 tests/infiniband_endport/test
README +6 -1
@@ -200,7 +200,12 @@ INFINIBAND TESTS ---------------- Because running Infiniband tests requires specialized hardware you must set up a configuration file for these tests. The tests are disabled by -default. See comments in the configuration file for info. +default. See comments in the configuration file for info. The endport +tests use smpquery, for Fedora it's provided by the infiniband-diags +package. Infiniband PKey test conf file: tests/infiniband_pkey/ibpkey_test.conf + +Infiniband Endport test conf file: +tests/infiniband_endport/ibendport_test.conf
policy/Makefile +1 -1
@@ -23,7 +23,7 @@ TARGETS = \ test_task_getsid.te test_task_setpgid.te test_task_setsched.te \ test_transition.te test_inet_socket.te test_unix_socket.te \ test_mmap.te test_overlayfs.te test_mqueue.te test_mac_admin.te \ - test_ibpkey.te + test_ibpkey.te test_ibendport.te ifeq ($(shell [ $(POL_VERS) -ge 24 ] && echo true),true) TARGETS += test_bounds.te
policy/test_ibendport.te new file +35 -0
@@ -0,0 +1,35 @@ +################################# +# +# Policy for testing Infiniband Pkey access. +# + +gen_require(` + type bin_t; + type infiniband_mgmt_device_t; +') + +attribute ibendportdomain; + +# Domain for process. +type test_ibendport_manage_subnet_t; +domain_type(test_ibendport_manage_subnet_t) +unconfined_runs_test(test_ibendport_manage_subnet_t) +typeattribute test_ibendport_manage_subnet_t testdomain; +typeattribute test_ibendport_manage_subnet_t ibendportdomain; + +type test_ibendport_t; +corenet_ib_endport(test_ibendport_t) + +dev_rw_infiniband_dev(test_ibendport_manage_subnet_t) +dev_rw_sysfs(test_ibendport_manage_subnet_t) + +allow test_ibendport_manage_subnet_t bin_t:file entrypoint; +allow test_ibendport_manage_subnet_t bin_t:file execute; +allow test_ibendport_manage_subnet_t infiniband_mgmt_device_t:chr_file { read write open ioctl}; +corenet_ib_access_unlabeled_pkeys(test_ibendport_manage_subnet_t) + +allow test_ibendport_manage_subnet_t test_ibendport_t:infiniband_endport manage_subnet; + +# Allow all of these domains to be entered from the sysadm domain. +miscfiles_domain_entry_test_files(ibendportdomain) +userdom_sysadm_entry_spec_domtrans_to(ibendportdomain)
tests/Makefile +3 -1
@@ -12,6 +12,8 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \ capable_sys dyntrans dyntrace bounds nnp mmap unix_socket inet_socket \ overlay checkreqprot mqueue mac_admin infiniband_pkey +SUBDIRS_NO_MAKE:= infiniband_endport + ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true) ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1) SUBDIRS += cap_userns
@@ -56,7 +58,7 @@ all: test: all chcon -R -t test_file_t . - @SUBDIRS="$(SUBDIRS)" PATH=/usr/bin:/bin:/usr/sbin:/sbin ./runtests.pl + @SUBDIRS="$(SUBDIRS) $(SUBDIRS_NO_MAKE)" PATH=/usr/bin:/bin:/usr/sbin:/sbin ./runtests.pl clean: @for subdir in $(SUBDIRS); do \
tests/infiniband_endport/ibendport_test.conf new file +14 -0
@@ -0,0 +1,14 @@ +# Enable(1)/Disable these tests. +SELINUX_INFINIBAND_ENDPORT_TEST=0 + +# Device/port pair that should allow access. +# The test uses semanage to allow, because +# ibendports are all unlabeled by default +# the reference policy. This allows using +# the same device and port for both the pass +# and fail testing as well. +SELINUX_INFINIBAND_ENDPORT_TEST_ALLOWED=mlx5_3 1 + +# Device/port pairs that should deny access. +SELINUX_INFINIBAND_ENDPORT_TEST_DENIED=mlx5_2 1 +
tests/infiniband_endport/test new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.12.2
Re: [PATCH v1 2/2] selinux-testsuite: Infiniband endport tests
Quoted 94 lines · Dan Jurgens
From: Daniel Jurgens <[email protected]>
New tests for Infiniband endports. Most users do not have infiniband hardware, and if they do the device names can vary. There is a configuration file for enabling the tests and setting environment specific configurations. If the tests are disabled they always show as
passed.A special test application was unnecessary, a standard diagnostic application is used instead. This required a change to the make file to avoid trying to build an application in the new subdir.
Signed-off-by Daniel Jurgens <[email protected]>---
v1:
- Synchronize interface names with refpolicy changes.
- Allowed access to unlabeled pkeys vs default pkey, default pkey is no
longer labeled in the refpolicy.
---
README | 7 +++- policy/Makefile | 2 +- policy/test_ibendport.te | 35
++++++++++++++++++++
tests/Makefile | 4 ++-tests/infiniband_endport/ibendport_test.conf| 14 ++++++++ tests/infiniband_endport/test | 49
++++++++++++++++++++++++++++6 files changed, 108 insertions(+), 3 deletions(-)create mode 100644 policy/test_ibendport.te
create mode 100644tests/infiniband_endport/ibendport_test.confcreate mode 100644 tests/infiniband_endport/testREADME +0
-0@@ -200,7 +200,12 @@ INFINIBAND TESTS----------------
Because running Infiniband tests requires specialized hardware you must
set up a configuration file for these tests. The tests are disabled byREADME +1
-1-default. See comments in the configuration file for info. +default. See comments in the configuration file for info. Theendport
README +2
-0+tests use smpquery, for Fedora it's provided by the infiniband-diags +package.
Infiniband PKey test conf file:
tests/infiniband_pkey/ibpkey_test.confREADME +3
-0+ +Infiniband Endport test conf file: +tests/infiniband_endport/ibendport_test.confpolicy/Makefile +0
-0@@ -23,7 +23,7 @@ TARGETS = \test_task_getsid.te test_task_setpgid.te test_task_setsched.te \
test_transition.te test_inet_socket.te test_unix_socket.te \
test_mmap.te test_overlayfs.te test_mqueue.te test_mac_admin.te \policy/Makefile +1
-1- test_ibpkey.te + test_ibpkey.te test_ibendport.te
ifeq ($(shell [ $(POL_VERS) -ge 24 ] && echo true),true) TARGETS += test_bounds.tepolicy/test_ibendport.te new file +17
-0@@ -0,0 +1,35 @@ +################################# +# +# Policy for testing Infiniband Pkey access. +# + +gen_require(` + type bin_t; + type infiniband_mgmt_device_t; +') + +attribute ibendportdomain; + +# Domain for process. +type test_ibendport_manage_subnet_t; +domain_type(test_ibendport_manage_subnet_t) +unconfined_runs_test(test_ibendport_manage_subnet_t) +typeattribute test_ibendport_manage_subnet_t testdomain;
policy/test_ibendport.te line 27
Quoted 10 lines
policy/test_ibendport.te new file +10
-0+typeattribute test_ibendport_manage_subnet_t ibendportdomain; + +type test_ibendport_t; +corenet_ib_endport(test_ibendport_t) + +dev_rw_infiniband_dev(test_ibendport_manage_subnet_t) +dev_rw_sysfs(test_ibendport_manage_subnet_t) + +allow test_ibendport_manage_subnet_t bin_t:file entrypoint; +allow test_ibendport_manage_subnet_t bin_t:file execute;
Just use:corecmd_bin_entry_type(test_ibendport_manage_subnet_t)
Quoted 3 lines
policy/test_ibendport.te new file +1
-0+allow test_ibendport_manage_subnet_tinfiniband_mgmt_device_t:chr_file { read write open ioctl}; +corenet_ib_access_unlabeled_pkeys(test_ibendport_manage_subnet_t)
This interface needs to be wrapped with an ifdef if this file is not excluded when refpolicy lacks the necessary definitions.
Quoted 3 lines
policy/test_ibendport.te new file +2
-0+ +allow test_ibendport_manage_subnet_ttest_ibendport_t:infiniband_endport
manage_subnet;
This needs to be conditional on the definition of this class. You could either omit the .te file altogether in the Makefile if not defined, as we do for e.g. cap_userns, icmp_socket, etc, or you need to
wrap it conditionally as we do for e.g. map permission.
Quoted 27 lines
policy/test_ibendport.te new file +4
-0+ +# Allow all of these domains to be entered from the sysadm domain. +miscfiles_domain_entry_test_files(ibendportdomain) +userdom_sysadm_entry_spec_domtrans_to(ibendportdomain)tests/Makefile +0
-0@@ -12,6 +12,8 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \
capable_sysdyntrans dyntrace bounds nnp mmapunix_socketinet_socket\
overlay checkreqprot mqueuemac_admininfiniband_pkeytests/Makefile +2
-0+SUBDIRS_NO_MAKE:= infiniband_endport +ifeq ($(shell grep -q
cap_userns$(POLDEV)/include/support/all_perms.spt && echo true),true) ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1) SUBDIRS +=cap_usernstests/Makefile +0
-0@@ -56,7 +58,7 @@ all:
test: all
chcon -R -ttest_file_t.tests/Makefile +0
-1- @SUBDIRS="$(SUBDIRS)" PATH=/usr/bin:/bin:/usr/sbin:/sbin./runtests.pl
tests/Makefile +1
-0+ @SUBDIRS="$(SUBDIRS) $(SUBDIRS_NO_MAKE)"
Quoted 1 line
PATH=/usr/bin:/bin:/usr/sbin:/sbin ./runtests.pl
This works, but elsewhere we've always just put a trivial Makefile with empty all: and clean: targets in it, e.g. entrypoint/Makefile. No big deal either way.
Quoted 88 lines
clean:
@for subdir in $(SUBDIRS); do \tests/infiniband_endport/ibendport_test.conf new file +14
-0@@ -0,0 +1,14 @@ +# Enable(1)/Disable these tests. +SELINUX_INFINIBAND_ENDPORT_TEST=0 + +# Device/port pair that should allow access. +# The test uses semanage to allow, because +# ibendports are all unlabeled by default +# the reference policy. This allows using +# the same device and port for both the pass +# and fail testing as well. +SELINUX_INFINIBAND_ENDPORT_TEST_ALLOWED=mlx5_3 1 + +# Device/port pairs that should deny access. +SELINUX_INFINIBAND_ENDPORT_TEST_DENIED=mlx5_2 1 +tests/infiniband_endport/test new file +20
-0@@ -0,0 +1,49 @@ +#!/usr/bin/perl + +use Test; + +BEGIN { plan tests => 2} + +$basedir = $0; $basedir =~ s|(.*)/[^/]*|$1|; + +my %conf; +my $confpath = $basedir."/ibendport_test.conf"; +open($f, $confpath) or die ("Couldn't open ibtest.conf"); +while($r = <$f>) { + if ($r =~ /^\s*#/ || $r =~ /^\s*$/) { next; } + chomp $r; + ($k,$v) = split(/=/, $r); + $conf{$k} = $v; +} + +if ($conf{SELINUX_INFINIBAND_ENDPORT_TEST} eq 1) { + @allowed_device_port = split(/,/,$conf{SELINUX_INFINIBAND_ENDPORT_TEST_ALLOWED});
tests/infiniband_endport/test new file +1
-0+ @denied_device_port = split(/,/,$conf{SELINUX_INFINIBAND_ENDPORT_TEST_DENIED});
tests/infiniband_endport/test new file +5
-0+ + foreach (@allowed_device_port) { + @dev_port_pair= split(/ /, $_); + + system "semanage ibendport -a -t test_ibendport_t -z$_ 2>/dev/null";
tests/infiniband_endport/test new file +1
-0+ $result = system "runcon -t
test_ibendport_manage_subnet_tsmpquery PKeyTable -C $dev_port_pair[0] -P $dev_port_pair[1] -D 1 2>/dev/null";tests/infiniband_endport/test new file +1
-0+ system "semanage ibendport -d -t test_ibendport_t -z$_ 2>/dev/null";
tests/infiniband_endport/test new file +9
-0+ if($result ne 0) { + last; + } + } + ok($result, 0); + + foreach (@denied_device_port) { + @dev_port_pair= split(/ /, $_); + $result = system "runcon -t
test_ibendport_manage_subnet_tsmpquery PKeyTable -C $dev_port_pair[0] -P $dev_port_pair[1] -D 1 2>/dev/null";tests/infiniband_endport/test new file +12
-0+ + if ($result>>8 eq 0) { + last; + } + } + + ok(int($result>>8) ne 0); +} else { + ok(1); + ok(1); +} +exit;
Paul Moore
maintainerRe: [PATCH v1 2/2] selinux-testsuite: Infiniband endport tests
Quoted 15 lines · Stephen Smalley
Quoted 14 lines · Dan Jurgens
From: Daniel Jurgens <[email protected]>
New tests for Infiniband endports. Most users do not have infiniband hardware, and if they do the device names can vary. There is a configuration file for enabling the tests and setting environment specific configurations. If the tests are disabled they always show as
passed.A special test application was unnecessary, a standard diagnostic application is used instead. This required a change to the make file to avoid trying to build an application in the new subdir.
Signed-off-by Daniel Jurgens <[email protected]>
...
Quoted 22 lines
Quoted 22 lines
policy/test_ibendport.te new file +4
-0+ +# Allow all of these domains to be entered from the sysadm domain. +miscfiles_domain_entry_test_files(ibendportdomain) +userdom_sysadm_entry_spec_domtrans_to(ibendportdomain)tests/Makefile +2
-0@@ -12,6 +12,8 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \ capable_sys dyntrans dyntrace bounds nnp mmap unix_socket inet_socket \ overlay checkreqprot mqueue mac_admin infiniband_pkey +SUBDIRS_NO_MAKE:= infiniband_endport + ifeq ($(shell grep -q cap_userns$(POLDEV)/include/support/all_perms.spt && echo true),true)
ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1) SUBDIRS +=cap_usernstests/Makefile +0
-0@@ -56,7 +58,7 @@ all:
Quoted 10 lines
Quoted 6 lines
tests/Makefile +0
-1test: all chcon -R -t test_file_t . - @SUBDIRS="$(SUBDIRS)" PATH=/usr/bin:/bin:/usr/sbin:/sbin./runtests.pl
+ @SUBDIRS="$(SUBDIRS) $(SUBDIRS_NO_MAKE)"
PATH=/usr/bin:/bin:/usr/sbin:/sbin ./runtests.plThis works, but elsewhere we've always just put a trivial
Makefilewith empty all: and clean: targets in it, e.g. entrypoint/Makefile. No big deal either way.
Since it looks like this needs a respin anyway to fix other issues, I'd probably prefer the entrypoint/Makefile approach for the sake of consistency.
Signature · 2 lines
paul moore www.paul-moore.com
Re: [PATCH v1 2/2] selinux-testsuite: Infiniband endport tests
In reply to Stephen SmalleyQuoted 8 lines · Stephen Smalley
policy/test_ibendport.te line 27
Quoted 5 lines · Dan Jurgens
From: Daniel Jurgens <[email protected]>
policy/test_ibendport.te new file +2
-0+allow test_ibendport_manage_subnet_t bin_t:file entrypoint; +allow test_ibendport_manage_subnet_t bin_t:file execute;Just use:
corecmd_bin_entry_type(test_ibendport_manage_subnet_t)
Done
Quoted 6 lines
Quoted 4 lines
+allow
test_ibendport_manage_subnet_tinfiniband_mgmt_device_t:chr_file { read write open ioctl}; +corenet_ib_access_unlabeled_pkeys(test_ibendport_manage_subnet_t)This interface needs to be wrapped with an ifdef if this file is not excluded when refpolicy lacks the necessary definitions.
Done
Quoted 7 lines
Quoted 3 lines
(quoted diff) +2
-0+ +allow test_ibendport_manage_subnet_ttest_ibendport_t:infiniband_endport
manage_subnet;This needs to be conditional on the definition of this class. You could either omit the .te file altogether in the
Makefileif not defined, as we do for e.g.cap_userns,icmp_socket, etc, or you need to
wrap it conditionally as we do for e.g. map permission.
Excluded building the .te file if the class is not defined.
Quoted 6 lines
Quoted 3 lines
(quoted diff) +1
-0+ @SUBDIRS="$(SUBDIRS) $(SUBDIRS_NO_MAKE)"PATH=/usr/bin:/bin:/usr/sbin:/sbin ./runtests.pl
This works, but elsewhere we've always just put a trivial
Makefilewith empty all: and clean: targets in it, e.g. entrypoint/Makefile. No big deal either way.
Switched to a stub makefile.