<div dir="ltr">Hello,<br><div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 7, 2015 at 5:55 PM, Christian Boltz <span dir="ltr"><<a href="mailto:apparmor@cboltz.de" target="_blank">apparmor@cboltz.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
Hat declarations ("^hat,") were added in 2.3 for declaring external<br>
hats, but in the meantime aren't supported by the parser anymore (tested<br>
with 2.9.2 parser).<br>
<br>
Additionally, if a profile contains both a hat declaration and the hat<br>
("^hat { ...}"), the hat declaration can overwrite the content of the<br>
hat on a "last one wins" base.<br>
<br>
This is caused by setting 'declared' to True, which means write_piece()<br>
will only write the "^hat," line, but not the "^hat { ... }" block.<br>
<br>
Therefore no longer set 'declared' to True, print a warning that hat<br>
declarations are no longer supported, and ignore the rule. This also<br>
means that running aa-cleanprof can make the profile valid again :-)<br>
<br>
Also no longer change 'hat' when hitting a profile declaration, which<br>
also looks wrong.<br>
<br>
<br>
Note: This change removes the only usage of 'declared'. A follow-up<br>
patch (trunk only) will completely remove the 'declared' handling.<br>
<br>
<br>
Reproducer profile (run aa-cleanprof on it):<br>
(will crash in remove_duplicate_rules() 80% of the time - if so, try<br>
multiple times. One of the next patches will fix that. Or just try 2.9,<br>
which doesn't have the crash in remove_duplicate_rules().)<br>
<br>
/usr/bin/true {<br>
<br>
  ^FOO {<br>
    capability setgid,<br>
  }<br>
<br>
  # deletes the content of ^FOO when saving the profile! (last one wins)<br>
  # additionally, the parser says this is invalid syntax<br>
  ^FOO,<br>
<br>
}<br>
<br>
<br>
See also the "Hat declarations" thread on the ML,<br>
<a href="https://lists.ubuntu.com/archives/apparmor/2015-June/008107.html" rel="noreferrer" target="_blank">https://lists.ubuntu.com/archives/apparmor/2015-June/008107.html</a><br>
<br>
<br>
I propose this patch for trunk and 2.9.<br>
<br>
<br>
[ 46-obsolete-change-hat.diff ]<br>
<br>
=== modified file utils/apparmor/aa.py<br>
--- utils/apparmor/aa.py        2015-06-06 14:54:10.584133536 +0200<br>
+++ utils/apparmor/aa.py        2015-06-07 13:06:52.764908018 +0200<br>
@@ -2992,11 +2992,8 @@<br>
             if not profile:<br>
                 raise AppArmorException(_('Syntax Error: Unexpected change hat declaration found in file: %(file)s line: %(line)s') % { 'file': file, 'line': lineno + 1 })<br>
<br>
-            hat = matches[0]<br>
-            hat = strip_quotes(hat)<br>
-<br>
-            if not profile_data[profile][hat].get('declared', False):<br>
-                profile_data[profile][hat]['declared'] = True<br>
+            aaui.UI_Important(_('Ignoring no longer supported change hat declaration "^%(hat)s," found in file: %(file)s line: %(line)s') % {<br>
+                    'hat': matches[0], 'file': file, 'line': lineno + 1 })<br>
<br>
         elif RE_PROFILE_HAT_DEF.search(line):<br>
             # An embedded hat syntax definition starts<br>
<br></blockquote><div>On the long term could we entirely do away with this regex and code block?<br><br>Thanks for the patch.<br><br>Acked-by: Kshitij Gupta <<a href="mailto:kgupta8592@gmail.com" target="_blank">kgupta8592@gmail.com</a>>.  <br><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
Regards,<br>
<br>
Christian Boltz<br>
<span class=""><font color="#888888">--<br>
> Leider Gottes ist es so, daß wenn man einen Spammer zu Strecke<br>
> gebracht hat, dafür drei neue auftauchen.<br>
Das ist wie bei den Fliegen. Schlägst Du eine Tot, kommen 40 zur<br>
Beerdigung. ;)   [> Martin Mewes und Michael Raab in suse-linux]<br>
<br>
<br>
--<br>
AppArmor mailing list<br>
<a href="mailto:AppArmor@lists.ubuntu.com">AppArmor@lists.ubuntu.com</a><br>
Modify settings or unsubscribe at: <a href="https://lists.ubuntu.com/mailman/listinfo/apparmor" rel="noreferrer" target="_blank">https://lists.ubuntu.com/mailman/listinfo/apparmor</a><br>
</font></span></blockquote></div><br></div></div></div>