Commit graph

5796 commits

Author SHA1 Message Date
John Johansen
21060e802a parser: Fix warning message when complain mode is forced
when a profile is being forced to complain a variation of the
following message is displayed

  Warning from /etc/apparmor.d/usr.sbin.sssd (/etc/apparmor.d/usr.sbin.sssd line 54): Warning failed to create cache: usr.sbin.sssd

This is incorrect in that the parser doesn't even try to create the
cache, it just can't cache force complain profiles.

Output a warning message for this case that is correct.

Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1899218
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/649
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-10-11 03:34:37 -07:00
Christian Boltz
01f5954b5c
Fix wording of some warnings
pwarn() prints "Warning" itsself, therefore it doesn't make sense to
include/repeat that word in the actual warning text.
2020-10-11 12:22:23 +02:00
John Johansen
ec19ff9f72 parser: fix parser.conf commenting on pinning an abi
The comments describing the example rules to pin the abi are wrong.
The comments of the two example rules are swapped resulting in confusion.

While we are at it. Add a reference to the wiki doc on abi, and
how to disable abi warnings without pinning.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/648
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-10-09 13:25:49 -07:00
John Johansen
042a75a6a5 Merge Fix dhclient and dhclient-script profiles to work on debian buster
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/645
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-08 06:33:08 +00:00
John Johansen
05acf374b1 Merge aa_status: Fix build issue with musl
add limits.h

aa_status.c:269:22: error: 'PATH_MAX' undeclared (first use in this function); did you mean 'AF_MAX'? | 269 | real_exe = calloc(PATH_MAX + 1, sizeof(char));

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/647
Signed-off-by: Armin Kuster [akuster808@gmail.com](mailto:akuster808@gmail.com)
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-08 06:31:02 +00:00
Armin Kuster
0dbcbee700 parser/Makefile: dont force host cpp to detect reallocarray
In cross build environments, using the hosts cpp gives incorrect
detection of reallocarray. Change cpp to a variable.

fixes:
parser_misc.c: In function 'int capable_add_cap(const char*, int, unsigned int, capability_flags)':
| parser_misc.c:297:37: error: 'reallocarray' was not declared in this scope
|   297 |   tmp = (struct capability_table *) reallocarray(cap_table, sizeof(struct capability_table), cap_table_size+1);

Signed-off-by: Armin Kuster <akuster808@gmail.com>
2020-10-07 20:55:52 -07:00
Bernhard M. Wiedemann
bd1e22ad07 profiles: add pyzorsocket and razorsocket
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:26:01 +02:00
Bernhard M. Wiedemann
c343f052c0 profiles: add haproxy
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:26:01 +02:00
Bernhard M. Wiedemann
2eea414c68 profiles: add clamd
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:26:01 +02:00
Bernhard M. Wiedemann
8319bc5dc7 profiles: Add 3 more dovecot services
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:26:01 +02:00
Bernhard M. Wiedemann
286f071259 profile: Allow SSL access to freshclam
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:12:45 +02:00
Bernhard M. Wiedemann
6e908f28d6 profiles: Drop duplicate line
already covered by dovecot-common

Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
2020-10-07 20:12:45 +02:00
Armin Kuster
a2a0d14b9c aa_status: Fix build issue with musl
add limits.h

aa_status.c:269:22: error: 'PATH_MAX' undeclared (first use in this function); did you mean 'AF_MAX'?
|   269 |    real_exe = calloc(PATH_MAX + 1, sizeof(char));

Signed-off-by: Armin Kuster <akuster808@gmail.com>
2020-10-07 09:10:43 -07:00
Christian Boltz
17c55b3bf8 Merge branch 'master' into 'master'
apparmor: fix manpage order

See merge request apparmor/apparmor!646

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-10-07 15:48:28 +00:00
Armin Kuster
37b9028499 apparmor: fix manpage order
It trys to create a symlink before the man pages are installed.

 ln -sf aa-status.8 /(path}/apparmor/3.0-r0/image/usr/share/man/man8/apparmor_status.8
 | ln: failed to create symbolic link '{path}/apparmor/3.0-r0/image/usr/share/man/man8/apparmor_status.8': No such file or directory

...

install -d /{path}/apparmor/3.0-r0/image/usr/share/man/man8 ; install -m 644 aa-status.8 /{path}/apparmor/3.0-r0/image/usr/share/man/man8;

Signed-off-by: Armin Kuster <akuster808@gmail.com>
2020-10-07 06:30:33 -07:00
Anton Nesterov
9b70ef4fb7 Fix dhclient and dhclient-script profiles to work on debian buster 2020-10-06 19:51:07 +00:00
John Johansen
6e7d1b6baa Merge Skip test if it can not access /var/log/wtmp
utils/test/test-aa-notify.py: Change `AANotifyTest.test_entries_since_login()` to be decorated by a `skipUnless()` checking for existence of **/var/log/wtmp** (similar to `AANotifyTest.test_entries_since_login_verbose()`). The test otherwise fails trying to access /var/log/wtmp in environments where the file is not available.

Closes https://gitlab.com/apparmor/apparmor/-/issues/120
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/641
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-05 00:01:22 +00:00
John Johansen
1909561150 Merge Test for full parser error messages, not parts
By using assertIn, we test if a given message is contained in the parser error message. This can (and actually does) hide errors if the error message changes outside the checked part.

Change the test to assertEqual to test the full error message, and add '\\n' to all expected error messages to make them still match.

Note: test_modefail() has an outdated error message which went unnoticed so far, and should cause the (updated) tests to fail.

I'll add another commit that adjusts the expected test_modefail() error message as soon as we have an official test failure.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/632
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-04 23:58:52 +00:00
Christian Boltz
3f752fac5f
Ensure empty stderr if no errors are expected
... instead of not checking stderr if it's expected to be empty.
2020-10-04 19:51:54 +02:00
Christian Boltz
37552669d4
Test for full parser error messages, not parts
By using assertIn, we test if a given message is contained in the parser
error message. This can (and actually does) hide errors if the error
message changes outside the checked part.

Change the test to assertEqual to test the full error message, and add
'\n' to all expected error messages to make them still match.

Depending on the kernel version and patches, there can be an additional
message
    Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)
which will be ignored by the check.
2020-10-04 19:51:54 +02:00
John Johansen
e6e54dc9e7 Merge libapparmor: add missing include for socklen_t
While `include/sys/apparmor.h` makes use of `socklen_t`, it doesn't include the `<sys/socket.h>` header to make its declaration available. While this works on systems using glibc via transitive includes, it breaks compilation on musl libc.

Fix the issue by including the header.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/642
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-03 20:15:17 +00:00
John Johansen
4a89067c1a Merge Symbol visibility
This fixes two issues with symbol visibility that's exposed when linking `apparmor_parser`.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/643
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-03 19:21:15 +00:00
Patrick Steinhardt
9a8fee6bf1 libapparmor: add _aa_asprintf to private symbols
While `_aa_asprintf` is supposed to be of private visibility, it's used
by apparmor_parser and thus required to be visible when linking. This
commit thus adds it to the list of private symbols to make it available
for linking in apparmor_parser.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2020-10-03 21:08:41 +02:00
Patrick Steinhardt
c9255a0343 libapparmor: add aa_features_new_from_file to public symbols
With AppArmor release 3.0, a new function `aa_features_new_from_file`
was added, but not added to the list of public symbols. As a result,
it's not possible to make use of this function when linking against
libapparmor.so.

Fix the issue by adding it to the symbol map.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2020-10-03 21:08:37 +02:00
Patrick Steinhardt
47263a3a74 libapparmor: add missing include for socklen_t
While `include/sys/apparmor.h` makes use of `socklen_t`, it doesn't
include the `<sys/socket.h>` header to make its declaration available.
While this works on systems using glibc via transitive includes, it
breaks compilation on musl libc.

Fix the issue by including the header.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2020-10-03 20:42:51 +02:00
David Runge
e0200b1b16
Skip test if it can not access /var/log/wtmp
utils/test/test-aa-notify.py:
Change `AANotifyTest.test_entries_since_login()` to be decorated by a
`skipUnless()` checking for existence of **/var/log/wtmp** (similar to
`AANotifyTest.test_entries_since_login_verbose()`).
The test otherwise fails trying to access /var/log/wtmp in environments
where the file is not available.

Fixes #120
2020-10-02 23:58:53 +02:00
John Johansen
5d51483bfe Prepare for AppArmor 3.0 release
- update Version file
- keep lib version updated in beta

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-10-01 09:50:10 -07:00
John Johansen
c9d5ba4a0d Merge parser: Fix parser FTBS due to reallocarray
Older glibcs and alternate libcs don't have reallocarray()

So define it if not defined by libc.

Closes item 3 of https://gitlab.com/apparmor/apparmor/-/issues/109
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/639
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:37:31 -07:00
John Johansen
8cf3534a5b tests regression: fix failure on older versions of Make
Older versions of Make will choke on the # character in the $(shell
expression, treating it as the beginning of a comment. Resulting in
the following error

make unterminated call to function 'shell': missing ')'.  Stop.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/639
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:33:12 -07:00
John Johansen
709fd0e930 parser: Fix parser FTBS due to reallocarray
Older glibcs and alternate libcs don't have reallocarray()

So define it if not defined by libc.

Fixes: #3 of https://gitlab.com/apparmor/apparmor/-/issues/109
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/639
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:33:12 -07:00
John Johansen
bee9f94eab parser: fix bison error message output when built against bison 3.6+
bison change the default text past to yerror in bison 3.6, this
breaks make check as some tests are comparing against the error
output

======================================================================
FAIL: test_modefail (__main__.AAErrorTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jj/apparmor.git/parser/tst/testlib.py", line 50, in new_unittest_func
    return unittest_func(self)
  File "./errors.py", line 58, in test_modefail
    self._run_test(
  File "./errors.py", line 40, in _run_test
    self.assertIn(message, outerr, report)
AssertionError: 'AppArmor parser error for errors/modefail.sd in profile errors/modefail.sd at line 6: syntax error, unexpected TOK_ID, expecting TOK_MODE' not found in 'AppArmor parser error for errors/modefail.sd in profile errors/modefail.sd at line 6: syntax error\n' :
Command: ../apparmor_parser --config-file=./parser.conf -S -I errors errors/modefail.sd
Exit value:1
STDERR
AppArmor parser error for errors/modefail.sd in profile errors/modefail.sd at line 6: syntax error

To fix this we need to add

define parse.error=verbose

to bison. Unfortunately define parse.error was only added in bison 3.0
and and older versions of bison will break if that is defined in
parser_yacc.y

Instead test for the version of bison available and set define parse.error
as a build flag if supported by the version of bison being called.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/640
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:17:09 -07:00
John Johansen
882380ad3d parser: enable variable expansion for mount type= and options=
Currently mount options type= and options= do not expand variables
but they should. Fix it.

Note: this does not treat either as paths because their use is
too device dependent for it to be safe to filter slashes.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/638
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:11:37 -07:00
John Johansen
2e5a266eb7 regression tests: Don't build syscall_sysctl if missing kernel headers
sys/sysctl.h is not guaranteed to exist anymore since
https://sourceware.org/pipermail/glibc-cvs/2020q2/069366.html

which is a follow on to the kernel commit
61a47c1ad3a4 sysctl: Remove the sysctl system call

While the syscall_sysctl currently checks if the kernel supports
sysctrs before running the tests. The tests can't even build if the
kernel headers don't have the sysctl defines.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/119
Fixes: https://bugs.launchpad.net/apparmor/+bug/1897288
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/637
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-29 11:21:01 -07:00
John Johansen
0f1493d640 Merge parser: Fix expansion of variables in the profile rules
The parser is not handling variable expansion/rule conditionals
correctly in some cases. Eg. NOT treating unix addr as a path and
filtering slashes after variable expansion. This can lead to errors
where

@{foo}=/a/ unix bind addr=@{foo}/bar,

will always fail because addr is being matched as /a//bar instead of
/a/bar.

Note: this is a first pass and may not fix all cases. Eg. There is a
known issue with profile names not being able to begin with a
variable.

Signed-off-by: John Johansen john.johansen@canonical.com
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-29 04:46:32 -07:00
Steve Beattie
74df38e284 parser sanity tests: add more mount options tests
Attempt to get clarity on what is valid syntax for mount options and
fstype options.

Note that simple_tests/mount/bad_opt_27.sd is marked TODO, as the
parser accepts it but should not.

Also mark the tests as expecting to fail to raise an exception by the
python utils.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
8f382f5c6b parser: add unix peer addr slash filter equality tests
Test to ensure that slash filtering occurs properly in unix file
peer socket addr paths.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://bugs.launchpad.net/apparmor/+bug/1856738
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
51aedb2118 parser: add mount path slash filtering equality tests
Test to ensure that slash filtering occurs properly in mount path
components.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
80d7e33432 parser: add dbus path slash filtering equality tests
Test to ensure that slash filtering occurs properly in dbus path
components.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
9cee676558 parser: add unix addr slash filter equality tests
Test to ensure that slash filtering occurs properly in unix file socket
addr paths.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://bugs.launchpad.net/apparmor/+bug/1856738
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
John Johansen
a1978fb1b2 parser: call filter slashes for mount conditionals
The mnt_point and devices conditionals in mount rules are generally
paths and should have slashes filtered after variable expansion.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:14:35 -07:00
John Johansen
35f6d49ec6 parser: call filter slashes for the dbus path conditional
Similar to unix addr rules, the dbus path conditional is more a path
than a profile name and should get its slashes filtered after variable
expansion.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:14:35 -07:00
John Johansen
6af05006d9 parser: Fix expansion of variables in unix rules addr= conditional
The parser is not treating unix addr as a path and filtering slashes
after variable expansion. This can lead to errors where

@{foo}=/a/
unix bind addr=@{foo}/bar,

will always fail because addr is being matched as /a//bar instead of
/a/bar.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Fixes: https://bugs.launchpad.net/apparmor/+bug/1856738
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:14:35 -07:00
John Johansen
46c355345e Merge Add support for upstream v8 abi network mediation in the 4.17 kernel
This adds support for the new v8 network mediation in the 4.17 and later kernels.

It requires that policy either be tagged with an abi rule that support the v8 network, or the policy be pinned with --policy-features= with a feature abit that supports v8 network.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-29 10:44:46 +00:00
John Johansen
0a52cf81e3 parser: add support for autobind sockets
af_unix allows for sockets to be bound to a name that is autogenerated.
Currently this type of binding is only supported by a very generic
rule.

  unix (bind) type=dgram,

but this allows both sockets with specified names and anonymous
sockets. Extend unix rule syntax to support specifying just an
auto bind socket by specifying addr=auto

eg.

  unix (bind) addr=auto,

It is important to note that addr=auto only works for the bind
permission as once the socket is bound to an autogenerated address,
the addr with have a valid unique value that can be matched against
with a regular

  addr=@name

expression

Fixes: https://bugs.launchpad.net/apparmor/+bug/1867216
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 03:34:56 -07:00
John Johansen
c9d01a325d parser: don't apply exec mapping computations to the policydb
v8 network permissions extend into the range used by exec mapping
so it is important to not blindly do execmapping on both the
file dfa and policydb dfa any more.

Track what type of dfa and its permissions we are building so
we can properly apply exec mapping only when building the
file dfa.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 03:34:47 -07:00
John Johansen
e92478a9c5 parser: add support for kernel 4.17 v8 networking
Make it so the parser can properly support network socket mediation
in the upstream kernel,

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 03:33:55 -07:00
John Johansen
82cfc9ccc5 Merge Add dovecot-script-login profile
... and allow dovecot to Px to it.

The profile is based on a profile I received in a bugreport, with the actual script factored out. Note that you'll *need* to add a rule to the local/ include to allow executing the actual script, but since the script to execute is configurable, it's basically impossible to add a default rule for it.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1166007

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/635
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-27 23:56:45 +00:00
John Johansen
037bcecc0e Merge Avoid crash on exec without log events for target profile
If an exec gets denied in enforce mode, there are no log events for the target binary/profile. Therefore, trying to set the final_name for the target will crash with a KeyError.

Check for the existence of hashlog\[aamode\]\[target_profile\] in all exec options to prevent this crash.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/634
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-27 23:54:22 +00:00
John Johansen
11ef957274 binutils: Add tool to enable extraction of the kernel features abi
Add a basic tool for manipulating the apparmor features abi via
libapparmor. This serves as a basic tool and as an example of using
the library api.

Currently its function is limited to extracting the kernel feature
abi and loading a feature abi from a file and then outputing it.

In the future it will pickup the ability to verify the feature
abi, and merge feature abis.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/613
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-27 16:28:27 -07:00
Christian Boltz
6e59f454b1
Add dovecot-script-login profile
... and allow dovecot to Px to it.

The profile is based on a profile I received in a bugreport, with the
actual script factored out. Note that you'll _need_ to add a rule to the
local/ include to allow executing the actual script, but since the
script to execute is configurable, it's basically impossible to add a
default rule for it.

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1166007
2020-09-27 16:26:28 +02:00