Skip to content

Commit

Permalink
libsepol/tests: add test for segregate attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
  • Loading branch information
cgzones committed Jun 29, 2022
1 parent aa43363 commit 5ff7343
Show file tree
Hide file tree
Showing 8 changed files with 394 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libsepol/tests/libsepol-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "test-expander.h"
#include "test-deps.h"
#include "test-downgrade.h"
#include "test-segregateattributes.h"

#include <CUnit/Basic.h>
#include <CUnit/Console.h>
Expand Down Expand Up @@ -69,6 +70,7 @@ static bool do_tests(int interactive, int verbose)
DECLARE_SUITE(expander);
DECLARE_SUITE(deps);
DECLARE_SUITE(downgrade);
DECLARE_SUITE(sattrs);

if (verbose)
CU_basic_set_mode(CU_BRM_VERBOSE);
Expand Down
87 changes: 87 additions & 0 deletions libsepol/tests/policies/test-sattrs/single.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
class process
class blk_file
class chr_file
class dir
class fifo_file
class file
class lnk_file
class sock_file

sid kernel
sid security
sid unlabeled
sid file
sid port
sid netif
sid netmsg
sid node
sid devnull

class process { dyntransition transition }
class file { write }

ifdef(`enable_mls',`
sensitivity s0;
dominance { s0 }
category c0; category c1; category c2; category c3;
category c4; category c5; category c6; category c7;
category c8; category c9; category c10; category c11;
category c12; category c13; category c14; category c15;
category c16; category c17; category c18; category c19;
category c20; category c21; category c22; category c23;

level s0:c0.c23;

mlsconstrain file { write } ( h1 dom h2 );
')

#
# Test start
#

attribute test1_attr1;
attribute test1_attr2;
type test1_type;
typeattribute test1_type test1_attr1;
typeattribute test1_type test1_attr2;
segregate_attributes test1_attr1, test1_attr2;


attribute test2_attr1;
attribute test2_attr2;
attribute test2_attr3;
type test2_type1;
type test2_type2;
type test2_type3;
type test2_type4;
typeattribute test2_type1 test2_attr1;
typeattribute test2_type1 test2_attr2;
typeattribute test2_type2 test2_attr1;
typeattribute test2_type2 test2_attr3;
typeattribute test2_type3 test2_attr2;
typeattribute test2_type3 test2_attr3;
typeattribute test2_type4 test2_attr1;
typeattribute test2_type4 test2_attr2;
typeattribute test2_type4 test2_attr3;
segregate_attributes test2_attr1, test2_attr2, test2_attr3;

#
# Test End
#

type sys_isid;
allow sys_isid self : process { dyntransition transition };
role sys_role;
role sys_role types sys_isid;
gen_user(sys_user,, sys_role, s0, s0 - s0:c0.c23)
sid kernel gen_context(sys_user:sys_role:sys_isid, s0)
sid security gen_context(sys_user:sys_role:sys_isid, s0)
sid unlabeled gen_context(sys_user:sys_role:sys_isid, s0)
sid file gen_context(sys_user:sys_role:sys_isid, s0)
sid port gen_context(sys_user:sys_role:sys_isid, s0)
sid netif gen_context(sys_user:sys_role:sys_isid, s0)
sid netmsg gen_context(sys_user:sys_role:sys_isid, s0)
sid node gen_context(sys_user:sys_role:sys_isid, s0)
sid devnull gen_context(sys_user:sys_role:sys_isid, s0)
fs_use_trans devpts gen_context(sys_user:sys_role:sys_isid, s0);
fs_use_trans devtmpfs gen_context(sys_user:sys_role:sys_isid, s0);
53 changes: 53 additions & 0 deletions libsepol/tests/policies/test-sattrs/split_base.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class process
class blk_file
class chr_file
class dir
class fifo_file
class file
class lnk_file
class sock_file

sid kernel
sid security
sid unlabeled
sid file
sid port
sid netif
sid netmsg
sid node
sid devnull

class process { dyntransition transition }
class file { write }

ifdef(`enable_mls',`
sensitivity s0;
dominance { s0 }
category c0; category c1; category c2; category c3;
category c4; category c5; category c6; category c7;
category c8; category c9; category c10; category c11;
category c12; category c13; category c14; category c15;
category c16; category c17; category c18; category c19;
category c20; category c21; category c22; category c23;

level s0:c0.c23;

mlsconstrain file { write } ( h1 dom h2 );
')

type sys_isid;
allow sys_isid self : process { dyntransition transition };
role sys_role;
role sys_role types sys_isid;
gen_user(sys_user,, sys_role, s0, s0 - s0:c0.c23)
sid kernel gen_context(sys_user:sys_role:sys_isid, s0)
sid security gen_context(sys_user:sys_role:sys_isid, s0)
sid unlabeled gen_context(sys_user:sys_role:sys_isid, s0)
sid file gen_context(sys_user:sys_role:sys_isid, s0)
sid port gen_context(sys_user:sys_role:sys_isid, s0)
sid netif gen_context(sys_user:sys_role:sys_isid, s0)
sid netmsg gen_context(sys_user:sys_role:sys_isid, s0)
sid node gen_context(sys_user:sys_role:sys_isid, s0)
sid devnull gen_context(sys_user:sys_role:sys_isid, s0)
fs_use_trans devpts gen_context(sys_user:sys_role:sys_isid, s0);
fs_use_trans devtmpfs gen_context(sys_user:sys_role:sys_isid, s0);
9 changes: 9 additions & 0 deletions libsepol/tests/policies/test-sattrs/split_module1.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module sattrs_test_1 1.0;

require {
type test_type_t;
}

attribute attr1;

typeattribute test_type_t attr1;
9 changes: 9 additions & 0 deletions libsepol/tests/policies/test-sattrs/split_module2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module sattrs_test_2 1.0;

require {
type test_type_t;
}

attribute attr2;

typeattribute test_type_t attr2;
9 changes: 9 additions & 0 deletions libsepol/tests/policies/test-sattrs/split_module3.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module sattrs_test_3 1.0;

require {
attribute attr1, attr2;
}

type test_type_t;

segregate_attributes attr1, attr2;
Loading

0 comments on commit 5ff7343

Please sign in to comment.