Commit graph

1020 commits

Author SHA1 Message Date
Christian Boltz
7aca12bb12 [38/38] Drop old path regexes
FileRule uses RE_PROFILE_FILE_ENTRY, which also means
RE_PROFILE_PATH_ENTRY, RE_PROFILE_BARE_FILE_ENTRY and RE_OWNER are now
unused.

This patch drops these regexes and their tests in test-regex_matches.py.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:16:36 +02:00
Christian Boltz
5dbb283af5 [37/38] Drop severity rank() dispatcher
rank() in severity.py is a dispatcher that calls the needed function
(rank_path(), rank_capability()) based on the parameter. Since all
calling code knows what rule type it is handling, this dispatcher is
superfluous - the calling code can call rank_path() or rank_capability()
directly.

This patch drops rank() and switches the remaining users of rank() to
call the rank_*() functions directly. For the tests, this means to drop
the CAP_ prefix because rank_capability doesn't expect this prefix.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:15:45 +02:00
Christian Boltz
265fd4a708 [36/38] Drop several now unused functions and variables from aamode.py
After switching to FileRule, several functions in aamode.py are no
longer used and can be deleted:
- print_mode()
- sub_mode_to_str()
- is_user_mode()
- split_mode()
- mode_to_str()
- flatten_mode()
- owner_flatten_mode()
- mode_to_str_user()
- log_str_to_mode()

The AA_EXEC_TYPE and ALL_AA_EXEC_TYPE variables are also unused now.



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:15:21 +02:00
Christian Boltz
95f47ba9ff [35/38] Drop old path code from aa.py and aa-mergeprof
Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:14:44 +02:00
Christian Boltz
3ed80a9ed4 [34/38] logprof, mergeprof: cleanup superfluous rules when user adds a new rule
When an user adds a new rule to a profile, cleanup / delete existing
rules that are covered by the new rule, and report the number of deleted
rules.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:13:49 +02:00
Christian Boltz
9a6c3430d0 [33/38] Add cleanup flag to *Ruleset.add()
Adding a rule to *Ruleset means it simply gets added. This also means
that then-superfluous rules will be kept.

This patch adds an optional cleanup flag to add(). If set, rules covered
by the new rule will be deleted. The difference to delete_duplicates()
is that cleanup only deletes rules that are covered by the new rule, but
keeps other, unrelated superfluous rules.

Also return the number of deleted rules to give the UI a chance to
report this number.

Finally, adjust the existing tests for FileRuleset to ensure default
mode (without cleanup) doesn't delete any rules, and add a test using
the cleanup flag.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:13:06 +02:00
Christian Boltz
6ccdd27937 [32/38] Re-implement exec conflict handling in aa-mergeprof
Replace the old (hasher-based) conflict_mode() with the new
(FileRule-based) ask_conflict_mode() function. If it detects conflicting
exec rules, it asks the user which one to keep.

Also call ask_conflict_mode() from ask_the_questions() so that it is
actually used.

Note: This patch isn't covered by unittests, but I did some manual
testing to make sure it works as expected.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:12:30 +02:00
Christian Boltz
d1347051f4 [31/38] FileRule: add get_exec_rules_for_path() and get_exec_conflict_rules()
get_exec_rules_for_path() returns a FileRuleset with all rules matching
the given path.

get_exec_conflict_rules() returns a FileRuleset with all exec rules that
conflict with the given oldrule. This will be used by aa-mergeprof to
ask the user which rule he wants to keep.

Also add tests for both functions.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:12:01 +02:00
Christian Boltz
a3586e614e [30/38] Re-enable clear_common() call in aa-mergeprof
The clear_common() call was disabled because it crashed in
delete_path_duplicates(). With the switch to FileRule, this function
no longer exists and therefore it can't crash ;-)

This patch re-enables the clear_common() call to avoid asking
superfluous questions.

References: https://bugs.launchpad.net/apparmor/+bug/1382236


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:09:36 +02:00
Christian Boltz
95404bb2f3 [29/38] let _is_covered_aare() check against the AARE instead of the (str) regex
This is the correct way of doing AARE matches. However, this check is
more strict when matching against an AARE containing wildcards etc.
(which can "by luck" match when doing str matching)

To avoid breaking DbusRule, PtraceRule and SignalRule (especially their
tests), introduce _is_covered_aare_compat() which keeps the previous
behaviour of doing str matching, and use it in these classes.

On the long term, _is_covered_aare_compat() needs to go away, but doing
the changes needed in DbusRule, PtraceRule and SignalRule (or ideally
just in AARE) are out of scope for the FileRule patch series.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:08:10 +02:00
Christian Boltz
dde4609f22 [28/38] AARE: let match() handle plain path regexes as non-regex
When matching an AARE against another AARE, most AARE objects don't
contain orig_regex (only AARE instances originating from a log event
contain orig_regex).

In this case, match() will use is_equal() to error out on the safe side.
Unfortunately this also means that there are lots of false negative
cases where match() returns False errornously.

With this patch, match() checks the given AARE regex and, if it doesn't
contain any special characters (wildcards, alternations or variables),
handles it as plain path. This avoids most of the false negatives.

Also extend the AARE tests to check a bunch of plain path regexes using
AARE matching instead of only str matching.



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:07:17 +02:00
Christian Boltz
06d880d1ff [27/38] Implement FileRule logprof_header()
Merge the existing and requested permissions into a nice set of headers
that can be displayed by aa-logprof. This will look like:

	Path:      /foo
	Old Mode:  r + owner w
	New Mode:  rw

Also split off a _join_given_perms() function off _joint_perms() so that
we can use the permission string merging for things not stored in self.*.

Finally add some tests for logprof_header().



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:06:38 +02:00
Christian Boltz
b78e65824c [26/38] Avoid crash in aa-logprof on events for non-existing profiles
If the audit.log contains an event for a non-existing profile (this can
happen when running with a foreign log or if the user manually deleted a
profile or hat), propose_file_rules() crashes because rule_obj is None
instead of a profile_storage() struct.

This patch adds a check that skips events for non-existing profiles and
hats.

Note: I'm quite sure this happens only for file events (because the
other rule types don't have something similar to propose_file_rules()),
therefore no backport to older versions is needed.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:05:58 +02:00
Christian Boltz
541977c91b [25/38] Set audit mode for all options
Add set_options_audit_mode() to switch the audit mode in all options
offered by aa-logprof and aa-mergeprof, not only the "original" rule
(in aa-logprof, this means the non-globbed rule_obj).

As usual, add some tests to ensure the function works as expected.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:05:27 +02:00
Christian Boltz
20161471be [24/38] Add propose_file_rules() to propose globbed etc. file rules in aa-logprof
aa.py:
- add propose_file_rules() - will propose matching paths from existing
  rules in the profile or one of the includes
- save user_globs if user selects '(N)ew' (will be re-used when
  proposing rules)
- change user_globs to a dict so that it can carry the human-readable
  path and an AARE object for it
- change order_globs() to ensure the original path (given as parameter)
  is always the last item in the resulting list
- add a ruletype switch to ask_the_questions() so that it uses
  propose_file_rules() for file events (I don't like this
  ruletype-specific solution too much, but everything else would make
  things even more complicated)

Also keep aa-mergeprof ask_the_questions() in sync with aa.py.

In FileRule, add original_perms (might be set by propose_file_rules())

Finally, add some tests to ensure propose_file_rules() does what it promises.



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:04:42 +02:00
Christian Boltz
f2a60f67e3 [23/38] Add get_file_perms() to aa.py
get_file_perms() collects the existing permissions for a file from
various rules (exact matches, wildcards) in the main profile and the
included abstractions.

It will be used to get displaying the current permissions back, and
also to propose rules with merged permissions (next patch).

Also add some tests to make sure it does what it promises ;-)



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:03:44 +02:00
Christian Boltz
435281f018 [22/38] Add get_perms_for_path() and get_rules_for_path() to FileRuleset
- get_rules_for_path() returns all rules matching the given path
  (both exact matches and AARE matches)
- get_perms_for_path() returns the merged permissions for the given
  path and a list of paths used in the matching rules

Also add tests for these two functions.



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:03:07 +02:00
Christian Boltz
8dc09bd643 [21/38] Add severity support to FileRule
Also add a rank_path() function to severity.py and change rank() to call
rank_path() for paths.
Long-term goal: get rid of the type "guessing" in rank()

Finally add some tests, mostly based on test-severity.py SeverityTest


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:02:34 +02:00
Christian Boltz
875f9cf7d9 [20/38] Re-add '(N)ew' to aa-logprof
This brings back the edit option for the path of file rules.

Also add it to aa-mergeprof to keep ask_the_questions() in sync.

Note: aa-mergeprof will ask about path mismatchs basically always.
That's because AARE is too careful on the matching - something to be
fixed in a later patch.



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:01:53 +02:00
Christian Boltz
0fe9ed8960 [19/38] Add support for editing paths to FileRule
This means adding
- self.can_edit - True if editing via '(N)ew' should be possible (will
  be False for bare file rules)
- edit_header() - returns the prompt text and the current path
- validate_edit() - checks if the new path matches the original one
- store_edit() - changes the path to the new one (even if it doesn't
  match the old one)

self.can_edit and the 3 functions are also added to BaseRule:
- can_edit is False by default
- the functions raise a NotImplementedError


Also add tests for the added code.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 20:00:32 +02:00
Christian Boltz
fa7e25530d [18/38] Re-add globbing support for file rules to aa-logprof
This change also needs some other changes in ask_the_questions():
- set q.options and q.selected inside the loop (because glob() and
  glob_ext() add another option)
- set 'selection' outside the if block to avoid doing it in nearly every
  if branch
- make sure to add the selected rule, not just rule_obj (which doesn't
  contain a modified, for example globbed, rule)
- skip 'deny' if an #include is selected
- re-add handling for CMD_GLOB and CMD_GLOB_EXT (was lost when switching
  to FileRule)
- add selection_to_rule_obj() helper function
- add glob and glob with ext buttons in available_buttons() if
  rule_obj.can_glob or rule_obj.can_glob_ext

Also apply the changes in ask_the_questions() to aa-mergeprof to keep it
in sync with aa.py, and disable the old path handling in aa-mergeprof.

Note: in its current state, aa-mergeprof will ask for some "superfluous"
file permissions, and doesn't check for 'x' conflicts. One of the
following patches will fix that.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 19:58:40 +02:00
Christian Boltz
f0ddee648d [17/38] Implement globbing in FileRule
Add the glob() and glob_ext() functions to FileRule, and set
self.can_glob and self.can_glob_ext. Also add some tests (just enough to
make sure the FileRule integration works - the globbing is handled
inside AARE,and the AARE tests contain more testcases).

Note that the implementation differs from the original plan (which was
to have globbing in *Ruleset). Therefore add can_glob and can_glob_ext
to BaseRule (both default to False), and add a comment to BaseRuleset
that globbing needs to be removed from all *Ruleset classes.


Acked-by: Steve Beattie <steve@nxnw.org>


As discussed, I added a pointer to the test-aare.py globbing tests in
test-file.py.
2016-10-01 19:57:30 +02:00
Christian Boltz
9d6b525899 [16/38] move glob_path() and glob_path_ext() to AARE
glob_path() and glob_path_ext() modify a (path) regex, so move them to
AARE. Also change them to use self.regex instead of the newpath
parameter, and to return a new AARE object.

While on it, also add several tests to test-aare.py.


Note: There are still glob_path() and glob_path_ext() calls in aa.py,
but those calls are in a (since the middle of this patch series) dead
code section. pyflakes will complain about them nevertheless ;-)



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 19:56:31 +02:00
Christian Boltz
ee7560d6ef [15/38] Change handle_children() and ask_the_questions() to FileRule
This patch changes handle_children() (which asks about exec events) and
ask_the_questions() (which asks everything else) to FileRule. This
solves the "brain split" introduced by the previous patch.

This means aa-logprof and aa-genprof ask useful questions again, and
store the answers at the right place.

In detail, this means (with '-' line number from the diff)
- (391) handle_binfmt(): use FileRule. Also avoid breakage if glob_common()
  returns an empty result.
- (484) profile_storage(): drop profile['allow']['path'] and
  profile['deny']['path']
- (510) create_new_profile(): switch to FileRule
- (1190..1432) lots of changes in handle_children():
  - drop escaping (done in FileRule)
  - don't add events with 'x' perms to prelog
  - use is_known_rule() instead of profile_known_exec()
  - replace several regexes for the selected CMD_* with more readable
    'in' clauses. While on it, drop unused parts of the regex.
  - use plain 'ix', 'px' (as str) instead of str_to_mode() format
  - call handle_binfmt() for the interpreter in ix, Pix and Cix rules
- (1652) ask_the_questions(): disable the old file-specific code
  (not dropped because some features aren't ported to FileRule yet)
- (2336) collapse_log():
  - convert file log events to FileRule (and add some workarounds and
    TODOs for logparser.py behaviour that needs to change)
  - disable the old file-specific code (not dropped because merging of
    existing permissions isn't ported to FileRule yet)
- (2403) drop now unused validate_profile_mode() and the regexes it used
- (3374) drop now unused profile_known_exec()

Test changes:
- adjust fake_ldd to handle /bin/bash
- change test-aa.py AaTest_create_new_profile to expect FileRule instead
  of a path hasher. Also copy the profiles to the tempdir and load the
  abstractions that are needed by the test.
  (These tests get skipped on py2 because changing
  apparmor.aa.cfg['settings']['ldd'] doesn't work for some unknown reason)


Important: Some nice-to-have features are not yet implemented for
FileRule:
- globbing
- (N)ew (allowing the user to enter a custom path)
- displaying and merging of permissions already existing in the profile

This means: aa-logprof works, but it's not as user-friendly as before.
The next patches will fix that ;-)

Also note that pyflakes will fail for ask_the_questions_OLD_FILE_CODE()
because of undefined symbols (aamode, profile, hat). This will be fixed
when the old code gets dropped in one of the later patches.


Acked-by: Steve Beattie <steve@nxnw.org>

Bug: https://launchpad.net/bugs/1569316
2016-10-01 19:55:58 +02:00
Christian Boltz
aaa244c5ec [14/38] Use FileRule and FileRuleset
Change aa.py to use FileRule and FileRuleset for parsing and saving
profiles.

In detail, this means:
- add 'file' to the list of rule classes to enable it at various places
- store file rules in aa[profile][hat]['file'] (not 'path' as before)
  to be consistent with the FileRule name
- drop the no longer needed delete_path_duplicates() - this is now
  handled by FileRuleset like in all other rule classes.
  (same change in cleanprofile.py)
- replace usage of RE_PROFILE_BARE_FILE_ENTRY and RE_PROFILE_PATH_ENTRY
  with FileRule.match()
- drop write_path_rules() and write_paths() and replace them with the
  new write_file() function.
- adjust several code sections to use write_file() and 'file' instead of
  'path'

FileRule doesn't drop optional keywords ('allow' and 'file'), therefore
adjust cleanprof_test.out to the changed behaviour. (If someone insists
on dropping optional keywords in aa-cleanprof, that's something for a
future patch.)

Also adjust the list of known failures in test-parser-simple-tests.py -
switching to FileRule avoids several test failures (and introduces a few
new ones ;-)




IMPORTANT:

This patch introduces a "brain split" which means
- parsing and writing the profile and aa-cleanprof use the new location
  (aa[profile][hat]['file'])
- aa-logprof and aa-genprof still save data to the old location
  (aa[profile][hat]['allow']['path']) and probably ask superfluous
  questions because there are no rules existing in the old location

TL;DR: don't try aa-logprof or aa-genprof with only this patch applied.

I know this isn't ideal, but still better than an even bigger and
totally unreadable patch ;-)



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 19:54:48 +02:00
Christian Boltz
c1fc2c9011 [13/38] Add ANY_EXEC to FileRule
aa-logprof needs to check if an exec rule for a given path exists.

This patch adds a __FileAnyExec class to FileRule, as well as ANY_EXEC
(which should be used externally, similar to ALL), and adjusts several
checks to allow it as a special execute mode.

This will allow to use is_covered() (or aa.py is_known_rule()) to find
out if execute is permitted, which replaces aa.py profile_known_exec()
in one of the following patches.

As usual, also add some tests.



Acked-by: Steve Beattie <steve@nxnw.org>


Note: as discussed, I adjusted the comment for 'pass' around line 240.
2016-10-01 19:53:38 +02:00
Christian Boltz
991d55d1dd [12/38] Change RE_PROFILE_BARE_FILE_ENTRY and RE_PROFILE_PATH_ENTRY imports in test-regex_matches.py
Patch 14 will drop the RE_PROFILE_PATH_ENTRY and
RE_PROFILE_BARE_FILE_ENTRY import from apparmor.aa.
This would break test-regex_matches.py, therefore
import these regexes from apparmor.regex.



Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 19:52:57 +02:00
Christian Boltz
5431db744f [11/38] FileRule: Handle duplicated exec permissions
The parser accepts duplicated execute permissions as long as they don't
conflict. For example,
	/bin/foo pxpxpxpx,
is a valid rule.

This patch changes FileRule to also accept those duplicated permissions,
even if it's unlikely to hit them outside of the parser tests ;-)

Also add some tests to make sure the parsing works as expected.


Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 19:52:12 +02:00
Christian Boltz
68ccc4eea5 [10/38] RE_PATH: allow to match '/'
RE_PATH expected (simplified) '/.+', however this excludes a plain '/'
that can appear in path rules.

This patch changes the regex so that it also matches '/'.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:51:36 +02:00
Christian Boltz
b84877b900 [09/38] Drop contains() in aamode.py
After dropping the dead code in handle_children(), there's only one use
of contains() left in log_str_to_mode().

This patch changes log_str_to_mode to use mode_contains() and drops the
now unused contains() function.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:50:57 +02:00
Christian Boltz
b8171d547e [08/38] Drop dead code in aa.py handle_children()
The 'exec' handling in handle_children starts with

     if do_execute:
         if profile_known_exec(...)
            continue

which means if profile_known_exec() returns True, the rest of the loop
will be skipped. profile_known_exec() will return True if it finds an
exec rule in the profile or an include (independent of the exec type,
and (thanks to rematchfrag()) even if the path is globbed.

Later in the loop, there are checks for various exec modes - but those
checks can only be reached without an existing x rule, so they'll never
be hit.

This patch removes the dead code in the handle_children() / 'exec' / 'no
existing x rule found' section.

I confirmed that this code is really dead by
a) reading the code and, after being confused
b) two manual aa-logprof runs with coverage enabled - in one of them, I
   added some ix, Px and Cx rules, and in the second one, no more exec
   rules were needed/asked.

After dropping the dead code, combinedmode and combinedaudit are no
longer used, so we can also drop the code that sets those variables.


Sidenote: this patch drops 2% of the lines in aa.py ;-)



Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:49:50 +02:00
Christian Boltz
c8e98de53a [07/38] Add tests for FileRule
As usual, we have 100% test coverage - at least until patch 22, which
introduces one 'partial' ;-)


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:49:00 +02:00
Christian Boltz
05e57e3932 [06/38] Add FileRule and FileRuleset
These classes handle file rules, including file rules with leading
perms, and are meant to replace lots of file rule code in aa.py and
aa-mergeprof.

Note: get_glob() and logprof_header_localvars() don't even look
finalized and will be changed in a later patch. (Some other things will
also be changed or added with later patches - but you probably won't
notice them while reviewing this patch.)


Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Kshitij Gupta <kgupta8592@gmail.com> (with some suggestions for a follow-up patch)



v1.1: remove 'and not deny' from a condition in split_perms() to get
more helpful error messages for rules like "deny /foo pix,"

Acked-by: Steve Beattie <steve@nxnw.org>
2016-10-01 19:47:52 +02:00
Christian Boltz
8a875d84d2 [05/38] Make sanity check in _is_covered_list() optional
_is_covered_list() has a sanity check that raises an exception if both
other_value and other_all evaluate to False. This breaks when using
_is_covered_list() for FileRule.perms which can be empty if exec_perms
are specified.

This patch adds an optional parameter that allows to skip the sanity
check.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:47:19 +02:00
Christian Boltz
9eb7ce5992 [04/38] Add detailed regex for file rules
For now, use an additional regex RE_PROFILE_FILE_ENTRY to avoid
breakage of the existing code by the added match groups.

The regex includes support for file rules with leading and trailing
permissions as well as bare file rules.

Note: even with the restriction to the permission letters we actually
use, it's in theory still possible that a future additional rule type or
permission letter might lead to additional matches for other rule types.
Therefore the parsing code should check for all other rule types before
matching for file rules.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:46:37 +02:00
Christian Boltz
1302c5cf96 [03/38] check_and_split_list(): allow 'lst' parameter to be a set
list, tuple, set - does python offer even more array types? ;-)


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2016-10-01 19:46:15 +02:00
Christian Boltz
f1ecae9d4e [02/38] check_and_split_list: optionally allow empty list
File permissions can be an empty list (if only exec permissions are
specified). This patch adds the optional allow_empty_list parameter so
that the function can handle this case.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:45:51 +02:00
Christian Boltz
46350f7e27 [01/38] Pass 'strict' flag from is_equal to is_equal_localvars
File rules contain some optional details (like leading permissions and
the file keyword) which should be ignored in non-strict mode.

This patch passes through the 'strict' parameter to is_equal_localvars
and adds it as function parameter in all existing rule classes.
It also adjusts test-baserule.py to test with the additional parameter.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-10-01 19:45:16 +02:00
Steve Beattie
4492e7cb2d utils/test/test-aa.py: skip tests that break with python2.7
For reasons that aren't entirely clear, the action to set
apparmor.aa.cfg['settings']['ldd'] to './fake_ldd' does not actually
work on python2.7, get_reqs() tries to use /usr/bin/ldd anyway (printing
out the contents of apparmor.aa.cfg['settings']['ldd'] after the set
operation shows it to still contain '/usr/bin/ldd' o.O). Therefore, skip
these two tests when running under python2.7.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>

Bug: https://launchpad.net/bugs/1522938
2016-09-21 11:52:42 -07:00
Christian Boltz
b6734696ea Allow 'kcm' in network rules
This is probably
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/Documentation/networking/kcm.txt


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10.

Bug: https://launchpad.net/bugs/1513880
2016-09-12 23:34:11 +02:00
Christian Boltz
e2039f021e Fix aa-logprof "add hat" endless loop
This turned out to be a simple case of misinterpreting the promptUser()
result - it returns the answer and the selected option, and
"surprisingly" something like
    ('CMD_ADDHAT', 0)
never matched
    'CMD_ADDHAT'
;-)

I also noticed that the new hat doesn't get initialized as
profile_storage(), and that the changed profile doesn't get marked as
changed. This is also fixed by this patch.


References: https://bugs.launchpad.net/apparmor/+bug/1538306



Acked-by: Steve Beattie <steve@nxnw.org> for trunk, 2.10 and 2.9
2016-08-15 22:02:55 +02:00
Christian Boltz
c8bc128039 type_is_str(): make pyflakes3 happy
pyflakes3 doesn't check sys.version and therefore complains about
'unicode' being undefined.

This patch defines unicode as alias of str to make pyflakes3 happy, and
as a side effect, simplifies type_is_str().


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10.
2016-08-12 12:02:20 +02:00
Christian Boltz
9a76e33e9b delete_duplicates(): don't modify self.rules while looping over it
By calling self.delete() inside the delete_duplicates() loop, the
self.rules list was modified. This resulted in some rules not being
checked and therefore (some, not all) superfluous rules not being
removed.

This patch switches to a temporary variable to loop over, and rebuilds
self.rules with the rules that are not superfluous.

This also fixes some strange issues already marked with a "Huh?" comment
in the tests.


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10.

Note that in 2.10 cleanprof_test.* doesn't contain a ptrace rule,
therefore the cleanprof_test.out change doesn't make sense for 2.10.
2016-08-08 23:14:33 +02:00
Christian Boltz
00026d74ca logparser: store network-related params if an event looks like network
Network events can come with an operation= that looks like a file event.
Nevertheless, if the event has a typical network parameter (like
net_protocol) set, make sure to store the network-related flags in ev.

This fixes the test failure introduced in my last commit.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com> for trunk, 2.10 and 2.9
2016-07-31 17:13:57 +02:00
Christian Boltz
89c9a8cdc5 logparser.py: ignore network events with 'send receive'
We already ignore network events that look like file events (based on
the operation keyword) if they have a request_mask of 'send' or
'receive' to avoid aa-logprof crashes because of "unknown" permissions.
It turned out that both can happen at once, so we should also ignore
this case.

Also add the now-ignored log event as test_multi testcase.


References: https://bugs.launchpad.net/apparmor/+bug/1577051 #13


Acked-by: Tyler Hicks <tyhicks@canonical.com> for trunk, 2.10 and 2.9.
2016-07-30 00:41:43 +02:00
Tyler Hicks
cbaa772320 utils: Handle the safe/unsafe change_profile exec modes
https://launchpad.net/bugs/1584069

This patch adds support for the safe and unsafe exec modes for
change_profile rules. The logic is pretty simple at this point because
the kernel's default for exec modes changed in newer versions.
Therefore, this patch simply retains any specified exec mode in parsed
rules. If an exec mode is not specified in a rule, there is no attempt
to force the usage of "safe" because older kernels do not support it.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2016-07-20 17:24:11 -05:00
Christian Boltz
939587178b Drop unused escape() function from aa.py
Besides being unused, this function contains a broken regex.


References: https://bugs.launchpad.net/bugs/1593324


Acked-by: Steve Beattie <steve@nxnw.org>
2016-06-17 13:26:40 +02:00
Kshitij Gupta
242bbfbbeb Re-order imports in aa-mergeprof and rule/capability.py
Acked-by: Christian Boltz <apparmor@cboltz.de>
2016-06-10 01:18:32 +05:30
Christian Boltz
9ab68b9225 Add a note about still enforcing deny rules to aa-complain manpage
This behaviour makes sense (for example to force the confined program to
use a fallback path), but is probably surprising for users, so we should
document it.

References: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=826218#37


Acked-by: John Johansen <john.johansen@canonical.com> for trunk, 2.10 and 2.9
2016-06-05 23:43:29 +02:00
Christian Boltz
db093de5ff honor 'chown' file events in logparser.py
Also add a testcase to libapparmor's log collection


Acked-by: Kshitij Gupta <kgupta8592@gmail.com> for trunk, 2.10 and 2.9
2016-06-05 20:06:43 +02:00