-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libsepol/tests: add cond xperm neverallow tests
Add some tests to verify assertion checking works for extended permissions in conditional policies. Signed-off-by: Christian Göttsche <[email protected]> --- v3: add patch
- Loading branch information
Showing
3 changed files
with
309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
251 changes: 251 additions & 0 deletions
251
libsepol/tests/policies/test-neverallow/policy_cond.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
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 { getattr ioctl open read write } | ||
|
||
bool boolean1 false; | ||
bool boolean2 true; | ||
|
||
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 | ||
# | ||
######################################## | ||
|
||
|
||
## Test 1 (basic - fail) | ||
|
||
type test1_t; | ||
if boolean1 { | ||
allow test1_t self : file read; | ||
} | ||
neverallow test1_t * : file *; | ||
|
||
|
||
## Test 2 (basic - fail) | ||
|
||
attribute test2_a; | ||
type test2_1_t, test2_a; | ||
type test2_2_t; | ||
if !boolean1 { | ||
allow test2_1_t test2_1_t : file write; | ||
allow test2_2_t test2_2_t : file write; | ||
} | ||
neverallow test2_a * : file *; | ||
|
||
|
||
## Test 3 (xperm - no xperm in one branch - fail) | ||
|
||
type test3_t; | ||
if boolean1 { | ||
allow test3_t self : file ioctl; | ||
} else { | ||
allowxperm test3_t self : file ioctl 0x1; | ||
} | ||
neverallowxperm test3_t self : file ioctl 0x4; | ||
|
||
|
||
## Test 4 (xperm - xperm in neither branch - fail) | ||
|
||
type test4_t; | ||
allow test4_t self : file ioctl; | ||
if boolean1 { | ||
allow test4_t self : file read; | ||
} else { | ||
allow test4_t self : file write; | ||
} | ||
neverallowxperm test4_t self : file ioctl 0x4; | ||
|
||
|
||
## Test 5 (xperm - xperm in both branches - no failure) | ||
|
||
type test5_t; | ||
allow test5_t self : file ioctl; | ||
if boolean1 { | ||
allowxperm test5_t self : file ioctl 0x1; | ||
} else { | ||
allowxperm test5_t self : file ioctl 0x2; | ||
} | ||
neverallowxperm test5_t self : file ioctl 0x4; # nofail | ||
|
||
|
||
## Test 6 (xperm - failure in one branch - fail) | ||
|
||
type test6_t; | ||
if boolean1 { | ||
allow test6_t self : file ioctl; | ||
allowxperm test6_t self : file ioctl 0x1; | ||
} else { | ||
allow test6_t self : file write; | ||
} | ||
neverallowxperm test6_t self : file ioctl 0x1; | ||
|
||
|
||
## Test 7 (xperm - failure in both branches - fail) | ||
|
||
type test7_t; | ||
if boolean1 { | ||
allow test7_t self : file ioctl; | ||
allowxperm test7_t self : file ioctl 0x1; | ||
} else { | ||
allow test7_t self : file ioctl; | ||
allowxperm test7_t self : file ioctl 0x2; | ||
} | ||
neverallowxperm test7_t self : file ioctl { 0x1-0x2 }; | ||
|
||
|
||
## Test 8 (xperm - different xperm in both branches - no failure) | ||
|
||
type test8_t; | ||
allow test8_t self : file ioctl; | ||
if boolean1 { | ||
allowxperm test8_t self : file ioctl 0x1; | ||
} else { | ||
allowxperm test8_t self : file ioctl 0x2; | ||
} | ||
neverallowxperm test8_t self : file ioctl 0x3; # nofail | ||
|
||
|
||
## Test 9 (xperm - rules split into two booleans - no failure) | ||
|
||
type test9_t; | ||
allow test9_t self : file ioctl; | ||
if boolean1 { | ||
allowxperm test9_t self : file ioctl 0x1; | ||
} | ||
if !boolean2 { | ||
allowxperm test9_t self : file ioctl 0x1; | ||
} | ||
neverallowxperm test9_t self : file ioctl 0x4; | ||
|
||
|
||
## Test 10 (xperm - valid usage in one branch - no failure) | ||
|
||
type test10_t; | ||
if boolean1 { | ||
allow test10_t self : file ioctl; | ||
allowxperm test10_t self : file ioctl 0x1; | ||
} else { | ||
allow test10_t self : file write; | ||
} | ||
neverallowxperm test10_t self : file ioctl 0x2; # nofail | ||
|
||
|
||
## Test 11 (xperm - valid usage in both branches - no failure) | ||
|
||
type test11_t; | ||
if boolean1 { | ||
allow test11_t self : file ioctl; | ||
allowxperm test11_t self : file ioctl 0x1; | ||
} else { | ||
allow test11_t self : file ioctl; | ||
allowxperm test11_t self : file ioctl 0x2; | ||
} | ||
neverallowxperm test11_t self : file ioctl 0x3; # nofail | ||
|
||
|
||
## Test 12 (xperm - base allow in one branch - fail) | ||
|
||
type test12_t; | ||
if boolean1 { | ||
allow test12_t self : file ioctl; | ||
} else { | ||
allow test12_t self : file write; | ||
} | ||
neverallowxperm test12_t self : file ioctl 0x1; | ||
|
||
|
||
## Test 13 (xperm - invalid second branch - fail) | ||
|
||
type test13_t; | ||
allow test13_t self : file ioctl; | ||
if boolean1 { | ||
allow test13_t self : file ioctl; | ||
allowxperm test13_t self : file ioctl 0x1; | ||
} else { | ||
allow test13_t self : file write; | ||
} | ||
neverallowxperm test13_t self : file ioctl 0x1; | ||
|
||
|
||
## Test 14 (xperm - invalid second branch - fail) | ||
|
||
type test14_t; | ||
allow test14_t self : file ioctl; | ||
if boolean1 { | ||
allow test14_t self : file ioctl; | ||
allowxperm test14_t self : file ioctl 0x1; | ||
} else { | ||
allow test14_t self : file write; | ||
} | ||
neverallowxperm test14_t self : file ioctl 0x2; | ||
|
||
|
||
## Test 15 (xperm - base uncond in one branch - fail) | ||
|
||
type test15_t; | ||
allow test15_t self : file ioctl; | ||
allowxperm test15_t self : file ioctl 0x1; | ||
if boolean1 { | ||
allow test15_t self : file ioctl; | ||
} else { | ||
allow test15_t self : file write; | ||
} | ||
neverallowxperm test15_t self : file ioctl 0x2; | ||
|
||
|
||
######################################## | ||
# | ||
# Test End | ||
# | ||
######################################## | ||
|
||
|
||
type sys_isid; | ||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters