Commit graph

1313 commits

Author SHA1 Message Date
Christian Boltz
e246568819
fix whitespace and indentation in several files 2019-08-12 23:58:04 +02:00
Christian Boltz
095d65f4ae
Simplify log prefilter in logparser.py
As discussed in https://gitlab.com/apparmor/apparmor/merge_requests/395
RE_LOG_ALL should be more broad so that it doesn't accidently
overlook/ignore valid log events.

Instead of adding more and more known log formats to logparser.py,
simplify the regex to do only a basic check.

If we really hand over a line to libapparmor that isn't an AppArmor log
event, worst thing that can happen is that we waste a few milliseconds
for handing over that line to libapparmor, and get AA_RECORD_INVALID as a
result.
2019-08-05 21:42:59 +02:00
Christian Boltz
a0c1eb0abd
logparser.py: don't error out on exec events without target
commit 7297e2f6a8 assumed that exec events
always have a "target=...", but this is only true for events in complain
mode. In enforce mode, the log line doesn't include "target=...".

This commits sets an empty target instead of erroring out on every exec
event in enforce mode.

Also adjust ask_exec() in aa.py to only update
hashlog[aamode][target_profile]['final_name'] if target_profile is set
(hashlog[aamode][''] doesn't exist and trying to write to it would error
out)
2019-07-27 22:48:30 +02:00
Christian Boltz
8f74ac02ca
Fix crash on unbalanced parenthesis in filename
convert_regexp() needs to escape '(' and ')' in filenames taken from a
logfile to get rid of their special meaning, and to avoid a crash on
unbalanced parenthesis (which makes the regex invalid if they are not
escaped).

Note: The added tests include an example log line, but the tests itsself
don't/didn't trigger the crash because they don't call convert_regexp().

Fixes: https://bugs.launchpad.net/bugs/1835311
2019-07-07 22:24:12 +02:00
John Johansen
0349cf2d0a libapparmor: logparse: fix RECORD_INVALID for valid log
v2:
- parse partial log line broken at \n
- add testcase_dbus_10.* for partial log line
- remove quotes from  testcasw_dbus_09.profile

The following log format has been seen in the wild, and currently results
in a RECORD_INVALID

    [4835959.046111] audit: type=1107 audit(1561053426.749:186): pid=640 uid=103 auid=4294967295 ses=4294967295 msg='apparmor="ALLOWED" operation="dbus_method_call"  bus="system" path="/org/freedesktop/systemd1" interface="org.freedesktop.systemd1.Manager" member="LookupDynamicUserByName" mask="send" name="org.freedesktop.systemd1" pid=20596 label="/usr/sbin/sshd" peer_pid=1 peer_label="unconfined"
                      exe="/usr/bin/dbus-daemon" sauid=103 hostname=? addr=? terminal=?'

Test parsing the above message with and without the \n embedded between
peer_label= and exec=

Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-07-02 01:01:37 -07:00
John Johansen
9144e39d25 Revert "utils/test-network.py: fix failing testcase"
This reverts commit 378519d23f.
this commit was meant for the 2.13 branch not master

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-14 01:05:16 -07:00
Steve Beattie
378519d23f utils/test-network.py: fix failing testcase
When dc010bc034 was
backported to the apparmor-2.13 branch (in commit
75236d62e2), it did not take into
account cb8c3377ba, which creates the
common/list_af_names.sh script as used in the test case, was not also
backported to the apparmor-2.13 branch.

Change the test case to get the list of network AF names via the same
make invocation taken by the utils/vim/create-apparmor.vim.py script
before the common/list_af_names.sh existed.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/391
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-06-14 00:04:00 -07:00
Steve Beattie
03c08cf989
utils: remove conflicting action in Swedish translation
The translated action character for Deny conflicted with the
untranslated action character for Finish in the Swedish translation.
Remote it, and hope for more action translations.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 15:03:06 -07:00
Launchpad Translations on behalf of apparmor-dev
9d226f5887
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:39:52 -07:00
Launchpad Translations on behalf of apparmor-dev
01656486ef
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:39:52 -07:00
Launchpad Translations on behalf of apparmor-dev
90a4b301bd
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:39:52 -07:00
Launchpad Translations on behalf of apparmor-dev
3b1c320cfc
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:01 -07:00
Launchpad Translations on behalf of apparmor-dev
5a62c68743
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
78c09e4337
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
2c614d4413
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
d14723b78c
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
fe2faeb24f
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:30:00 -07:00
Launchpad Translations on behalf of apparmor-dev
9650201928
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
2b936e25a8
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
02ba8523c6
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
72bcf23c5d
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
9f9294b48b
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
41b5fecbcf
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:59 -07:00
Launchpad Translations on behalf of apparmor-dev
dc98e8ff55
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:29:09 -07:00
Launchpad Translations on behalf of apparmor-dev
ba3dc9fc85
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:28:53 -07:00
Launchpad Translations on behalf of apparmor-dev
42b43d58d0
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:28:40 -07:00
Launchpad Translations on behalf of apparmor-dev
301857ef5d
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:28:10 -07:00
Launchpad Translations on behalf of apparmor-dev
303deea3a8
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:27:22 -07:00
Launchpad Translations on behalf of apparmor-dev
eb38db5953
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:26:30 -07:00
Launchpad Translations on behalf of apparmor-dev
5cc8718965
Launchpad automatic translations update.
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-06-13 14:26:01 -07:00
Christian Boltz
5abfb08a3e
drop unused 'finishing' in do_logprof_pass()
finishing was always false, resulting in always returning 'NORMAL'.

Remove the variable, remove the unused condition - and change the only
place (aa-genprof) that expected a return value from do_logprof_pass()
to not expect it anymore.

found by Coverity, CID 198637
2019-05-17 22:27:57 +02:00
Christian Boltz
758a6b214f Merge branch 'cboltz-rewrite-logparser' into 'master'
Rewrite log handling

logparser.py puts each log event on a big "stack" in self.pid. Later,
handle_children() in aa.py then converts that (named 'log' in aa.py) to
the prelog hasher.

This commit changes logparser.py to create a prelog-like structure itsself
(named hashlog), which
- removes one level of indirection
- probably saves some memory because the hashlog automatically
  de-duplicates events

In aa.py, collapse_log() gets updated to work with hashlog. (There's
also a handle_hashlog() function in this patch series, but it didn't 
survive the final patches ;-)

OTOH, the now superfluous code handling capability, network etc.
events gets removed from handle_children(). The remaining parts of
this function get split into ask_exec() and ask_addhat().

logparser.py gets a new function init_hashlog() to initialize hashlog
for each profile. It also gets changed to store capability, network etc.
events into hashlog instead of storing them in self.pid.

hashlog uses the full profile name as key, which is the first baby step
to support nested child profiles. (for now, collapse_log() still
splits the profile name into profile and hat.)

There are many more details, see the individual commits ;-)

See merge request apparmor/apparmor!377

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-05-12 10:56:14 +00:00
Christian Boltz
205ae4a256
collapse_log(): don't overwrite existing ProfileStorage
When a user chooses the ix exec mode, don't overwrite the existing
ProfileStoragge to avoid loosing the already collected events.
2019-05-09 18:22:07 +02:00
Christian Boltz
836caca462
collapse_log: ignore events from null-* profiles
If final_name still includes null-*, that's most likely caused by nested
execs which aren't supported by the tools yet. Ignoring them is better
than creating a useless null-* hat.

Note: The tools always had this restriction, so this is not a regression ;-)

Also note that test-libapparmor-test_multi expects that null-* hats get
created (which makes sense because the one-line log sniplets don't have
any exec indication), therefore add an optional parameter to keep this
behaviour for the tests.
2019-05-09 18:14:18 +02:00
Christian Boltz
387d1646c8
Merge handle_hashlog() into collapse_log()
Now that all log events arrive in hashlog, having a separate 'prelog' no
longer makes sense. Changing collapse_log() to accept 'hashlog' directly
removes that level of indirection.
2019-05-09 17:29:26 +02:00
Christian Boltz
c5f0097f65
make 'prelog' non-global
It's only used by two functions:
- handle_hashlog() - writes to prelog, and now returns it
- collapse_log() - reads prelog, and now gets it as parameter
2019-05-09 17:29:26 +02:00
Christian Boltz
c77426ed62
Introduce 'final_name' to hashlog and handle exec choices
'final_name' by default is the profile name, but ask_exec() will change
it for the target profile (which is a null-* profile at this stage)
based on exec mode choice. ask_addhat() will also change it based on the
chosen hat.

Choosing "deny" or "unconfined" will result in an empty final_name and
ignoring these log events.

All other choices set final_name to the full profile name ("foo" for Px,
"foo//bar" for Cx, current profile for ix).

Also fix the order of handling log events - since ask_exec() changes the
hashlog final_name, it has to run first so that ask_addhat() (which
"only" adjusts the hat name in final_name) and handle_hashlog() can work
with the updated profile name.

Finally, update test-libapparmor-test_multi.py to ignore final_name when
checking if hashlog is empty, and fix the call order of ask_exec() etc.
2019-05-09 17:29:26 +02:00
Christian Boltz
d1b8772a1d
ask_exec(): simplify to_name logic
At this stage of ask_exec(), to_name is always empty, therefore drop an
if condition that checks it (and the code inside that branch).
2019-05-09 17:15:35 +02:00
Christian Boltz
5953ac3dda
ask_exec(): drop useless setting of profile and hat
profile and hat don't get used in the following lines, and later get
overwritten in the next round of the for loop.

The deleted code was last useful for setting the (dropped)
profile_changes array.
2019-05-09 17:15:35 +02:00
Christian Boltz
3ec4869adf
ask_exec(): Get rid of unused context_new variable 2019-05-09 17:15:35 +02:00
Christian Boltz
48cc1b2837
add a split_name() function to split a profile name
... into profile and hat.

Also change several places to use split_name().
2019-05-09 17:15:35 +02:00
Christian Boltz
305b378bfd
Delete apparmor/aamode.py and its testsuite
After the logparser cleanup, aamode.py and its overly complicated
permission handling is no longer needed.
2019-05-09 17:15:35 +02:00
Christian Boltz
45a3d8920a
Drop unused 'pid' parameter from ReadLog.__init__()
... and self.pid which is also unused.

This simple change also means to adjust all the code that uses ReadLog.
We get rid of log_pid in aa.py, and have to change lots of test-*
2019-05-09 17:15:35 +02:00
Christian Boltz
9a92909a89
Change read_log to return only hashlog
self.log is unused, drop it.

Also change all places that call read_log() to match the simplified
return value.
2019-05-09 17:15:35 +02:00
Christian Boltz
d4512aa5d7
Drop add_to_tree and some superfluous code
After all the changes in this branch, parse_event_for_tree always
returns None, which makes the "if event is not None" branch dead code.

This branch was the only place where add_to_tree() was called, therefore
remove this function.

This also makes self.pid and self.log unused. They'll be removed with
separate commits.
2019-05-09 17:15:35 +02:00
Christian Boltz
3b77d63556
ask_exec(): don't overwrite 'hat' in cx handling
Otherwise we'd have to reset 'hat' in the next round of the for loop.

Using 'exec_target' instead of 'hat' in the cx code is much easier.
2019-05-09 17:15:35 +02:00
Christian Boltz
d2663b148a
Transform handle_children() to ask_exec()
The only remaining job of handle_children() was to handle exec events.
(And recursively calling itsself if it hits nested log events, but
logparser.py never created such a log structure.)

Therefore:
- drop the dead code handling nested log (type != str)
- rename the remaining function to ask_exec()
- drop checks for typ = 'exec' (now done as part of the for loop
- drop the "else" branch for unknown event types
- change 'return' to 'continue' because ask_exec handles all exec events
  in a loop instead of being called multiple times
- oh, and of course switch over to using hashlog

Finally, change do_logprof_pass() and the tests to call ask_exec()
instead of handle_children().

While on it, update a comment in test-translations.py which held the
last reference to handle_children().
2019-05-09 17:15:35 +02:00
Christian Boltz
7297e2f6a8
parse_event_for_tree(): Move exec events to loghash
The 'hat' and 'prog' variables are no longer needed, drop them.

Also no longer include denied_mask in the event - operation='exec' means
an exec event, no need to additionally hand over 'x' permissions.

Note: This commit introduces a "brain split", which means exec handling
is temporarily broken. Later commits will fix this.
2019-05-03 23:25:55 +02:00
Christian Boltz
62adc8547c
handle_children(): drop using 'prog' and checking for non-empty to_name
parse_event_for_tree() always sets prog = 'HINT' and to_name = '' for
exec events.

The only exception is in the 'mandatory profile missing' case where
prog = aamode and to_name = target_profile, but I've never seen that in
practise.

This means the prog != 'HINT' branch in exec handling never gets used
and can be dropped.

Erroring out "if to_name:" also never gets used (to_name is always ''),
therefore drop it as well.
2019-05-03 23:01:21 +02:00
Christian Boltz
460d1fda93
handle_children(): get rid of 'domainchange'
"if domainchange == 'change':" is always true, therefore get rid of this
check and the domainchange variable.
2019-05-03 22:54:46 +02:00