mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-30 13:58:22 +00:00
Ignore change hat declarations when parsing a profile
Hat declarations ("^hat,") were added in 2.3 for declaring external hats, but in the meantime aren't supported by the parser anymore (tested with 2.9.2 parser). Additionally, if a profile contains both a hat declaration and the hat ("^hat { ...}"), the hat declaration can overwrite the content of the hat on a "last one wins" base. This is caused by setting 'declared' to True, which means write_piece() will only write the "^hat," line, but not the "^hat { ... }" block. Therefore no longer set 'declared' to True, print a warning that hat declarations are no longer supported, and ignore the rule. This also means that running aa-cleanprof can make the profile valid again :-) Also no longer change 'hat' when hitting a profile declaration, which also looks wrong. Note: This change removes the only usage of 'declared'. A follow-up patch (trunk only) will completely remove the 'declared' handling. Reproducer profile (run aa-cleanprof on it): (will crash in remove_duplicate_rules() 80% of the time - if so, try multiple times. One of the next patches will fix that. Or just try 2.9, which doesn't have the crash in remove_duplicate_rules().) /usr/bin/true { ^FOO { capability setgid, } # deletes the content of ^FOO when saving the profile! (last one wins) # additionally, the parser says this is invalid syntax ^FOO, } See also the "Hat declarations" thread on the ML, https://lists.ubuntu.com/archives/apparmor/2015-June/008107.html Acked-by: Kshitij Gupta <kgupta8592@gmail.com> for both 2.9 and trunk.
This commit is contained in:
@@ -2994,11 +2994,8 @@ def parse_profile_data(data, file, do_include):
|
|||||||
if not profile:
|
if not profile:
|
||||||
raise AppArmorException(_('Syntax Error: Unexpected change hat declaration found in file: %(file)s line: %(line)s') % { 'file': file, 'line': lineno + 1 })
|
raise AppArmorException(_('Syntax Error: Unexpected change hat declaration found in file: %(file)s line: %(line)s') % { 'file': file, 'line': lineno + 1 })
|
||||||
|
|
||||||
hat = matches[0]
|
aaui.UI_Important(_('Ignoring no longer supported change hat declaration "^%(hat)s," found in file: %(file)s line: %(line)s') % {
|
||||||
hat = strip_quotes(hat)
|
'hat': matches[0], 'file': file, 'line': lineno + 1 })
|
||||||
|
|
||||||
if not profile_data[profile][hat].get('declared', False):
|
|
||||||
profile_data[profile][hat]['declared'] = True
|
|
||||||
|
|
||||||
elif RE_PROFILE_HAT_DEF.search(line):
|
elif RE_PROFILE_HAT_DEF.search(line):
|
||||||
# An embedded hat syntax definition starts
|
# An embedded hat syntax definition starts
|
||||||
|
Reference in New Issue
Block a user