Commit Graph

203 Commits

Author SHA1 Message Date
Chris PeBenito
e82fcadf58 PolicyDifference: Add type annotations.
Includes some minor code changes to fix errors from static type checking.

Disable unsubscriptable-object pylint check on Wrapper subclass
declarations, as this hits the bug described in PyCQA/pylint#2822.

Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-10-14 10:16:54 -04:00
Chris PeBenito
bef620512d AVRuleTest: Diasable pycodestyle W605 check on single line instead of everywhere.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-10-14 10:16:54 -04:00
Chris PeBenito
9ed62f198a PermissionMap: Clean up implementation.
Clean up style issues and rename attributes that are considered internal.
Also add type annotations.

Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-10-14 10:16:54 -04:00
Chris PeBenito
83f91adb2c checker: Implement RBAC rule assertion check.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-08-23 11:18:46 -04:00
Chris PeBenito
27b0f2ef84 checker/util.py: Remove redundant functions. Add a boolean config function.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-08-22 20:46:38 -04:00
Chris PeBenito
f6dc7c3cf8 MatchPermission: Change to use CriteriaPermissionSetDescriptor.
Fix common query test policy to meet new permission validations.

Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-08-22 18:42:39 -04:00
Chris PeBenito
a107811abb AssertTE: Add expect_source and expect_target options.
This is used to assert the existence of TE rules.

Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-07-25 15:19:12 -04:00
Chris PeBenito
df5bf03d20 checker/util: Change lists from comma-separated to space-separated.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-07-25 10:47:58 -04:00
Chris PeBenito
58475daba2 PolicyCheckerTest: Fix mock check names.
Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-07-05 13:31:59 -04:00
Chris PeBenito
bf03b6749c PolicyChecker: Implement config file-driven automated analysis checker.
This is a .ini config file-driven analysis check.

Signed-off-by: Chris PeBenito <chpebeni@linux.microsoft.com>
2020-06-10 11:09:17 -04:00
Chris PeBenito
9ca7e648e3 ReadOnlyExecutables: Implement read-only executables assertion check.
This determines all file types that are executable and checks if they are
also read-only.

Signed-off-by: Chris PeBenito <chpebeni@linux.microsoft.com>
2020-06-10 11:09:06 -04:00
Chris PeBenito
e8c172c720 AssertTE: Implement type enforcement allow rule assertion check.
This checks for the nonexistance of allow rules that match the criteria
set in the check's options.

Signed-off-by: Chris PeBenito <chpebeni@linux.microsoft.com>
2020-06-10 11:09:06 -04:00
Chris PeBenito
bb698389af EmptyTypeAttr: Implement empty type attribute assertion check.
This asserts that an attribute is empty.

Signed-off-by: Chris PeBenito <chpebeni@linux.microsoft.com>
2020-06-10 11:09:06 -04:00
Chris PeBenito
210665f575 Implement utility functions for parsing configuration strings.
These are various functions such as parsing comma separated strings,
looking up objects in the policy, and expanding attributes.

Signed-off-by: Chris PeBenito <chpebeni@linux.microsoft.com>
2020-06-10 11:09:06 -04:00
Chris PeBenito
d3a9fcb1d6 Default: Add support for default_range glblub.
Closes #44

Signed-off-by: Chris PeBenito <pebenito@ieee.org>
2020-05-07 11:16:37 -04:00
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
2c133a6831
Merge pull request #15 from driechersRC/tunables
Add feature to select only the default tunable rules
2019-02-16 14:37:49 -05:00
Riechers, Daniel J
b662b07cc0 infoflow: adds boolean selection to seinfoflow
Adds the option to the infoflow analysis to filter conditional policy based on the default or user specified boolean values.

Signed-off-by: Daniel Riechers <daniel.riechers@rockwellcollins.com>
Signed-off-by: David Graziano <david.graziano@rockwellcollins.com>
2019-02-06 21:02:46 +00:00
Chris PeBenito
a943daa452 MatchName: Add support for alias dereferencing.
For #17
2019-02-02 10:17:26 -05:00
Chris PeBenito
b1336686bd PolicyDifference: Add ibendportcon and ibpkeycon difference. 2018-12-05 15:22:07 -05:00
Chris PeBenito
ea2485059a Fix PEP8 issues. 2018-11-30 20:05:10 -05:00
Chris PeBenito
832462fd0f Add ibendportcon and ibpkeycon queries. 2018-11-25 10:51:23 -05:00
Chris PeBenito
e6fc383eee ConstraintExpression: Move constraint/validatetrans expression to new class.
This represents the constraint expression and simplifies use of the
expression.
2018-08-31 21:09:14 -04:00
Chris PeBenito
6d7a672611 Update static testing and fix identified issues.
* Change pep8 to new pycodestyle tool.
* Load the policrep extension in pylint
2018-08-11 20:46:06 -04:00
Chris PeBenito
2b4d69d42e Revise structure to make policyrep a module instead of a subpackage.
The setools.policyrep.exception module merged into setools.exception.
2018-08-11 20:46:01 -04:00
Chris PeBenito
57e4f464bf setup.py: Update build for local SELinux userspace code.
Now USERSPACE_SRC points to the top level directory that has the
libsepol, libselinux, and checkpolicy source trees.
2018-06-18 20:21:30 -04: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
dc3752e12d tests: Fix static analysis errors. 2018-06-15 20:26:49 -04:00
Chris PeBenito
51b91d6130 Convert policyrep and SWIG wrapper into Cython libpolicyrep. 2018-06-15 20:26:49 -04:00
Chris PeBenito
cc313f9791 __future__ print functions no longer need importing. 2017-09-24 20:40:29 -04:00
Chris PeBenito
856b56accb Update NetworkX support to 2.0. NetworkX 2.0 has API breakage.
Now SETools requires NetworkX 2.0+.
2017-09-23 14:03:26 -04:00
Chris PeBenito
9fa55c25cb Update unit tests for Python 3 only use. 2017-09-19 20:58:03 -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
bfa50a42f8 NodeconQuery: Make ipaddress module usage unconditional.
Closes #107
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
c0ebad8d15 SELinuxPolicy: Create enumerations for handle_unknown and target_platform. 2016-11-11 13:58:43 -05:00
Chris PeBenito
96428e6309 Implement an enumeration for *bounds rule types. 2016-09-03 16:44:13 -04:00
Chris PeBenito
9648d013a2 Implement an enumeration for constraint rule type. 2016-09-03 16:44:13 -04:00
Chris PeBenito
693b5a435b Implement an enumeration for default rule type, value, and range value. 2016-09-03 16:44:13 -04:00
Chris PeBenito
8ea292f934 Implement an enumeration for fs_use_* ruletype. 2016-09-03 16:44:07 -04:00
Chris PeBenito
4b5b6c0970 Implement an enumeration for MLS rule type. 2016-09-03 16:40:54 -04:00
Chris PeBenito
a441a92937 Implement an enumeration for RBAC rule type. 2016-09-03 16:19:52 -04:00
Chris PeBenito
f3fb462c88 Implement an enumeration for TE rule types. 2016-09-03 16:17:07 -04:00
Chris PeBenito
2d23bd42ce SELinuxPolicyTest: add extended permission rule count tests
Closes #73
2016-03-29 09:55:51 -04:00
Chris PeBenito
47d8eda957 TERulesDifference: add extended permission rules
Related to #73
2016-03-25 15:33:07 -04:00
Chris PeBenito
982b3f893d Minor revisions to Xen code.
* Remove unnecessary namedtuple classes
* Simplify __str__ functions on XenContext subclasses
* Rename mem_addr to addr in Iomemcon and IomemconQuery
* Minor logging tweaks in Xen queries
* Remove type checking in DevicetreeconQuery
2016-03-25 11:01:33 -04:00
Chris PeBenito
a9cd2248e9 Complete TERuleQuery changes for extended permission rules.
Related to #73.
2016-03-22 11:07:25 -04:00
Chris PeBenito
c56e01bc8c Complete policy representation classes for extended permissions rules.
Related to #73.
2016-03-22 10:26:43 -04:00
Chris PeBenito
56965ae9b3 Fix PEP8 and lint issues in Xen code. 2016-03-21 10:58:05 -04:00