Commit graph

1275 commits

Author SHA1 Message Date
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
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
Christian Boltz
aa1e315e77
Add tests for link rules to test-file.py 2019-04-22 23:39:47 +02:00
Christian Boltz
f176baf904
Add support for link rules to FileRule 2019-04-22 23:39:47 +02:00
Christian Boltz
a477a06847
Extend RE_PROFILE_FILE_ENTRY to cover link rules 2019-04-22 23:39:47 +02:00
Christian Boltz
ee2185f4b6 Merge branch 'cboltz-link-owner' into 'master'
Add testcases for 'owner link' rules

See merge request apparmor/apparmor!369

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-22 17:59:06 +00:00
Christian Boltz
7d95e2658e Merge branch 'cboltz-typo' into 'master'
Fix typo in set_json_mode() comment

See merge request apparmor/apparmor!364

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-22 17:58:15 +00:00
Christian Boltz
0facb1598c
Add testcases for 'owner link' rules
.. and document that the tools don't support them yet
2019-04-22 13:36:33 +02:00
Christian Boltz
1d19bb7110
parse_profile_start: test with un-named profile
Also update the comment in _parse to match the updated return values.
2019-04-22 12:38:38 +02:00
Otto Kekäläinen
d4cab56ac7 aa-notify: Use fixed output width in tests so results always look same 2019-04-21 18:37:10 +03:00
Otto Kekäläinen
d5990da72a aa-notify: Use AATest class in tests since possible now with Python 2019-04-21 18:37:10 +03:00