Commit graph

1261 commits

Author SHA1 Message Date
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
Otto Kekäläinen
a74d7cf51c Re-implement aa-notify in Python (Closes: #16)
- Code layout based on aa-genprof example
- Extend Python dependencies to cover new need by aa-notify
- Update documentation after aa-notify is no longer in Perl
2019-04-21 18:37:10 +03:00
Otto Kekäläinen
3a1eec49d4 Add tests for shared aa library functions used in command line scripts 2019-04-21 18:37:10 +03:00
Otto Kekäläinen
3c7e1668bd aa.py: Indicate permission error if log file is found but cannot be opened 2019-04-21 18:35:33 +03:00
Otto Kekäläinen
455c441357 aa.py: Ensure there is always a fallback falue for the logfile location
Related to #22.

Fixes error message:

  Traceback (most recent call last):
    File "./aa-notify", line 523, in <module>
      main()
    File "./aa-notify", line 399, in main
      aa.set_logfile(args.file)
    File "/home/otto/koodia/apparmor/utils/apparmor/aa.py", line 1762,
    in set_logfile
      print(conf.find_first_file(cfg['settings']['logfiles']))
    File "/usr/lib/python3.6/configparser.py", line 1233, in __getitem__
      raise KeyError(key)
  KeyError: 'logfiles'
2019-04-20 23:34:04 +03:00
Christian Boltz
7153eb09d9
Fix typo in set_json_mode() comment 2019-04-19 22:25:30 +02:00
Otto Kekäläinen
fdd13db13b Add tests for shared aa library functions used in command line scripts 2019-04-19 17:29:26 +03:00
Christian Boltz
9feebc4363
Add some tests for complex profile names
Add some tests with the complex profile name (including alternations and
wildcards) to ensure we don't break such cases in the future.

These tests are based on the log from the (invalid) bugreport
https://gitlab.com/apparmor/apparmor/issues/26
2019-03-31 17:34:55 +02:00
John Johansen
52b3fc220e Adjust tests to match base abstraction update.
Since !345 the set of permissions that are granted (get_file_perms_2)
or suggested (propose_file_rules) has changed. These new sets are
expected due to the changes brought by this MR, so let's adjust
the test suite accordingly.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/358
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-29 07:56:23 +00:00
intrigeri
0170e98f9c Adjust tests to match base abstraction update.
Since !345 the set of permissions that are granted (get_file_perms_2)
or suggested (propose_file_rules) has changed. These new sets are
expected due to the changes brought by this MR, so let's adjust
the test suite accordingly.
2019-03-24 14:45:03 +00:00
John Johansen
cfe20d2b63 Add support for profiles with xattrs matching
Add userland support for matching based on extended file attributes. This
leverages DFA based matching already in the kernel:

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8e51f908
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=73f488cd

Matching is exposed via flags on the profile:

    /usr/bin/* xattrs=(user.foo=bar user.bar=foo) {
        # ...
    }

xattr values are appended to the existing xmatch via a null transition.

    $ echo '/usr/bin/* xattrs=(user.foo=foo user.bar=bar) {}' | \
        ./parser/apparmor_parser -QT -D expr-tree
    DFA: Expression Tree
    /usr/bin/[^\0000/]([^\0000/])*(\0000bar)?(\0000foo)?< 0x1>
    DFA: Expression Tree
    (\a|(\n|(\0002|\t)))< 0x4>

Tested manually on a 4.19 kernel via QEMU+KVM.

TODO:

  * ~~Add regression tests~~ (EDIT: done)
  * ~~EDIT: add support in the tools~~ (EDIT: done)

Questions for reviewers:

  * ~~parser/libapparmor: regex construction probably needs cleaning up~~ (EDIT: done)
  * ~~parser/parser_regex.c: confused what xmatch length is for~~ (EDIT: done)

/cc @mjg59

PR: https://gitlab.com/apparmor/apparmor/merge_requests/270
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-21 08:12:07 +00:00
Christian Boltz
49849ed7a3
update network keyword list in utils and add test
The tools also have a list of network keywords, update it:
- add xdp and qipcrtr
- move ib and mpls to match the kernel order

Also add a test to ensure that (at least) the keywords provided by the
running kernel are listed in network_domain_keywords.
2019-03-16 12:52:37 +01:00
Eric Chiang
a42fd8c6f4 parser: add support for matching based on extended file attributes
Add userland support for matching based on extended file attributes.
This leverages DFA based matching already in the kernel:

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=8e51f908
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=73f488cd

Matching is exposed via flags on the profile:

  /usr/bin/* xattrs=(user.foo=bar user.bar=**) {
      # ...
  }

Profiles list the set of extended attributes that a file MUST have, and
a regex to match the value of that extended attributes. Additional
extended attributes on the file don't effect the match.

Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-03-14 10:47:54 -07:00
Christian Boltz
62abfe38e8
Replace deprecated assertEquals with assertEqual
assertEquals is deprecated since Python 2.7 and 3.2.
2019-02-26 21:27:00 +01:00
Christian Boltz
f729391deb Merge branch 'cboltz-test-setup_aa' into 'master'
add an example for setup_aa() to test-example.py

See merge request apparmor/apparmor!330

Acked-by: Steve Beattie <steve@nxnw.org>
2019-02-13 22:42:19 +00:00