Commit Graph

31 Commits

Author SHA1 Message Date
Chris PeBenito
dbf2c197c7 Genfscon: Look up object class references since object class values are not static.
The object class values have not been static for many years.  This has only
worked because libsepol was similarly setting static class values.  This
will soon be removed, see SELinuxProject/selinux#200.

Add file object classes to the unit tests where genfscons are used.  The
classes are added in the same alignment as the static values since old
policies will have these class values.

Remove static class values from sepol.pxd.

Closes #39

Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-03-10 15:55:24 -04:00
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
Chris PeBenito
b1336686bd PolicyDifference: Add ibendportcon and ibpkeycon difference. 2018-12-05 15:22:07 -05:00
Chris PeBenito
4684eca5bc tests: Revise unit tests for binary-only policy support.
Closes #72
2018-06-15 20:26:49 -04:00
Chris PeBenito
78a15c92ac Nodecon: Implement network property.
The network property will return an IPv4Network or IPv6Network based on the
nodecon.  If the policy has host bits set, the ipaddress module will
simply ignore the host bits, so there may be unexpected results in network
comparisons.

Closes #108
2017-09-17 09:43:13 -04:00
Chris PeBenito
5200f0c666 TERulesDifference: Fix bug with unioning permissions.
Unit tests did not correctly test this scenario.
2016-12-03 12:19:53 -05:00
Chris PeBenito
47d8eda957 TERulesDifference: add extended permission rules
Related to #73
2016-03-25 15:33:07 -04:00
Chris PeBenito
a4d4920d3c PolicyDifference: implement typebounds diff.
Closes #67
2016-02-10 11:44:41 -05:00
Chris PeBenito
b1b1a36ae2 PolicyDifference: implement constraints diff
Closes #63
2016-02-05 09:30:37 -05:00
Chris PeBenito
ce02bfc5a5 PolicyDifference: implement default_* diff.
Closes #65
2016-02-01 09:15:51 -05:00
Chris PeBenito
69df208ab6 PolicyDifference: implement portcon diff
Closes #37
2016-01-21 10:00:55 -05:00
Chris PeBenito
3227fb87de PolicyDifferenceTest: fix invalid policies.
Found the policy compile-load has a bug and does not detect if a user's
default level is not within the allowed range.

Opened #72 to track.
2016-01-20 14:13:01 -05:00
Chris PeBenito
b64fcea379 PolicyDifference: implement policy capabilities diff
Closes #64
2016-01-15 09:43:01 -05:00
Chris PeBenito
dbad48a742 PolicyDifference: implement nodecon diff
Closes #38
2016-01-15 09:43:01 -05:00
Chris PeBenito
485c9746b4 PolicyDifference: implement netifcon diff
Closes #39
2016-01-15 09:42:00 -05:00
Chris PeBenito
00bc854968 PolicyDifference: implement level decl difference
Closes #36
2016-01-12 16:12:33 -05:00
Chris PeBenito
afeb3561d2 PolicyDifference: implement genfscon diff
Closes #41
2016-01-11 14:43:11 -05:00
Chris PeBenito
d6e0d56fac PolicyDifference: implement fs_use_* diff
Closes #40
2016-01-10 11:44:11 -05:00
Chris PeBenito
64d6d4d075 PolicyDifference: implement initial SID diff
Closes #42
2016-01-09 11:45:22 -05:00
Chris PeBenito
2bd871ae18 PolicyDifference: implement sensitivities diff
Closes #34
2016-01-09 09:01:52 -05:00
Chris PeBenito
8b136a007c PolicyDifference: implement categories diff
Closes #35
2016-01-09 08:56:40 -05:00
Chris PeBenito
d59444ef0e PolicyDifference: implement Booleans diff 2016-01-08 15:30:39 -05:00
Chris PeBenito
451e549001 PolicyDifference: add type attribute diff
Closes #33
2016-01-08 11:25:13 -05:00
Chris PeBenito
aebe3f8706 PolicyDifference: implement user diff
Closes #29
2016-01-08 09:55:34 -05:00
Chris PeBenito
b0ed2c5477 PolicyDifference: add RBAC rule differences
Closes #44
2016-01-07 11:44:33 -05:00
Chris PeBenito
0513f0bb5a diff: implement MLS rule (range_transition) diff.
Closes #45
2016-01-07 09:37:47 -05:00
Chris PeBenito
c913989f8c PolicyDifference: implement TE rule difference
Closes #43
2016-01-02 18:17:39 -05:00
Chris PeBenito
92134725c1 PolicyDifference: add object class diff
Closes #28
2015-12-21 11:01:30 -05:00
Chris PeBenito
b3dbe6a8b3 PolicyDifference: implement common permission set diff
Closes #27
2015-12-18 19:39:02 -05:00
Chris PeBenito
12b13406f1 PolicyDifference: add role difference
Closes #30
2015-12-18 11:07:37 -05:00
Chris PeBenito
eae9ff97d5 setools: add PolicyDifference class
Begin diff functions by implementing type difference function.

Closes #32
2015-12-17 11:08:35 -05:00