Here is the current sepolgen patch from Fedora.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
This patch incorporates to changes to make audit2allow rule generation better.
First it adds audit2why functionality so that audit2allow can tell a user when he is looking at the AVC messages a boolean exists to fix the problem, or if the policy is fixed in the current release.
Secondly I added the open access and tried to change some of the weights to make audit2allow -R work better.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAk0GZ5MACgkQrlYvE4MpobNB8wCgwqA7gzBO+qqDvjTboeWYTSz3 Z8cAn1SiNxTFJHuW0CsWI1krhgJQcIVG
=DWHT
-----END PGP SIGNATURE-----
sepolgen/src/sepolgen/access.py +9 -4
@@ -32,6 +32,7 @@ in a variety of ways, but they are the fundamental representation of access. """ import refpolicy +from selinux import audit2why def is_idparam(id): """Determine if an id is a paramater in the form $N, where N is
@@ -85,6 +86,8 @@ class AccessVector: self.obj_class = None self.perms = refpolicy.IdSet() self.audit_msgs = [] + self.type = audit2why.TERULE + self.bools = [] # The direction of the information flow represented by this # access vector - used for matching
@@ -253,20 +256,22 @@ class AccessVectorSet: for av in l: self.add_av(AccessVector(av)) - def add(self, src_type, tgt_type, obj_class, perms, audit_msg=None): + def add(self, src_type, tgt_type, obj_class, perms, audit_msg=None, avc_type=audit2why.TERULE, bools=[]): """Add an access vector to the set. """ tgt = self.src.setdefault(src_type, { }) cls = tgt.setdefault(tgt_type, { }) - if cls.has_key(obj_class): - access = cls[obj_class] + if cls.has_key((obj_class, avc_type)): + access = cls[obj_class, avc_type] else: access = AccessVector() access.src_type = src_type access.tgt_type = tgt_type access.obj_class = obj_class - cls[obj_class] = access + access.bools = bools + access.type = avc_type + cls[obj_class, avc_type] = access access.perms.update(perms) if audit_msg:
sepolgen/src/sepolgen/audit.py +43 -3
78 lines not on this page · raw message
sepolgen/src/sepolgen/defaults.py +3 -0
@@ -30,6 +30,9 @@ def perm_map(): def interface_info(): return data_dir() + "/interface_info" +def attribute_info(): + return data_dir() + "/attribute_info" + def refpolicy_devel(): return "/usr/share/selinux/devel"
sepolgen/src/sepolgen/interfaces.py +65 -8
110 lines not on this page · raw message
sepolgen/src/sepolgen/matching.py +5 -4
@@ -50,7 +50,7 @@ class Match: return 1 class MatchList: - DEFAULT_THRESHOLD = 120 + DEFAULT_THRESHOLD = 150 def __init__(self): # Match objects that pass the threshold self.children = []
@@ -63,14 +63,15 @@ class MatchList: def best(self): if len(self.children): return self.children[0] - else: - return None + if len(self.bastards): + return self.bastards[0] + return None def __len__(self): # Only return the length of the matches so # that this can be used to test if there is # a match. - return len(self.children) + return len(self.children) + len(self.bastards) def __iter__(self): return iter(self.children)
sepolgen/src/sepolgen/policygen.py +37 -1
@@ -29,6 +29,8 @@ import objectmodel import access import interfaces import matching +import selinux.audit2why as audit2why +from setools import * # Constants for the level of explanation from the generation # routines
@@ -77,6 +79,7 @@ class PolicyGenerator: self.dontaudit = False + self.domains = None def set_gen_refpol(self, if_set=None, perm_maps=None): """Set whether reference policy interfaces are generated.
@@ -151,8 +154,41 @@ class PolicyGenerator: rule = refpolicy.AVRule(av) if self.dontaudit: rule.rule_type = rule.DONTAUDIT + rule.comment = "" if self.explain: - rule.comment = refpolicy.Comment(explain_access(av, verbosity=self.explain)) + rule.comment = str(refpolicy.Comment(explain_access(av, verbosity=self.explain))) + if av.type == audit2why.ALLOW: + rule.comment += "#!!!! This avc is allowed in the current policy\n" + if av.type == audit2why.DONTAUDIT: + rule.comment += "#!!!! This avc has a dontaudit rule in the current policy\n" + + if av.type == audit2why.BOOLEAN: + if len(av.bools) > 1: + rule.comment += "#!!!! This avc can be allowed using one of the these booleans:\n# %s\n" % ", ".join(map(lambda x: x[0], av.bools)) + else: + rule.comment += "#!!!! This avc can be allowed using the boolean '%s'\n" % av.bools[0][0] + + if av.type == audit2why.CONSTRAINT: + rule.comment += "#!!!! This avc is a constraint violation. You will need to add an attribute to either the source or target type to make it work.\n" + rule.comment += "#Contraint rule: " + + if av.type == audit2why.TERULE: + if "write" in av.perms: + if "dir" in av.obj_class or "open" in av.perms: + if not self.domains: + self.domains = seinfo(ATTRIBUTE, name="domain")[0]["types"] + types=[] + + try: + for i in map(lambda x: x[TCONTEXT], sesearch([ALLOW], {SCONTEXT: av.src_type, CLASS: av.obj_class, PERMS: av.perms})): + if i not in self.domains: + types.append(i) + if len(types) == 1: + rule.comment += "#!!!! The source type '%s' can write to a '%s' of the following type:\n# %s\n" % ( av.src_type, av.obj_class, ", ".join(types)) + elif len(types) >= 1: + rule.comment += "#!!!! The source type '%s' can write to a '%s' of the following types:\n# %s\n" % ( av.src_type, av.obj_class, ", ".join(types)) + except: + pass self.module.children.append(rule)
sepolgen/src/sepolgen/refparser.py +1 -1
@@ -1044,7 +1044,7 @@ def parse_headers(root, output=None, expand=True, debug=False): # of misc_macros. We are just going to pretend that this is an interface # to make the expansion work correctly. can_exec = refpolicy.Interface("can_exec") - av = access.AccessVector(["$1","$2","file","execute_no_trans","read", + av = access.AccessVector(["$1","$2","file","execute_no_trans","open", "read", "getattr","lock","execute","ioctl"]) can_exec.children.append(refpolicy.AVRule(av))
sepolgen/src/share/perm_map +29 -22
122 lines not on this page · raw message