Commit graph

5108 commits

Author SHA1 Message Date
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
c6128da1fc Merge branch 'cboltz-test-parse-profile-start' into 'master'
parse_profile_start: test with un-named profile

See merge request apparmor/apparmor!367

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-22 17:57:44 +00:00
Christian Boltz
233f7179ef Merge branch 'EmersonBernier/shellcheck' into 'master'
parser/rc.apparmor.functions: fix minor issues detected by shellcheck/shellharden

See merge request apparmor/apparmor!370

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-04-22 14:18:13 +00:00
Emerson Bernier
fe6fc458e7 parser/rc.apparmor.functions: fix minor issues detected by shellcheck/shellharden 2019-04-22 15:02:45 +02: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
115a1d890e
Drop 'to' option for link rules from manpage
The apparmor.d manpage listed 'to' as an alternative for '->' in link
rules.

However, the parser doesn't accept 'to', none of our examples and tests
include it, and nobody ever complained about it. Therefore I'll call
this a documentation bug ;-) and simply adjust the manpage to only list
'->' as valid syntax.
2019-04-22 12:46:37 +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
Christian Boltz
7ed1a16af1
Add several libapparmor/swig/ruby files to gitignore
These files get created by swig, and deleted with make clean
2019-04-21 21:56:46 +02:00
Christian Boltz
e3f0a6ff63 Merge branch 'feature/aa-notify-in-python' into 'master'
Rewrite aa-notify in Python

Closes #16

See merge request apparmor/apparmor!341

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-04-21 17:02:34 +00:00
Christian Boltz
cece787182 Merge branch 'bugfix/aa-always-logfile-fallback' into 'master'
Fix error 'KeyError: 'logfiles'' when no logprof.conf exists

See merge request apparmor/apparmor!365

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2019-04-21 16:48:34 +00: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
Christian Boltz
c01c867216 Merge branch 'feature/aa-test' into 'master'
Add tests for shared aa library functions used in command line scripts

See merge request apparmor/apparmor!328

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-04-19 20:24:08 +00: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
234a924480
syslog-ng: add abstractions/python for python-parser
When running syslog-ng with a defined python-parser, it needs access to
python libraries.

For details about python-parser, see
https://www.syslog-ng.com/community/b/blog/posts/format-your-log-messages-in-python

References: https://github.com/balabit/syslog-ng/issues/2625
2019-04-05 19:16:46 +02:00
Christian Boltz
1e4dcbeb23 Merge branch 'cboltz-complex-profile-name' into 'master'
Add some tests for complex profile names

See merge request apparmor/apparmor!360

Acked-by: Eric Chiang <ericchiang@google.com>
2019-04-03 20:35:53 +00: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
2b091491b0 Merge branch 'identd' into 'master'
identd: Add network netlink dgram

identd requires access to network netlink dgram.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/353
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-29 08:04:40 +00: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
9ba051c6ed Merge branch 'base-abstraction-allow-all-libraries' into 'master'
base abstraction: allow mr on *.so* in common library paths.

For example, VirtualBox guests have /usr/lib/VBoxOGL.so.

Without this changes, in a VirtualBox VM with VBoxVGA graphics,
at least one Qt5 application (OnionShare) won't start and display:

  ImportError: libGL.so.1: failed to map segment from shared object

… and the system logs have:

  apparmor="DENIED" operation="file_mmap" profile="/usr/bin/onionshare-gui" name="/usr/lib/VBoxOGL.so" pid=11415 comm="onionshare-gui" requested_mask="m" denied_mask="m" fsuid=1000 ouid=0

While this works fine with VBoxSVGA and VMSVGA when 3D acceleration is enabled.

So let's not assume all libraries have a name that starts with "lib".

Bug-Tails: https://redmine.tails.boum.org/code/issues/16414

Candidate for master and 2.13.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/345
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-24 07:04:14 +00:00
intrigeri
5cbb7df95e base abstraction: allow mr on *.so* in common library paths.
For example, VirtualBox guests have /usr/lib/VBoxOGL.so.

Without this changes, in a VirtualBox VM with VBoxVGA graphics,
at least one Qt5 application (OnionShare) won't start and display:

  ImportError: libGL.so.1: failed to map segment from shared object

… and the system logs have:

  apparmor="DENIED" operation="file_mmap" profile="/usr/bin/onionshare-gui" name="/usr/lib/VBoxOGL.so" pid=11415 comm="onionshare-gui" requested_mask="m" denied_mask="m" fsuid=1000 ouid=0

While this works fine with VBoxSVGA and VMSVGA when 3D acceleration is enabled.

So let's not assume all libraries have a name that starts with "lib".
2019-03-24 06:06:42 +00:00
John Johansen
5014f4a99c dovecot: master SIGTERM child that are slow to die
When doing a service reload, I noticed the following:

```Mar 22 15:52:27 smtp dovecot: master: Warning: SIGHUP received - reloading configuration
Mar 22 15:52:27 smtp dovecot: imap(simon): Server shutting down. in=35309 out=232805
Mar 22 15:52:27 smtp dovecot: imap(simon): Server shutting down. in=24600 out=1688166
Mar 22 15:52:27 smtp dovecot: imap(simon): Server shutting down. in=14026 out=95516
Mar 22 15:52:27 smtp dovecot: imap(simon): Server shutting down. in=13776 out=141513
Mar 22 15:52:33 smtp dovecot: master: Warning: Processes aren't dying after reload, sending SIGTERM.
Mar 22 15:52:33 smtp dovecot: master: Error: service(imap): kill(5806, 15) failed: Permission denied
Mar 22 15:52:33 smtp dovecot: master: Error: service(imap-login): kill(5804, 15) failed: Permission denied
Mar 22 15:52:33 smtp dovecot: master: Error: service(config): kill(506, 15) failed: Permission denied
Mar 22 15:52:33 smtp kernel: [65542.184326] audit: type=1400 audit(1553284353.609:82): apparmor="DENIED" operation="signal" profile="dovecot" pid=414 comm="dovecot" requested_mask="send" denied_mask="send" signal=term peer="/usr/lib/dovecot/imap"
Mar 22 15:52:33 smtp kernel: [65542.197596] audit: type=1400 audit(1553284353.625:83): apparmor="DENIED" operation="signal" profile="dovecot" pid=414 comm="dovecot" requested_mask="send" denied_mask="send" signal=term peer="/usr/lib/dovecot/imap-login"
Mar 22 15:52:33 smtp kernel: [65542.197635] audit: type=1400 audit(1553284353.625:84): apparmor="DENIED" operation="signal" profile="dovecot" pid=414 comm="dovecot" requested_mask="send" denied_mask="send" signal=term peer="/usr/lib/dovecot/config"
Mar 22 15:52:36 smtp dovecot: imap(simon): Server shutting down. in=17882 out=104004
```

The server was heavily loaded which is probably why it ended up trying to SIGTERM those.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/357
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-22 23:03:26 +00:00
Simon Deziel
f01fd38ca0 dovecot: master SIGTERM child that are slow to die
Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-03-22 18:33:14 -04: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
John Johansen
9eb738e5f1 Get rid of $MODULE, replace usage with hardcoded "apparmor"
I slightly ;-) doubt we'll change the module name.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/354
Signed-off-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-21 08:10:12 +00:00
John Johansen
ad7ea230aa parser/libapparmor_re: remove unnecessary throw(int)
Compiling the parser currently prints a deprecation warning. Remove
throw(int) annotations from function signatures. These aren't required
to catch exceptions. This gets us closer to possibly enabling '-Werror'
in the future.

For example, the following program catches the exception without a
throw(int) annotation:

	#include <iostream>
	void throw_an_error()
	{
	        throw 3;
	        return;
	}
	int main ()
	{
	        try
	        {
	                throw_an_error();
	        }
	        catch (int e)
	        {
	                std::cout << "caught exception " << e << '\n';
	        }
	        return 0;
	}

This program prints:

	$ g++ -o error error.cc
	$ ./error
	caught exception 3

PR: https://gitlab.com/apparmor/apparmor/merge_requests/356
Signed-off-by: Eric Chiang <ericchiang@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-21 08:07:48 +00:00
Christian Boltz
777a3137e5 Merge branch 'cboltz-shellcheck' into 'master'
Make shellcheck happier

See merge request apparmor/apparmor!355

Acked-by: Eric Chiang <ericchiang@google.com>
2019-03-18 23:31:31 +00:00
Christian Boltz
7b68d820ea
Add quotes around several variables
Note that $PARSER_OPTS has to stay without quotes because it can
sometimes be empty, and would (if quoted) be interpreted as empty
filename by apparmor_parser
2019-03-18 19:30:37 +01:00
Christian Boltz
5f46dedd6e
replace deprecated egrep with grep -e 2019-03-18 19:17:16 +01:00
Christian Boltz
6c42cd9eae
skip_profile: make tests posix-compatible
[ foo -o bar ] isn't supported everywhere, replace it with
[ foo ] || [ bar ]
2019-03-18 19:05:47 +01:00
Eric Chiang
48dcbb9dcb parser/libapparmor_re: remove unnecessary throw(int)
Compiling the parser currently prints a deprecation warning. Remove
throw(int) annotations from function signatures. These aren't required
to catch exceptions.

For example, the following program catches the exception without a
throw(int) annotation:

	#include <iostream>
	void throw_an_error()
	{
	        throw 3;
	        return;
	}
	int main ()
	{
	        try
	        {
	                throw_an_error();
	        }
	        catch (int e)
	        {
	                std::cout << "caught exception " << e << '\n';
	        }
	        return 0;
	}

This program prints:

	$ g++ -o error error.cc
	$ ./error
	caught exception 3

Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-03-18 10:57:05 -07:00
Christian Boltz
e20e49c130
Get rid of $MODULE, replace usage with hardcoded "apparmor"
I slightly ;-) doubt we'll change the module name.
2019-03-18 18:53:42 +01:00
Christian Boltz
75dc438823 Merge branch 'cboltz-deprecate-kill' into 'master'
drop most of apparmor_kill()

See merge request apparmor/apparmor!351

Acked-by: Eric Chiang <ericchiang@google.com>
2019-03-18 17:49:59 +00:00
Christian Boltz
c9148a304c Merge branch 'cboltz-subshell' into 'master'
remove_profiles(): Fix returning $retval

See merge request apparmor/apparmor!352

Acked-by: Eric Chiang <ericchiang@google.com> for 2.11..master
2019-03-18 17:45:53 +00:00
Goldwyn Rodrigues
1d75abba3f identd: Add network netlink dgram
identd requires access to network netlink dgram.
2019-03-18 11:15:49 -05:00
Christian Boltz
dc010bc034 Merge branch 'cboltz-utils-keywords' into 'master'
update network keyword list in utils and add test

See merge request apparmor/apparmor!350

Acked-by: Eric Chiang <ericchiang@google.com> for 2.12..master
2019-03-18 16:02:20 +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
Christian Boltz
be02f008c3
remove_profiles(): Fix returning $retval
Extend the subshell so that the actual (possibly non-zero) value of
$retval gets returned. Before, the changed value was lost at "done"
(= leaving the subshell), and the initial $retval=0 was returned.

(found with shellcheck)
2019-03-15 23:12:17 +01:00
Christian Boltz
0e3d6ee43a
drop most of apparmor_kill()
AppArmor can't be built as a kernel module since years, which also means
it's impossible to unload it.
2019-03-15 22:55:51 +01:00
Christian Boltz
6416ccebf6 Merge branch 'cboltz-network-keywords' into 'master'
apparmor.d manpage: update list of network domain keywords

See merge request apparmor/apparmor!349

Acked-by: Eric Chiang <ericchiang@google.com> for 2.12..master
2019-03-14 21:20:02 +00:00
Christian Boltz
6b2765637e
apparmor.d manpage: update list of network domain keywords
- add 'qipcrtr' and 'xdp'
- sort other keywords to the order in apparmor.vim
2019-03-14 21:54:30 +01:00