Commit graph

6348 commits

Author SHA1 Message Date
Steve Beattie
be61c5d22d libapparmor: fix a typo in grammar.y
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/938
Approved-by: Steve Beattie <steve@nxnw.org>
Merged-by: Steve Beattie <steve@nxnw.org>
2022-10-27 18:21:57 +00:00
Georgia Garcia
5cc7a26e78 libapparmor: add support for class in logparsing
We want to use the class field to identify operations such as
posix_mqueue

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 18:16:53 +00:00
Georgia Garcia
a05c9483f3 libapparmor: add support for requested and denied on logparsing
In order to decrease the number of characters in the audit logs
from the kernel, we will drop the "_mask" from the fields
"requested_mask" and "denied_mask".

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 18:16:53 +00:00
Georgia Garcia
19e7016068 Merge add support for user namespace creation
the only supported mode for the moment is `create`, so the following rules have the same effect
```
userns,
userns create,
```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/927
Approved-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 18:16:11 +00:00
Christian Boltz
5f36521e9f
Fix a typo in libapparmor grammar.y 2022-10-27 20:08:07 +02:00
Georgia Garcia
ef54144357 parser tests: add userns simple tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 17:54:42 +00:00
Georgia Garcia
f400b41c4a parser: add support for user namespace creation
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-10-27 17:54:42 +00:00
Christian Boltz
6920daea49
samba-rpcd-spoolss: allow mkdir /var/cache/samba/printing/
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1993572
2022-10-27 18:32:46 +02:00
Christian Boltz
18d1b06b0c Merge abstactions/kde: update for kwinrc, kdedefaults/* files
GUI applications such as KDE dragon player, qTox, LibreOffice tries to
access .config/kwinrc, .config/kdedefaults/kwinrc and
.config/kdedefaults/kdeglobals.

Update abstractions/kde to fix denials for applications running under
KDE.

Some examples:
```
type=AVC msg=audit(1666458796.112:5561): apparmor="DENIED" operation="open" profile="libreoffice-soffice" name="/home/vincas/.config/kdedefaults/kdeglobals" pid=43868 comm="soffice.bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666458796.204:5683): apparmor="DENIED" operation="open" profile="libreoffice-soffice" name="/home/vincas/.config/kdedefaults/kwinrc" pid=43868 comm="soffice.bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"

```
```
type=AVC msg=audit(1666462415.255:3640): apparmor="DENIED" operation="open" profile="kde-dragon-player" name="/home/vincas/.config/kdedefaults/kdeglobals" pid=8344 comm="dragon" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666462415.343:3641): apparmor="DENIED" operation="open" profile="kde-dragon-player" name="/home/vincas/.config/kdedefaults/kwinrc" pid=8344 comm="dragon" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
```

```
type=AVC msg=audit(1666459466.968:5852): apparmor="DENIED" operation="open" profile="qtox" name="/home/vincas/.config/kdedefaults/kdeglobals" pid=44561 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666459467.076:6057): apparmor="DENIED" operation="open" profile="qtox" name="/home/vincas/.config/kdedefaults/kwinrc" pid=44561 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"
type=AVC msg=audit(1666459467.076:6058): apparmor="DENIED" operation="open" profile="qtox" name="/home/vincas/.config/kwinrc" pid=44561 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000FSUID="vincas" OUID="vincas"

```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/936
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-10-22 19:28:25 +00:00
Vincas Dargis
d9dc0b61e3 abstactions/kde: update for kwinrc, kdedefaults/* files
GUI applications such as KDE dragon player, qTox, LibreOffice tries to
access .config/kwinrc, .config/kdedefaults/kwinrc and
.config/kdedefaults/kdeglobals.

Update abstractions/kde to fix denials for applications running under
KDE.
2022-10-22 21:58:17 +03:00
Alistair Young
5232eaa2d5 Adds /mnt/wsl/resolv.conf to nameservices. 2022-10-21 16:33:46 +00:00
Christian Boltz
fed907431e
syslog-ng: allow reading *.journal in flatter directory structure
On openSUSE Leap 15.4 (and probably also 15.3), the journal lives in
/var/log/journal/*.journal - without an additional subdirectory level.
2022-10-09 21:02:17 +02:00
Christian Boltz
05d7bdd655 Merge parser: fix DISTRO variable in Makefile
A single '$()' results in variable expansion, which makes
"$(rpm --eval ..)" always an empty string.

Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/928
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-10-07 19:44:55 +00:00
Spyros Seimenis
75a6679be5 tests/regression: Add simple e2e test
This adds a single e2e test to check that raw_data of a loaded
policy matches the generated policy (cached).

Signed-off-by: Spyros Seimenis <spyros.seimenis@canonical.com>
2022-10-05 20:39:37 +03:00
Alexey Kodanev
1df547ee8f parser: fix DISTRO variable in Makefile
A single '$()' results in variable expansion, which makes
"$(rpm --eval ..)" always an empty string.

Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
2022-09-30 14:22:27 +03:00
John Johansen
e1cc90f3a2 Merge profiles/apparmor.d: Update samba profile
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1990692
Signed-off-by: Spyros Seimenis <spyros.seimenis@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/926
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-09-30 09:59:14 +00:00
Spyros Seimenis
96aff5a5c5 profiles/apparmor.d: Update samba profile
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1990692
Signed-off-by: Spyros Seimenis <spyros.seimenis@canonical.com>
2022-09-29 16:02:20 +03:00
Christian Boltz
c038682745 Merge Simplify combine profname
Closes #275.

Closes #275
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/921
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-09-12 19:12:47 +00:00
Mark Grassi
084e35e3be Change apparmor.common.combine_profname arguments from list to tuple literals. 2022-09-11 21:56:26 -04:00
Mark Grassi
179ac34113 Simplify apparmor.common.combine_profname 2022-09-11 21:55:40 -04:00
Mark Grassi
5dc10264d2 Fix error in AppArmorBug exception text 2022-09-11 21:51:42 -04:00
Christian Boltz
7f6ffd33b2 Merge Rename BaseRule parse() and _parse() methods
As discussed in !920, this MR renames BaseRule's `parse()` and `_parse()` methods to `create_instance()` and `_create_instance()`, respectively. It then removes the `selection_to_rule_obj` function from `apparmor.aa`, which is now an unnecessary alias for the renamed public method.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/923
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-09-11 09:18:18 +00:00
Christian Boltz
46e51abbb3 Merge Remove if True: conditionals
Closes #274.

Closes #274
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/922
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-09-11 09:04:56 +00:00
Mark Grassi
86ae50b79e Remove selection_to_rule_obj() function from apparmor.aa 2022-09-10 20:50:22 -04:00
Mark Grassi
c7d1d5ea93 Rename BaseRule's _parse() method to _create_instance() 2022-09-10 19:54:35 -04:00
Mark Grassi
accc2debe9 Rename BaseRule's parse() method to create_instance() 2022-09-10 19:54:35 -04:00
Mark Grassi
170d7db186 Remove if True: conditionals 2022-09-10 18:11:01 -04:00
Christian Boltz
8c2a05469f Merge Change direct type comparisons to isinstance() calls where applicable.
This MR addresses #269.

Notes:
- In all `is_equal_localvars()` Rule methods, `type(self)` is now used instead of the explicit class. This approach works better with inheritance, and was already used in `IncludeRule` for this reason. 
- Remaining direct type comparisons were changed to use `is`/`is not` instead of `==`/`!=`.
- I fixed two typos in `alias.py`; the plural of alias is aliases, not aliass.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/920
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-09-10 22:01:14 +00:00
Mark Grassi
9725e66981 Change direct type comparisons to isinstance() calls where applicable. 2022-09-10 22:01:13 +00:00
Christian Boltz
f5594fbb7c Merge Prevent crash on log entries for non-existing profile
If audit.log contains entries for a profile that doesn't exist (for
example when working with a log file from another system), skip these
log entries instead of crashing.

Reproducer (crashes without this patch):

    aa-logprof -f <(echo 'type=AVC msg=audit(1661739121.578:77893): apparmor="DENIED" operation="open" profile="no_such_profile" name="/run/" pid=33099 comm="no" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0')

I propose this patch for 3.1 and master. (3.0 and older are not affected and do not need this fix.)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/919
Approved-by: Jon Tourville <jon.tourville@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-29 19:56:01 +00:00
Christian Boltz
94c7c79c8b
Prevent crash on log entries for non-existing profile
If audit.log contains entries for a profile that doesn't exist (for
example when working with a log file from another system), skip these
log entries instead of crashing.

Reproducer (crashes without this patch):

    aa-logprof -f <(echo 'type=AVC msg=audit(1661739121.578:77893): apparmor="DENIED" operation="open" profile="no_such_profile" name="/run/" pid=33099 comm="no" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0')
2022-08-29 14:36:18 +02:00
Christian Boltz
447199029e Merge Replace exit() with sys.exit().
Addresses #270. The `mk_features_file.py` changes are just for clarity, as shadowing built-ins confuses readers.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/918
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-29 11:46:39 +00:00
Mark Grassi
380bed3c9b Replace exit() with sys.exit(). 2022-08-28 22:40:28 -04:00
Christian Boltz
ace8e04477
Allow reading /sys/devices/system/cpu/possible
... in the dnsmasq//libvirt_leaseshelper profile

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1202849
2022-08-28 12:32:17 +02:00
Christian Boltz
4dcab85ce6 Merge Narrow broad except statements.
As discussed in #241 and !906, there are some overly broad `except` statements that should be fixed. This MR does so. Some notes:
- `profile_dir` in `aa.py` may be `None`, hence the `TypeError` catches. The other globals are not caught in the code, however. E.g. there are possibilities of TypeErrors due to `extra_profile_dir` being `None`.
- I added a TODO in `common.py` that I'd like some eyes on. I do not think that `os.path.normpath` can raise an exception (the [Python docs](https://docs.python.org/3/library/os.path.html?#os.path.normpath) don't mention exceptions, and none are raised in the [CPython source code](https://github.com/python/cpython/blob/main/Lib/posixpath.py#L345)). [After discussing this in the MR, the `os.path.normpath` check was removed.]
- The `except Exception: raise` occurrences throughout `test-aa-easyprof.py` do nothing, so I removed them.
- In `valgrind_simple.py`, I fixed a possible `NameError` in the `finally` clause.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/912
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-27 17:58:52 +00:00
Mark Grassi
e754e8aed7 Narrow broad except statements. 2022-08-27 17:58:51 +00:00
Christian Boltz
4e6ff1ad17
Hardcode and check the expected libapparmor.so name/number
... to prevent wrong/unexpected numbering (like
https://gitlab.com/apparmor/apparmor/-/issues/266) in future releases.
2022-08-26 21:43:17 +02:00
Christian Boltz
d024100efe Merge profiles: permit php-fpm pid files directly under run/
The upstream php-fpm.conf file carries the following pid file example
path:
  [global]
  ; Pid file
  ; Note: the default prefix is @EXPANDED_LOCALSTATEDIR@
  ; Default Value: none
  ;pid = run/php-fpm.pid

Add this path to profiles/apparmor.d/php-fpm, alongside the current
nested "@{run}/php{,-fpm}/php*-fpm.pid" wildcard.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/267

Suggested-by: Ali Abdallah <ali.abdallah@suse.com>
Signed-off-by: David Disseldorp <ddiss@suse.de>

Closes #267
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/914
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-26 10:35:49 +00:00
David Disseldorp
d8533ec851 profiles: permit php-fpm pid files directly under run/
The upstream php-fpm.conf file carries the following pid file example
path:
  [global]
  ; Pid file
  ; Note: the default prefix is @EXPANDED_LOCALSTATEDIR@
  ; Default Value: none
  ;pid = run/php-fpm.pid

Add this path to profiles/apparmor.d/php-fpm, alongside the current
nested "@{run}/php{,-fpm}/php*-fpm.pid" wildcard.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/267

Suggested-by: Ali Abdallah <ali.abdallah@suse.com>
Signed-off-by: David Disseldorp <ddiss@suse.de>
2022-08-26 00:04:36 +02:00
Georgia Garcia
8e8aad4eae Merge [3.1] libapparmor: fix mistaken SO version bump
In commit 7c7224004 ("Prepare for AppArmor 3.1 release"), as preperation
for the AppArmor 3.1.0 release, the SO versioning information was
adjusted, using a more significant bump to give prior AppArmor releases
room to address bugs in libapparmor without ending up with conflicting
SO versions. Unfortunately, that process was untested and because
AA_LIB_AGE was not incremented by the same amount as AA_LIB_CURRENT,
this resulted in an accidental major SO versions bump with the library
SO version being:

  libapparmor.so.4.9.0

This commit increments AA_LIB_AGE by the same amount, resulting in a
library versioned as:

  libapparmor.so.1.12.0

and adds a note to mention that AA_LIB_AGE needs to be incremented
in the same way as AA_LIB_CURRENT. This fix is intended to address
this for the 3.1 branch; I'd like to find a better approach for
the development branch that can be used in future AppArmor primary
releases.

In general, thanks to symbol versioning (see
`libraries/libapparmor/src/libapparmor.map`) we should not need to
ever bump the SO version except in an extreme case.

Fixes: 7c7224004 ("Prepare for AppArmor 3.1 release")
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://gitlab.com/apparmor/apparmor/-/issues/266

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/913
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>


(cherry picked from commit 075c69a4eb)

f9dbaa38 [3.1] libapparmor: fix mistaken SO version bump
2022-08-25 20:10:43 +00:00
John Johansen
7c7224004c Prepare for AppArmor 3.1 release
- update version file
- update library version

Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-08-23 13:39:18 -07:00
John Johansen
db246ddbb5 parser: begin deprecation process for #include
by adding a warning flag that is disabled by default. This will enable
devs to find when and where #include is in use by adding the compile
flag

  --warn=pound-include

and can even abort policy compiles by using

  --warn=pound-include --Werror=pound-include

The resulting messages look like

  Warning from /etc/apparmor.d/usr.sbin.cupsd (/etc/apparmor.d/usr.sbin.cupsd line 5): deprecated use of '#include'

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Time-out
2022-08-22 15:03:26 -07:00
John Johansen
a382452a54 libapparmor: update rules around the library version
This change tries to give us some room to deal with versioning issues
like we had in

  145136f6 Fix 2.13 libapparmor so version

which revered the library version bump in
  5c47e448 libapparmor: Bump revision in preparation for release.

which was done because of the symbol added by
  351014c3 libapparmor: add _aa_asprintf to private symbols

unfortunately this collided with the 3.0 library symbol versioning
which had a different set of symbols with the same version numbering.
Leaving us no way to increase the version number to when fixing an
exported symbol version in a released library.

Ideally this would have been fixed with library version synchs but
in this case that option wasn't open as we were dealing with two
released versions of the library.

Bumping the current version by 5 on the larger releases gives us room
to deal with these kind of bugs in the future.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Time-out
2022-08-22 14:52:37 -07:00
John Johansen
f51049ea2e Merge dnsmasq: Add missing r permissions for libvirt_leaseshelper
Note: This was reported for /usr/libexec/libvirt_leaseshelper, but since
this is probably unrelated to the path or a path change, this commit
also adds r permissions for the previous path.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1202161

I propose this patch for 3.0 and master (optionally also for 2.12 and 2.13 - please tell me if you want that after reviewing the patch, or just merge ;-)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/905
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-08-22 21:44:12 +00:00
Christian Boltz
406b6398af Merge dnsmasq: allow paths for podman dnsname plugin in rootless mode
In rootless mode, files needed to access are under /run/user/, so those needs to be defined separately.

similar change than https://gitlab.com/apparmor/apparmor/-/merge_requests/800 but adds permissions for rootless mode.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/909
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-22 11:57:21 +00:00
Christian Boltz
bcffe7c92c Merge Address Style Guide Infractions
This MR addresses much of #241. Each commit handles a different aspect of the style guide. All commits are style-only. Lacking from this MR are changes that would alter behavior and/or break backward-compatibility.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/906
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2022-08-22 10:47:33 +00:00
IIkka Ollakka
86069dd934 dnsmasq: allow paths for podman dnsname plugin in rootless mode
In rootless mode, files needed to access are under /run/user/, so those needs to be defined separately.
2022-08-22 13:20:40 +03:00
Mark Grassi
2f9068e37c Remove duplicate regex "or" comments. 2022-08-21 11:15:07 -04:00
Mark Grassi
46a2be31a7 Remove outdated/incorrect comment. 2022-08-21 11:15:07 -04:00
Mark Grassi
e8b60e46fe Improve regex formatting. 2022-08-21 11:15:07 -04:00