setools/tests
James Carter 89cad5e1b7 Change how differences in AV rules are generated in sediff
The primary motivation for the change is to correctly handle redundant
rules. Recent changes in the SELinux toolchain added support for an
optimization that removes redundant rules from a policy. These are
conditional rules that are either already specified in unconditional
policy or rules using types that are also specified more generally
through an attribute. Since attributes are always expanded in sediff,
the second type of redundant rules are already effectively removed. But
redundant conditional rules show up as differences when a binary version
of a policy that has been optimized is compared to one that has not been.

A secondary motivation for the change is to reduce memory usage and diff
times. A modern Fedora policy cannot be diffed with a system with less than
32Gb of memory and it takes over four hours to complete.

With this change AV rules are processed by creating a data structure which
consists of nested dictionaries that store BOTH the left and the right
policies. All of the keys are interned strings to save space.

The basic structure is
  rule_db[cond_exp][block_bool][src][tgt][tclass]=sides
where:
  cond_exp is a boolean expression
  block_bool is either true or false
  src is the source type
  tgt is the target type
  tclass is the target class
  sides is a namedtuple with "left" and "right" attributes
    Each side is either None or another namedtuple with "perms" and
    "orig_rule" attributes
      perms is the set of permissions for this rule
      orig_rule is the original unexpanded rule

These changes improve diff times and memory usage.
Without the change
                         Time        Memory Usage
Older Fedora Policy    3 min 17 sec      4.5Gb
Recent Refpolicy       4 min 19 sec      6.0Gb
Recent Fedora Policy   4 hrs  9 min     31.9Gb

With the change
                         Time        Memory Usage
Older Fedora Policy          28 sec      1.7Gb
Recent Refpolicy             34 sec      1.9Gb
Recent Fedora Policy   4 min 45 sec      7.7Gb

Also added a unit test to check that redundant rules are removed.

Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2019-10-24 09:00:19 -04:00
..
invalid_perm_maps PermissionMapTest: add additional unit tests for error cases 2015-04-07 14:40:04 -04:00
policyrep Update static testing and fix identified issues. 2018-08-11 20:46:06 -04:00
__init__.py Add ibendportcon and ibpkeycon queries. 2018-11-25 10:51:23 -05:00
boolquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
boolquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
boundsquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
boundsquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
categoryquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
categoryquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
commonquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
commonquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
conditionalinfoflow.conf infoflow: adds boolean selection to seinfoflow 2019-02-06 21:02:46 +00:00
conditionalinfoflow.py infoflow: adds boolean selection to seinfoflow 2019-02-06 21:02:46 +00:00
constraintquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
constraintquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
defaultquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
defaultquery.py Revise structure to make policyrep a module instead of a subpackage. 2018-08-11 20:46:01 -04:00
devicetreeconquery.conf setools-V4: Add updates for testing V30 xen and xperms 2016-03-21 10:56:37 -04:00
devicetreeconquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
diff_left_redundant.conf Change how differences in AV rules are generated in sediff 2019-10-24 09:00:19 -04:00
diff_left_standard.conf Change how differences in AV rules are generated in sediff 2019-10-24 09:00:19 -04:00
diff_left.conf Change how differences in AV rules are generated in sediff 2019-10-24 09:00:19 -04:00
diff_right_rmisid.conf Change how differences in AV rules are generated in sediff 2019-10-24 09:00:19 -04:00
diff_right.conf Change how differences in AV rules are generated in sediff 2019-10-24 09:00:19 -04:00
diff.py Change how differences in AV rules are generated in sediff 2019-10-24 09:00:19 -04:00
dta.conf Add additional DTA and infoflow rules for self loop testing. 2015-02-28 10:11:13 -05:00
dta.py Update static testing and fix identified issues. 2018-08-11 20:46:06 -04:00
fsusequery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
fsusequery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
genfsconquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
genfsconquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
ibendportconquery.conf Add ibendportcon and ibpkeycon queries. 2018-11-25 10:51:23 -05:00
ibendportconquery.py Fix PEP8 issues. 2018-11-30 20:05:10 -05:00
ibpkeyconquery.conf Add ibendportcon and ibpkeycon queries. 2018-11-25 10:51:23 -05:00
ibpkeyconquery.py Fix PEP8 issues. 2018-11-30 20:05:10 -05:00
infoflow.conf InfoFlow tests: fix disconnected node tests 2015-03-27 09:07:48 -04:00
infoflow.py Revise structure to make policyrep a module instead of a subpackage. 2018-08-11 20:46:01 -04:00
initsidquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
initsidquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
iomemconquery.conf setools-V4: Add updates for testing V30 xen and xperms 2016-03-21 10:56:37 -04:00
iomemconquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
ioportconquery.conf setools-V4: Add updates for testing V30 xen and xperms 2016-03-21 10:56:37 -04:00
ioportconquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
mixins.py Revise structure to make policyrep a module instead of a subpackage. 2018-08-11 20:46:01 -04:00
mlsrulequery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
mlsrulequery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
netifconquery.conf Implement MLS range tests on several context-based queries. 2015-02-24 15:50:08 -05:00
netifconquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
nodeconquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
nodeconquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
objclassquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
objclassquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
pcideviceconquery.conf setools-V4: Add updates for testing V30 xen and xperms 2016-03-21 10:56:37 -04:00
pcideviceconquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
perm_map PermissionMapTest: add additional unit tests for error cases 2015-04-07 14:40:04 -04:00
permmap.conf PermissionMap: implement policy mapping function. 2015-03-18 10:16:15 -04:00
permmap.py Update static testing and fix identified issues. 2018-08-11 20:46:06 -04:00
pirqconquery.conf setools-V4: Add updates for testing V30 xen and xperms 2016-03-21 10:56:37 -04:00
pirqconquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
polcapquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
polcapquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
portconquery.conf Implement MLS range tests on several context-based queries. 2015-02-24 15:50:08 -05:00
portconquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
rbacrulequery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
rbacrulequery.py Revise structure to make policyrep a module instead of a subpackage. 2018-08-11 20:46:01 -04:00
rolequery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
rolequery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
sensitivityquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
sensitivityquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
terulequery2.conf Complete TERuleQuery changes for extended permission rules. 2016-03-22 11:07:25 -04:00
terulequery.conf Extend indirect handling for rule queries. 2016-03-16 14:06:49 -04:00
terulequery.py Update static testing and fix identified issues. 2018-08-11 20:46:06 -04:00
typeattrquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
typeattrquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
typequery.conf MatchName: Add support for alias dereferencing. 2019-02-02 10:17:26 -05:00
typequery.py MatchName: Add support for alias dereferencing. 2019-02-02 10:17:26 -05:00
userquery.conf tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00
userquery.py tests: Revise unit tests for binary-only policy support. 2018-06-15 20:26:49 -04:00