Commit graph

1384 commits

Author SHA1 Message Date
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
Christian Boltz
13f67d45d0
ask_addhat: print warning only if we have change_hat events
Printing the warning whenever a child profile exists is pointless. It
only makes sense if there are change_hat events inside the child profile.
2019-05-03 22:54:46 +02:00
Otto Kekäläinen
81d514d89a aa-notify: Always use aa.CONFDIR, don't assume "/etc/apparmor"
Also fix cosmetic comment.
2019-05-03 17:53:24 +03:00
Christian Boltz
1b7cdec70d
Fix and simplify ask_addhat()
- replace/merge 'uhat' with 'hat'
- adjust ProfileStorage comment to the new function name
- initialize default hat if it gets chosen and doesn't exist yet
- don't exit the function if "Deny" gets chosen. Instead, continue with
  the next hat to (possibly) add
2019-05-03 00:12:46 +02:00
Christian Boltz
560fb6fabe
Use hashlog for change_hat log events
Adjust logparser.py to store change_hat events in hashlog.

In aa.py,
- split off ask_addhat() from handle_children()
- change ask_addhat() to use hashlog
- call ask_addhat() from do_logprof_pass()

Also call ask_addhat() in test-libapparmor-test_multi.py to keep it in
sync with do_logprof_pass().
2019-05-03 00:12:46 +02:00
Christian Boltz
eeb70c4695
drop restriction on complain mode in change_hat handling
Also move/merge the remaining change_hat checks into the section
handling change_hat events.
2019-05-02 23:10:08 +02:00
Christian Boltz
49b8ca1e73
handle_children: don't initialize variables that get always set
All the variables initialized at the start of the function always get
overwritten in the loop, therefore it's superfluous to initialize them.

Also inline 'entries' to the only place that uses it.
2019-05-02 23:10:08 +02:00
Christian Boltz
a2870a71cb
Drop handling of operation="clone"
According to John, this isn't supported since 10 years.

In case you wonder why this commit removes the "fork" handling in
handle_children() - logparser.py names clone events "fork" on the event
stack.
2019-05-02 23:10:03 +02:00
Christian Boltz
d11ed33d16
Stop ignoring profile_set events
According to John, this is no longer needed.
2019-05-02 20:24:15 +02:00
Christian Boltz
8b1b10babd
Add tests for parse_event_for_tree() with invalid log lines
Also convert test-logparser.py to AATest.
2019-05-02 01:10:18 +02:00
Christian Boltz
a43c1da287
Remove superfluous code and checks in path log handling
In logparser parse_event_for_tree() path event handling, drop mapping
permissions for request_mask because request_mask never gets used.
Also drop the validate_log_mode() call because the function has its own,
more strict check since the last commit.

In aamode.py, drop the now unused validate_log_mode() and
hide_log_mode() functions and the LOG_MODE_RE regex.

Finally, drop the validate_log_mode() tests from test-aamode.py
2019-05-02 01:10:18 +02:00
Christian Boltz
3d3667f38b
move path log event handling to hashlog
In logparser.py parse_event_for_tree, convert path handling to hashlog.
While on it, include 'owner' as part of hashlog so that aa.py doesn't
need to guess.

Also switch to a simple for loop instead of using log_str_to_mode() from
aamode.py to convert denied_mask to hasher keys (which would have been
needed to allow merging of several log events for the same path anyway).
Note that the check for 'mrawlk' (intentionally without 'x') is more
strict than the validate_log_mode(), but it should still cover all file
permissions. (validate_log_mode() also allows things like 'Px', which
we'll never hit in a logfile.)

In aa.py collapse_log() update the handling of path events to match the
additional [owner] key in hashlog/prelog. This makes the owner detection
in collapse_log() superfluous.

In aa.py handle_children(), remove 'path' handling from the 'path' or
'exec' section, and add an 'if True:' to avoid lots of whitespace
changes.

In aamode.py, drop the now unused split_mode() function, and
AA_OTHER_REMOVE() that was only used by split_mode().

Finally, remove sample log events with null-* hats from the list of
known failures in test-libapparmor-test_multi.py (we no longer filter
out null-* hats), and fix whitespace in two expected profiles.
2019-05-02 01:10:18 +02:00
Christian Boltz
1a46de1892
drop check if 'inode_permission' event means exec
According to John, 'inode_permission' wasn't used for 10 years.

This little change also means that we now have a clear separation
between "exec" and "normal" (mrwlk) file events.

Also drop the now superfluous makes peek_at_next_log_entry() and
throw_away_next_log_entry() functions.
2019-05-02 01:10:13 +02:00
Christian Boltz
61251dfd50
move dbus and ptrace log events to hashlog 2019-05-01 21:24:48 +02:00
Christian Boltz
6b63f49ad4
Remove a level of indirection on logparser.py
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 the prelog structure itsself
(named hashlog), which
- removes one level of indirection
- probably saves some memory because the hashlog automatically
  de-duplicates events

This commit does this for capability, network and signal events, and
adds the infrastructure needed for all event/rule types.

In aa.py, the new function handle_hashlog() copies the hashlog content
to prelog. OTOH, the now superfluous code handling capability, network
and signal events gets removed from handle_children().
Long-term, hashlog will replace log in aa.py. When this is done,
handle_hashlog() will be replaced by a simple prelog = hashlog.

logparser.py gets a new function init_hashlog() to initialize hashlog
for each profile. It also gets changed to store capability, network and
signal 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, handle_hashlog() still
splits the profile name into profile and hat.)

Known issue: The new implementation doesn't handle exec yet, which means
that events get lost at the exec boundary (= in cases aa-logprof asks
which execute mode to use). This will be fixed in a later commit.
2019-05-01 21:22:36 +02:00
Christian Boltz
7282fbd8bf Merge branch 'cboltz-drop-set-process' into 'master'
Drop broken set_process() and the profile_changes array

See merge request apparmor/apparmor!376

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2019-05-01 16:44:48 +00:00
Christian Boltz
14a3ca0439
Drop no longer used set_allow_str()
The old link rule implementation (which was replaced some commits ago)
was the last user of this function.
2019-04-30 00:59:09 +02:00
Christian Boltz
7099459f2c
drop profile_changes array
... which is unused after dropping set_process()
2019-04-30 00:02:05 +02:00
Christian Boltz
b07459c854
Drop broken set_process()
This function was meant to set a process running under a null-* profile
to its "real" profile after deciding about the exec mode/target.
However, this is not supported in the kernel.

"Luckily" the function was also broken and exited early, which
successfully prevented erroring out.

All that means set_process() is useless and we can drop it.
2019-04-29 23:35:52 +02:00
Christian Boltz
382eb7a629 Merge branch 'cboltz-link' into 'master'
Move handling of 'link' rules to FileRule

See merge request apparmor/apparmor!371

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-29 19:09:32 +00:00
Christian Boltz
f473e692c7 Merge branch 'cboltz-mergeprof-import' into 'master'
drop superfluous import apparmor.aamode from aa-mergeprof

See merge request apparmor/apparmor!373

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-29 18:58:07 +00:00
Christian Boltz
53a2eb56b4
handle_children: raise exception on unknown event type
(shouldn't happen, but a check never hurts)
2019-04-28 17:57:37 +02:00
Christian Boltz
f5add27aaa
rename 'netdomain' log events to 'network' to match rule name 2019-04-28 16:27:48 +02:00
Christian Boltz
b86fed1a57
drop commented out code from logparser.py 2019-04-28 14:37:43 +02:00
Christian Boltz
bed9ce35a1
inline parse_log_record() into parse_event_for_tree() and read_log() 2019-04-28 12:04:43 +02:00
Christian Boltz
1ce93a4c2d
inline add_event_to_tree() into read_log() 2019-04-28 11:57:29 +02:00
Christian Boltz
3dd6fdad79
drop superfluous import apparmor.aamode from aa-mergeprof 2019-04-23 21:53:52 +02:00
Christian Boltz
99b476510f
Remove 'owner link' tests from list of known-broken tests
... because they work now :-)
2019-04-23 00:22:25 +02:00
Christian Boltz
6bcfbb7a18
Remove old code for link rules 2019-04-23 00:22:25 +02:00
Christian Boltz
09a761ed80
Update and extend cleanprof tests for link rules 2019-04-22 23:41:08 +02:00