apparmor/utils/apparmor
Christian Boltz bc492533cc
Fix aa-mergeprof crash caused by accidentially initialzed hat
Hasher causes some fun in aa-mergeprof: If the profile in
/etc/apparmor.d/ has a hat or subprofile that doesn't exist in the
to-be-merged profile, aa-mergeprof crashes. This is caused by reading
self.other.aa[program][hat]['include'] which accidently "creates" that
profile inside the aa hasher as empty hasher (instead of ProfileStorage).

Later, the code loops over self.other.aa[profile].keys(), expects
everything to be ProfileStorage, and explodes [1] when for example
trying to run .delete_duplicates on the hasher (which obviously doesn't
provide this method).

This patch adds checks to all self.other.aa accesses in
CleanProf.remove_duplicate_rules() to avoid accidently creating new keys
in the hasher.

Interestingly this bug survived unnoticed for years (at least since
2.11).

[1] last lines of the backtrace:
  File ".../utils/apparmor/cleanprofile.py", line 42, in compare_profiles
    deleted += self.remove_duplicate_rules(profile)
  File ".../utils/apparmor/cleanprofile.py", line 65, in remove_duplicate_rules
    deleted += apparmor.delete_duplicates(self.other.aa[program][hat], inc)
  File ".../utils/apparmor/aa.py", line 1680, in delete_duplicates
    deleted += profile[rule_type].delete_duplicates(include[incname][incname][rule_type])
AttributeError: 'collections.defaultdict' object has no attribute 'delete_duplicates'
2018-10-11 19:49:26 +02:00
..
rule Add 'can_owner' flag to *Rule 2017-12-17 16:31:05 +01:00
__init__.py Due to wanting to support additional external apparmor python modules, 2014-09-15 12:18:16 -07:00
aa.py Add basic support for abi rules to the tools 2018-09-26 22:09:17 +02:00
aamode.py [36/38] Drop several now unused functions and variables from aamode.py 2016-10-01 20:15:21 +02:00
aare.py [28/38] AARE: let match() handle plain path regexes as non-regex 2016-10-01 20:07:17 +02:00
cleanprofile.py Fix aa-mergeprof crash caused by accidentially initialzed hat 2018-10-11 19:49:26 +02:00
common.py type_is_str(): make pyflakes3 happy 2016-08-12 12:02:20 +02:00
config.py Let 'make check' work without logprof.conf 2015-10-20 23:21:51 +02:00
easyprof.py utils: Add option to aa-easyprof to specify the apparmor_parser path 2017-03-02 21:24:05 +00:00
fail.py Let the apparmor.fail error handler print to stderr 2015-12-16 11:59:10 +01:00
logparser.py utils: Properly identify empty ouid/fsuid fields in logs 2018-03-07 15:26:26 +00:00
profile_storage.py Add basic support for abi rules to the tools 2018-09-26 22:09:17 +02:00
regex.py Add basic support for abi rules to the tools 2018-09-26 22:09:17 +02:00
rules.py [7/9] Remove the DBUS_Rule class 2016-05-23 23:19:59 +02:00
sandbox.py remove unused exception binding in sandbox.py 2018-08-22 21:23:25 +02:00
severity.py update python tools to support includes with absolute paths 2017-12-20 17:21:21 -06:00
tools.py fix serialize_profile() calls to always use a dict for options 2018-06-25 21:42:29 +02:00
translations.py Merge in Kshitij Gupta <kgupta8592@gmail.com>'s rewrite of the 2014-02-12 15:54:00 -08:00
ui.py Keep JSON version at 2.12 2017-10-26 18:49:32 +02:00