Commit graph

4854 commits

Author SHA1 Message Date
John Johansen
6804731892 Policy cache fixes
Fix the `aa_policy_cache.sh` regression test to work correctly with the new(ish) multicache support in `libapparmor`. Then a couple subtle bugs that were uncovered by the fixed test.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/348
Acked-by: John Johansen <john.johansen@canoical.com>
2019-03-13 06:17:37 +00:00
Tyler Hicks
e28ffcdf7d libapparmor: Get rid of unnecessary variable
Remove the k variable since it really isn't necessary here.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:46:09 +00:00
Tyler Hicks
d7ac07afc4 libapparmor: Fix variable name overlap in merge() macro
The calling function and the merge() macro both make use of a variable
named "i" but this causes problems when merging. The aa_policy_cache.sh
test script experiences "bad file descriptor" failures due to the merged
list containing invalid fd values (-1).

Fix this by renaming merge()'s index variables from i and j to y and z
to hopefully prevent future overlap. The better fix here would be to
convert merge() to a function but that's a more intrusive change and I
don't have an easy way to test the overlay feature.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:46:00 +00:00
Tyler Hicks
8b21871820 libapparmor: Fix segfault when loading policy cache files
qsort()'s _size_ parameter is used to indicate the size of the elements
in the _base_ array parameter. Adjust the third argument to qsort() to
indicate that we're dealing with an array of struct dirent pointers
rather than an array of struct dirent.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:39:55 +00:00
Tyler Hicks
f31457b26e tests: Teach aa_policy_cache.sh about the cache location and subdirs
Adjust aa_policy_cache.sh to handle the additional layer in the
directory hierarchy when determining where the policy cache binaries are
stored. This is needed due to the multicache changes that allow multiple
policy caches to exist on a single system.

Differentiate between the cache location (the top level directory
containing all caches) and the cache directory (the directory used to
store the cached policies).

Use the libapparmor wrapper to get the cache directory for the given
cache location and the features of the currently running kernel.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:39:54 +00:00
Tyler Hicks
ad81ea0e67 tests: Add option to dump policy cache dir with the libapparmor wrapper
Print the policy cache directory path for the features of the currently
running kernel to stdout so that the aa_policy_cache.sh regression test
script can make use of it when writing out binary policy files.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2019-03-13 02:23:35 +00:00
John Johansen
abbca9435f library: fix segfault in overlaydirat_for_each
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Tyler Hicks <tyler.hicks@canonical.com>
2019-03-12 16:17:35 -07:00
John Johansen
2c4386a0d1 Merge branch 'xmatch_regex_priority' into 'master'
parser: determine xmatch priority based on smallest DFA match

The length of a xmatch is used to prioritize multiple profiles that
match the same path, with the intent that the more specific match wins.
Currently, the length of a xmatch is computed by the position of the
first regex character.

While trying to work around issues with no_new_privs by combining
profiles, we noticed that the xmatch length computation doesn't work as
expected for multiple regexs. Consider the following two profiles:

    profile all /** { }
    profile bins /{,usr/,usr/local/}bin/** { }

xmatch_len is currently computed as "1" for both profiles, even though
"bins" is clearly more specific.

When determining the length of a regex, compute the smallest possible
match and use that for xmatch priority instead of the position of the
first regex character.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/326
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-12 11:23:30 +00:00
John Johansen
a122764ddf dovecot: align {pop3,managesieve}-login to imap-login
Those 3 login daemons should have similiar needs and thus similar profiles. IMAP is likely the most tested one so let's align the other 2 with it. Unix and TCP sockets rules were added to pop3-login after the removal of abstractions/nameservice that included them implicitly.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/338
Signed-off-by: Simon Deziel [simon@sdeziel.info](mailto:simon@sdeziel.info)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-11 22:58:55 +00:00
John Johansen
6eea2bcd0d Merge branch 'desktop-abstractions' into 'master'
abstractions/qt5: read user configuration

See merge request apparmor/apparmor!335
2019-03-11 22:53:07 +00:00
Cameron Nemo
6d81563267 abstractions/qt5: read user configuration
Signed-off-by: Cameron Nemo <camerontnorman@gmail.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-11 15:50:45 -07:00
Christian Boltz
175a78c55a Merge branch 'profile-updates' into 'master'
profiles/gnome: add @{HOME}/.cache/gtk-3.0

Found this path is used by gtk_compose_hash_get_cache_path() in
gtkcomposetable.c.

See merge request apparmor/apparmor!342

Acked-by: Jamie Strandboge <jamie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-03-07 18:59:22 +00:00
Christian Boltz
62d6ae22b8 Merge branch 'cboltz-assert-equals' into 'master'
Replace deprecated assertEquals with assertEqual

assertEquals is deprecated since Python 2.7 and 3.2.

See merge request apparmor/apparmor!347

Acked-by: Eric Chiang <ericchiang@google.com>
2019-02-26 20:50:51 +00: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
intrigeri
2ed3763a2f Merge branch 'bug1816470' into 'master'
tunables/share: fix buggy syntax that broke the ~/.local/share part of the @{user_share_dirs} tunable

See merge request apparmor/apparmor!344
2019-02-25 06:49:23 +00:00
intrigeri
cdeb618518 tunables/share: fix buggy syntax that broke the ~/.local/share part of the @{user_share_dirs} tunable
Fixes regression introduced in a91d199ab1.

Bug: https://bugs.launchpad.net/apparmor/+bug/1816470
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=920833, https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=921888
2019-02-24 15:20:17 +00:00
John Johansen
14f177e53a parser: update indentation of work_spawn() macro
Update the indetation of work_spawn to correct for the changes made in
cb43e57d27 ("parser: Fix parser failing to handle errors when setting up work")

the indetation was not updated in that patch to make the changes made
easier to review and see in diffs.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-02-22 02:28:43 -08:00
John Johansen
1259319508 parser: Fix parser failing to handle errors when setting up work
The parser is not correctly handling some error conditions when
dealing with work units. Failure to spawn work, access files, etc
should be returned where appropriate, and be able to abort processing
if abort_on_error is set.

In addition some errors are leading to a direct exit without checking
for abort_on_error.

BugLink: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=921866
BugLink: http://bugs.launchpad.net/bugs/1815294

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Eric Chiang <ericchiang@google.com>
2019-02-22 02:28:30 -08:00
Jörg Sommer
6da7ed2a78 profiles/gnome: add @{HOME}/.cache/gtk-3.0
Found this path is used by gtk_compose_hash_get_cache_path() in
gtkcomposetable.c.
2019-02-20 00:35:06 +01:00
Simon Deziel
e3fd962e36 dovecot: restrict access by owner to the dovecot/config socket
Being able to read the config means accessing ssl_key data so
should only be restricted to root https://wiki.dovecot.org/Services#config

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-18 09:53:39 -05:00
Simon Deziel
bc36daa264 dovecot: align {pop3,managesieve}-login to imap-login
Those 3 login daemons should have similiar needs and thus similar
profiles. IMAP is likely the most tested one so let's align the
other 2 with it. Unix and TCP sockets rules were added to pop3-login
after the removal of abstractions/nameservice that included them
implicitly.

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-17 17:33:24 -05:00
Christian Boltz
5e5b02b722 Merge branch 'dovecot-ssl' into 'master'
dovecot: remove SSL access to {imap,managesieve,pop3}-login

See merge request apparmor/apparmor!337

Acked-by: Christian Boltz <apparmor@cboltz.de> (master only)
2019-02-17 21:07:44 +00:00
Christian Boltz
e68beb988a Merge branch 'dovecot-fixes-no-doveadm' into 'master'
misc dovecot fixes (take #2)

See merge request apparmor/apparmor!336

Acked-by: Christian Boltz <apparmor@cboltz.de> for master..2.10
2019-02-17 21:04:27 +00:00
Simon Deziel
f509fa1675 dovecot: add OpenSSL access to {imap,managesieve,pop3}-login
Based on feedback from Christian Boltz

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-17 15:55:32 -05:00
Simon Deziel
702411170d dovecot: remove SSL access to {imap,managesieve,pop3}-login
The certificates and keys are read by dovecot and
dovecot/config only.

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-17 15:43:58 -05:00
Cameron Nemo
1b57591175 abstractions/qt5: read user configuration 2019-02-17 00:07:45 -08:00
Simon Deziel
6a7c49b149 dovecot: add abstractions/ssl_certs to lmtp
It already has abstractions/ssl_keys

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-14 21:01:23 -05:00
Simon Deziel
17db8f3884 dovecot: auth processes need to read from postfix auth socket
They also need rw on the auth-userdb socket

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-13 22:50:14 -05:00
Simon Deziel
9afeb22548 dovecot: let dovecot/anvil rw the auth-penalty socket
Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-13 22:33:44 -05:00
Simon Deziel
d0aa863f6b dovecot: allow chroot'ing the auth processes
When using passdb/userdb not requiring root (!= /etc/shadow access)
it is recommended to run the auth processes as non root and chroot'ed

Signed-off-by: Simon Deziel <simon@sdeziel.info>
2019-02-13 22:27:08 -05: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
Steve Beattie
b4ab8476e4 usr merge fixups
Debian and Ubuntu have releases coming out with usr-merge in place. For these systems, /bin and /sbin are symlinks to their respective /usr directories. This breaks a few tests in the python utils and in the regression tests. This patch series fixes them, mostly by performing realpath() calls when necessary. For the ptrace regression test, it copies the called /bin/true binary into the created temporary directory and executes it from there. (Good for other reasons, too.)

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>

These patches should be safe to backport to the supported releases (but I have not attempted that, yet).

See merge request apparmor/apparmor!331
2019-02-13 16:57:52 +00:00
Steve Beattie
8c09b32828
ptrace regression tests: fix usr-merge failures
In a usr-merge ubuntu/debian environment /bin is a symlink to
/usr/bin, which causes invalid apparmor policy to be generated for
/bin/true. Instead, copy /bin/true to the per test temporary directory
and execute it from there.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-02-12 23:17:59 -08:00
Steve Beattie
eb31fcf9c5
regression tests: use realpath when generating inierpreter profile
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-02-12 23:17:59 -08:00
Steve Beattie
45c26214cc
utils: fixup test-aa.py tests that fail due to usr-merge
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2019-02-12 23:17:59 -08:00
Simon Deziel
a57f01d86b dovecot: allow FD passing between dovecot and dovecot's anvil 2019-02-10 21:36:10 -05:00
Christian Boltz
d6bc00b35b
add an example for setup_aa() to test-example.py
(commented out, but having it documented is helpful nevertheless)
2019-02-10 23:24:29 +01:00
Christian Boltz
f2c0a11327 Merge branch 'update-vulkan' into 'master'
vulkan: allow reading /etc/vulkan/icd.d/

See merge request apparmor/apparmor!329

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2019-02-10 13:40:53 +00:00
Vincas Dargis
e322c02c37 vulkan: allow reading /etc/vulkan/icd.d/
Recent Vulkan upgrades introduces new denies:

```
type=AVC msg=audit(1549749243.284:4250): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube" name="/etc/vulkan/icd.d/"
pid=16472 comm="vkcube" requested_mask="r" denied_mask="r" fsuid=1000
ouid=0
```

```
type=AVC msg=audit(1549800398.470:2612): apparmor="DENIED"
operation="open" profile="/usr/bin/vkcube"
name="/etc/vulkan/icd.d/test.j
son" pid=12230 comm="vkcube" requested_mask="r" denied_mask="r"
fsuid=1000 ouid=0
```

Update `vulkan` abstraction to allow reading new configuration directory.
2019-02-10 14:07:17 +02:00
Christian Boltz
a40dc49530 Merge branch 'feature/aa-notify-test' into 'master'
Add tests for aa-notify

See merge request apparmor/apparmor!324

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-02-09 20:15:22 +00:00
Otto Kekäläinen
aaf7d0a27a Skip aa-notify tests if their requirements for running are missing
When run locally on a development machine or in production, the full test
is likely to run. However inside a CI system container 'last' might fail
to show last login or there might not be access to kern.log and the test
will automatically skip those without failing the whole test suite.
2019-02-09 13:50:02 +02:00
Otto Kekäläinen
f05a464369 Add tests for aa-notify
This will help ensure the future rewrite of aa-notify from Perl to Python
is less likely to introduce regressions. Tests run the command line utility
via a subprocess so it does not matter that the tests are in Python but
the aa-notify utility is in Perl (for now).
2019-02-09 13:12:01 +02:00
Eric Chiang
cc09794fbd parser: determine xmatch priority based on smallest DFA match
The length of a xmatch is used to prioritize multiple profiles that
match the same path, with the intent that the more specific match wins.
Currently, the length of a xmatch is computed by the position of the
first regex character.

While trying to work around issues with no_new_privs by combining
profiles, we noticed that the xmatch length computation doesn't work as
expected for multiple regexs. Consider the following two profiles:

    profile all /** { }
    profile bins /{,usr/,usr/local/}bin/** { }

xmatch_len is currently computed as "1" for both profiles, even though
"bins" is clearly more specific.

When determining the length of a regex, compute the smallest possible
match and use that for xmatch priority instead of the position of the
first regex character.
2019-02-08 13:51:02 -08:00
Christian Boltz
3b4d1ed0e4 Merge branch 'feature/debuglogger-stdout' into 'master'
Extend common DebugLogger with option to log to stderr

See merge request apparmor/apparmor!325

Acked-by: Eric Chiang <ericchiang@google.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-02-07 18:26:19 +00:00
Otto Kekäläinen
c04a0cadef Extend common DebugLogger with option to log to stderr
This makes it possible for e.g. command line tools to have the --debug
option and when invoked print the existing debug messages directly to
stderr so the user running the command can see them.
2019-02-07 01:05:32 +02:00
Christian Boltz
365bb375d5 Merge branch 'fix-kdeglobals' into 'master'
kde: fix global settings access for Kubuntu and openSUSE

See merge request apparmor/apparmor!322

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.12..master
2019-02-05 17:23:05 +00:00
Vincas Dargis
0f30a59021 kde: fix global settings access for Kubuntu and openSUSE
On Kubuntu, these denies are being produced:
```
type=AVC msg=audit(1549301888.419:91): apparmor="DENIED" operation="open"
profile="qtox"
name="/usr/share/kubuntu-default-settings/kf5-settings/kdeglobals" pid=1603
comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

type=AVC msg=audit(1549301964.008:126): apparmor="DENIED" operation="open"
profile="qtox" name="/usr/share/kubuntu-default-settings/kf5-settings/breezerc"
pid=1822 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

type=AVC msg=audit(1549302031.194:155): apparmor="DENIED" operation="open"
profile="qtox"
name="/usr/share/kubuntu-default-settings/kf5-settings/baloofilerc" pid=1899
comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

Meanwhile, on openSUSE:
```
type=AVC msg=audit(1549302286.921:205): apparmor="DENIED" operation="open" profile="qtox" name="/etc/xdg/kdeglobals" pid=12781 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
```

Add read only rules for allowing access to global KDE settings.
2019-02-05 18:46:39 +02:00
Christian Boltz
a18d03767e Merge branch 'feature/aa-decode-with-python' into 'master'
Rewrite aa-decode to use inline Python as Perl is to be deprecated

See merge request apparmor/apparmor!321

Acked-by: Eric Chiang <ericchiang@google.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-02-05 12:17:07 +00:00
Otto Kekäläinen
707ef17923 Rewrite aa-decode to use inline Python instead of to-be-deprecated Perl 2019-02-05 00:20:47 +02:00
Otto Kekäläinen
a3ae271d1e Bugfix aa-decode test: Get stderr correctly, don't ignore stderr contents
Defining 'stderr = subprocess.STDOUT' as a default value for function
did not work and the 'stderr' was always empty, thus also 'outerr' was
always empty and not standard error contents was ever considered in any
way.

Best in fact was to remove excess function arguments as they were not even
used and replace it with a simpler and less error prone structure.

Even after reading 'stderr' correctly it did not help much as all tests
used 'assertIn' which ignored excess output. Better replace the normal
output with the error output if there ever was something, since stderr
is most likely a serious thing and tests should stop on it.
2019-02-05 00:15:13 +02:00