2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 01:57:43 +00:00

8286 Commits

Author SHA1 Message Date
Christian Boltz
a606397417 Merge Update utils/aa-notify to add running in the foreground and continue on "read_profiles" permission error
Hello!

I run AppArmor daily on my personal machine and use `aa-notify` to receive alerts for any audit events. I wanted to submit two features and one bugfix for problems that I've seen while running `aa-notify`.

### Here are the two features in this merge request:

1. Allow `aa-notify` to run in the foreground.
   I understand that `aa-notify` is ment to be run as a background notification daemon, however there are situations when running in the foreground would be better suited. One example is any startup "launcher" that creates and monitors it's child processes (my setup basically does this) and when `aa-notify` forks, the launcher percieves it as crashing on startup.
   This merge request adds an option "-F"/"--foreground" to prevent background forking and perserves the default behavior, while allowing `aa-notify` to run like a standard foreground application. The test cases in `utils/test/test-aa-notify.py` are also updated to reflect the argument changes.

2. Prevent `aa-notify` from exiting with a fatal error when the AppArmor profiles directory cannot be read.
   During startup, `aa-notify` will attempt to read the AppArmor profiles from the profile directory using the `aa.read_profiles` function. If this function fails due to a permissions check, `aa-notify` will exit with an error. In my setups, the standard user does not have any read access to the AppArmor profiles directory (reasoning: as an attacker, I could read the profiles to find something that would have the weakest permissions for explitation, but with that route blocked, this becomes significantly harder). In this merge request, an optional paramater `skip_perm_error` that is by-default False, is added to the `read_profiles` function call in `aa-notify`. In `aa.py`, this function has two added lines, which are under `except (OSError, TypeError):`. The extra code checks if `skip_perm_error` is True, and if so will print a warning out using the `aaui.UI_Info` function and returns cleanly. During my test cases, I have not run into any issues running `aa-notify` without reading any profiles.

### BugFixes

1. Crash during `aa-notify` polling during audit events that cause `rl.parse_record(event)` to return None
   I've noticed certain events will cause `aa-notify` to crash, specifically the ones in the attached log snipped will cause `ev` to be `None`.
   In this merge request, I've added a simple `if ev is None:` check before attempting to read from `ev`. If `ev` is None, it will fall into `continue` and prevent a crash from occuring. The crash log is also attached for additional information.

Please let me know if there's any additional questions or information you may need! And thank you for all your hard work on this project!

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1706
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-06-14 15:07:44 +00:00
iDigitalFlame
b4ab583520 Update utils/aa-notify to add running in the foreground and continue on "read_profiles" permission error 2025-06-14 15:07:44 +00:00
Georgia Garcia
0dfa2fb9f2 Merge Deduplicate example rules in apparmor.d manpage
foo.pid is also matched by foo.* (which has broader permissions)

Reported in https://gitlab.com/apparmor/apparmor/-/work_items/524#note_2555705082

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1715
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-12 15:54:20 -03:00
Georgia Garcia
af396a46ee profiles: add mount permissions to fusermount3 needed by flatpak-builder
There were failures in the flatpak-build autopkgtests due to missing
mount permissions:

[   60.822732] audit: type=1400 audit(1749737394.684:168): apparmor="DENIED" operation="mount" class="mount" info="failed mntpnt match" error=-13 profile="fusermount3" name="/var/tmp/test-flatpak-uuKcEE/.flatpak-builder/rofiles/rofiles-JxeDhQ/" pid=3150 comm="fusermount3" fstype="fuse.rofiles-fuse" srcname="rofiles-fuse" flags="rw, nosuid, nodev"
[   60.825556] audit: type=1400 audit(1749737394.686:169): apparmor="DENIED" operation="mount" class="mount" info="failed mntpnt match" error=-13 profile="fusermount3" name="/var/tmp/test-flatpak-uuKcEE/.flatpak-builder/rofiles/rofiles-JxeDhQ/" pid=3151 comm="fusermount3" fstype="fuse" srcname="/dev/fuse" flags="rw, nosuid, nodev"
[  918.564687] audit: type=1400 audit(1749738252.435:186): apparmor="DENIED" operation="umount" class="mount" profile="fusermount3" name="/var/tmp/test-flatpak-AI4MsP/.flatpak-builder/rofiles/rofiles-vIM7ok/" pid=7093 comm="fusermount"

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-12 15:08:07 -03:00
Georgia Garcia
9d2aca7945 profiles: add ix permissions for mount and umount on fusermount3 profile
After an upgrade to libfuse 3.17.1-rc0, autopkgtests started to fail
due to a missing x permission for /usr/bin/mount. After looking at the
source code for fusermount, I noticed that it does call /bin/mount and
/bin/umount in certain cases. These uses were already there in
previous versions of libfuse but I'm still not sure why it hasn't
triggered before.

To reproduce it:
sudo autopkgtest-buildvm-ubuntu-cloud -v -r questing
autopkgtest archivemount -U --apt-pocket=proposed=src:fuse3 --shell-fail -- qemu autopkgtest-questing-amd64.img

After the test fails, enter the vm by

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022 ubuntu@localhost

You can reproduce the test by running

cd /tmp/autopkgtest.*/build.*/src/
/tmp/autopkgtest.*/build.*/src/debian/tests/test

Note that ix for mount and umount were enough to make the autopkgtest
failures to start passing, but there could be issues in the future
regarding the use of fs specific mount binaries like
/usr/sbin/mount.fuse

Fixes: http://bugs.launchpad.net/bugs/2111845
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-12 14:23:32 -03:00
Maxime Bélair
d068678112 Merge initial john the ripper
@jjohansen had mentioned to me when he suggested this profile that there was smth he noticed about john that gave him the impression it was a good candidate for confinement. I think that would be the only thing I'd want to call out - wondering whether something like this captures that spirit or if there's something else worth including.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1662
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-06-12 05:56:26 +00:00
Christian Boltz
fbea9f00df
Deduplicate example rules in apparmor.d manpage
foo.pid is also matched by foo.* (which has broader permissions)

Reported in https://gitlab.com/apparmor/apparmor/-/work_items/524#note_2555705082
2025-06-11 14:34:20 +02:00
Eduardo Barretto
3d25f1c80f
profiles: mbsync: Allow mmap as it is needed for other architectures 2025-06-11 11:33:34 +02:00
Eduardo Barretto
a7003f4d49
profiles: mbsync: Use openssl abstraction instead 2025-06-11 11:33:30 +02:00
Eduardo Barretto
bb422c1f01
profile: mbsync: Move vim tag 2025-06-11 11:33:27 +02:00
Eduardo Barretto
76338c29f2
mbsync: Add read to gss
This was needed when testing the profile in Oracular
2025-06-11 11:33:23 +02:00
Eduardo Barretto
00a1152700
mbsync: Add missing write permission to create any folders existent 2025-06-11 11:33:20 +02:00
Eduardo Barretto
5f0fcfcae9
profiles: mbsync: make use of nameservice-strict abstraction
Signed-off-by: Eduardo Barretto <eduardo.barretto@canonical.com>
2025-06-11 11:33:16 +02:00
Eduardo Barretto
74ad177d07
Add profile for mbsync tool
Source package isync

Signed-off-by: Eduardo Barretto <eduardo.barretto@canonical.com>
2025-06-11 11:33:12 +02:00
Georgia Garcia
2d58858c27 Merge ci: add emulated USB devices for lsusb profile test
With this lsusb sees a non-empty emulated bus and the test is successful.

```
zyga@x13:~/apparmor$ spread garden:ubuntu-cloud-24.04:tests/profiles/lsusb
2025-06-10 08:01:13 Project content is packed for delivery (6.93MB).
2025-06-10 08:01:13 If killed, discard servers with: spread -reuse-pid=290633 -discard
2025-06-10 08:01:13 Allocating garden:ubuntu-cloud-24.04...
2025-06-10 08:03:25 Waiting for garden:ubuntu-cloud-24.04 to make SSH available at localhost:5000...
2025-06-10 08:03:25 Allocated garden:ubuntu-cloud-24.04.
2025-06-10 08:03:25 Connecting to garden:ubuntu-cloud-24.04...
2025-06-10 08:03:32 Connected to garden:ubuntu-cloud-24.04 at localhost:5000.
2025-06-10 08:03:32 Sending project content to garden:ubuntu-cloud-24.04...
2025-06-10 08:03:34 Preparing garden:ubuntu-cloud-24.04 (garden:ubuntu-cloud-24.04)...
2025-06-10 08:04:26 Preparing garden:ubuntu-cloud-24.04:tests/profiles/lsusb (garden:ubuntu-cloud-24.04)...
2025-06-10 08:04:26 Executing garden:ubuntu-cloud-24.04:tests/profiles/lsusb (garden:ubuntu-cloud-24.04) (1/1)...
2025-06-10 08:04:26 Restoring garden:ubuntu-cloud-24.04:tests/profiles/lsusb (garden:ubuntu-cloud-24.04)...
2025-06-10 08:04:26 Discarding garden:ubuntu-cloud-24.04...
2025-06-10 08:04:27 Successful tasks: 1
2025-06-10 08:04:27 Aborted tasks: 0
```

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1714
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-10 09:28:09 -03:00
Federico Quattrin
8cf0bda8d2 added '/usr/bin/free mr' in free profile 2025-06-10 09:26:02 -03:00
Zygmunt Krynicki
ddba3bb5b5 tests: match printed output from lsusb
This is a small improvement that makes sure lsusb is able to read some
properties of the virtual USB devices provisioned for the test.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2025-06-10 08:14:53 +02:00
Zygmunt Krynicki
d68dea45f1 ci: add emulated USB devices for lsusb profile test
With this lsusb sees a non-empty emulated bus and the test is successful.

```
zyga@x13:~/apparmor$ spread garden:ubuntu-cloud-24.04:tests/profiles/lsusb
2025-06-10 08:01:13 Project content is packed for delivery (6.93MB).
2025-06-10 08:01:13 If killed, discard servers with: spread -reuse-pid=290633 -discard
2025-06-10 08:01:13 Allocating garden:ubuntu-cloud-24.04...
2025-06-10 08:03:25 Waiting for garden:ubuntu-cloud-24.04 to make SSH available at localhost:5000...
2025-06-10 08:03:25 Allocated garden:ubuntu-cloud-24.04.
2025-06-10 08:03:25 Connecting to garden:ubuntu-cloud-24.04...
2025-06-10 08:03:32 Connected to garden:ubuntu-cloud-24.04 at localhost:5000.
2025-06-10 08:03:32 Sending project content to garden:ubuntu-cloud-24.04...
2025-06-10 08:03:34 Preparing garden:ubuntu-cloud-24.04 (garden:ubuntu-cloud-24.04)...
2025-06-10 08:04:26 Preparing garden:ubuntu-cloud-24.04:tests/profiles/lsusb (garden:ubuntu-cloud-24.04)...
2025-06-10 08:04:26 Executing garden:ubuntu-cloud-24.04:tests/profiles/lsusb (garden:ubuntu-cloud-24.04) (1/1)...
2025-06-10 08:04:26 Restoring garden:ubuntu-cloud-24.04:tests/profiles/lsusb (garden:ubuntu-cloud-24.04)...
2025-06-10 08:04:26 Discarding garden:ubuntu-cloud-24.04...
2025-06-10 08:04:27 Successful tasks: 1
2025-06-10 08:04:27 Aborted tasks: 0
```

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
2025-06-10 08:06:19 +02:00
Georgia Garcia
1f25a876ad Merge profiles: add additional rules needed for lsusb under sudo + other flags
Fixes: https://bugs.launchpad.net/ubuntu/+source/usbutils/+bug/2110212
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1713
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-09 17:37:45 -03:00
Ryan Lee
9f70004058 profiles: add additional rules needed for lsusb under sudo + other flags
Fixes: https://bugs.launchpad.net/ubuntu/+source/usbutils/+bug/2110212
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-06-09 12:56:36 -07:00
John Johansen
ac81cafa4f Merge added lsusb profile
AppArmor profile for the lsusb binary, developed and tested on Ubuntu 22.04. 

Signed-off-by: Federico Quattrin <federico.quattrin@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1433
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-06-09 18:33:26 +00:00
Federico Quattrin
bf207941ad update pci sys devices rules 2025-06-06 13:56:39 -07:00
Federico Quattrin
ec2c363125 added basic integration test 2025-06-06 13:56:39 -07:00
Federico Quattrin
61d5f1a56f removed abstractions/nameservice and added network netlink raw 2025-06-06 13:56:39 -07:00
Federico Quattrin
2634352a75 update lsusb profile name 2025-06-06 13:56:39 -07:00
Federico Quattrin
7af7fd35e5 include local lsusb profile if exists
Signed-off-by: Federico Quattrin <federico.quattrin@canonical.com>
2025-06-06 13:56:39 -07:00
Federico Quattrin
65f8bd4d82 added a few more rules for lsusb to cover verbose mode
Signed-off-by: Federico Quattrin <federico.quattrin@canonical.com>
2025-06-06 13:56:39 -07:00
Federico Quattrin
22023ce70b added lsusb profile
Signed-off-by: Federico Quattrin <federico.quattrin@canonical.com>
2025-06-06 13:56:39 -07:00
John Johansen
520227e4ea Merge Remove global declarations when variables are only read
... but don't get a new value assigned.

Found by pyflakes 3.3.2 / python 3.13.3

While on it, remove some obsolete, commented out debugging code.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1708
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-06-05 23:17:20 +00:00
John Johansen
f9c20e4786 Merge parser: set progname explicitly for tst_regex
Otherwise tst_regex would log as being from parser_common.c instead of
being from the actual source of parser_regex.c

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1707
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-06-05 23:14:48 +00:00
Georgia Garcia
9fceca5b88 Merge Fix parsing of mount options to honor full words
Parsing mount options (also) accepted partial matches as long as the
option started with the right characters. For example, 'options=syncfoo'
was parsed as 'sync'. This is also the reason why the list of mount
options was re-ordered so that 'r' and 'w' came last to give longer
options a chance to match (otherwise, 'rw' would be interpreted as 'r').

Fix parsing by adding a lookahead match so that the regex enforces that
the mount option is followed by whitespace, or is at the end of
rule_details.

Note that this issue only affected the options=foo syntax.
options=(foo) worked correctly even without this fix.


Now that this is fixed, move 'r' and 'w' back to their original position
in the list of mount options.

Also add a test where a mount rule ends with 'options=rw,' to ensure
that the '$' lookahead works.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1712
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-05 09:33:06 -03:00
Christian Boltz
ba5e007287
Fix parsing of mount options to honor full words
Parsing mount options (also) accepted partial matches as long as the
option started with the right characters. For example, 'options=syncfoo'
was parsed as 'sync'. This is also the reason why the list of mount
options was re-ordered so that 'r' and 'w' came last to give longer
options a chance to match (otherwise, 'rw' would be interpreted as 'r').

Fix parsing by adding a lookahead match so that the regex enforces that
the mount option is followed by whitespace, or is at the end of
rule_details.

Note that this issue only affected the options=foo syntax.
options=(foo) worked correctly even without this fix.

Now that this is fixed, move 'r' and 'w' back to their original position
in the list of mount options.

Also add a test where a mount rule ends with 'options=rw,' to ensure
that the '$' lookahead works.
2025-06-04 22:42:34 +02:00
Georgia Garcia
1009a66e0c Merge Improve error message for unknown mount options
Parsing `mount options=x` results in "Passed unknown options keyword to
MountRule: x", while parsing `mount options=xy` results in "Can't parse mount rule".

This difference happens because the code checks (besides the list of
known options) for a regex `([A-Za-z0-9])` which only matched a
single-character unknown option.

Change that regex to also match multiple characters, and also allow to
match `-` (used in some known mount options, so it's likely that it also
gets used in so far unknown mount options)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1710
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-06-04 17:28:14 -03:00
Christian Boltz
9a9f290099 Merge simplify mount_condition_pattern
The whole pattern already has `(...)*`, therefore there's no need to
make option_pattern optional.

Before this change, mount_condition_pattern could have matched
- on empty strings (it still can, thanks to the trailing `*` which can
  also mean "zero matches") or
- whitespace-only strings (which is covered by the two regexes using
  mount_condition_pattern - they both have `\s*` and/or `\s+` around it)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1709
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2025-06-04 19:35:58 +00:00
Christian Boltz
9a035cb0ee
Improve error message for unknown mount options
Parsing `mount options=x` results in "Passed unknown options keyword to
MountRule: x", while parsing `mount options=xy` results in "Can't parse mount rule".

This difference happens because the code checks (besides the list of
known options) for a regex `([A-Za-z0-9])` which only matched a
single-character unknown option.

Change that regex to also match multiple characters, and also allow to
match `-` (used in some known mount options, so it's likely that it also
gets used in so far unknown mount options)
2025-06-04 20:47:14 +02:00
Christian Boltz
d223751de0
simplify mount_condition_pattern
The whole pattern already has `(...)*`, therefore there's no need to
make option_pattern optional.

Before this change, mount_condition_pattern could have matched
- on empty strings (it still can, thanks to the trailing `*` which can
  also mean "zero matches") or
- whitespace-only strings (which is covered by the two regexes using
  mount_condition_pattern - they both have `\s*` and/or `\s+` around it)
2025-06-04 19:38:56 +02:00
Christian Boltz
2bfdcb780f
Remove global declarations when variables are only read
... but don't get a new value assigned.

Found by pyflakes 3.3.2 / python 3.13.3

While on it, remove some obsolete, commented out debugging code.
2025-06-04 19:29:16 +02:00
Ryan Lee
6e643a1dab parser: set progname explicitly for tst_regex
Otherwise tst_regex would log as being from parser_common.c instead of
being from the actual source of parser_regex.c

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-06-04 12:05:48 -04:00
Julia Sarris
3c6db7c14b Merge branch apparmor:master into master 2025-06-04 14:27:35 +00:00
John Johansen
23deb55149 Merge utils: add support for multiple options and fstypes in mount rules
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1693
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-06-03 23:43:40 +00:00
Maxime Bélair
e426cc983d Merge Allow lsblk to access Xen PVH disk devices
Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2111604

Signed-off-by: Christian Kujau <launchpad@nerdbynature.de>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1702
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Maxime Bélair <maxime.belair@canonical.com>
2025-06-03 14:53:55 +00:00
Julia Sarris
b019f9ef08 Merge branch apparmor:master into master 2025-06-03 14:18:41 +00:00
John Johansen
f8b5e5d9a4 Merge profiles: provide backwards compat for hwctl profile
The hwctl profile is being carried upstream, so we can keep it in
sync, but is being packaged from the regular profile set so that it
can be part of a package that is SRUed (ubuntu stable release update)
separate from the rest of apparmor, and its profiles.

Provide backwards compat with older parser to reduce the amount of
distro patching that is needed.

Signed-off-by: John Johansen <john.johansen@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1705
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2025-06-02 21:43:59 +00:00
Julia Sarris
d9d1776579 add owner back to rule lines 2025-06-02 16:29:57 -04:00
Julia Sarris
edf42d4f79 nameservice strict 2025-06-02 09:58:53 -04:00
Julia Sarris
f382920950 private files strict 2025-06-02 09:50:44 -04:00
Julia Sarris
3356f5ea0a Merge branch apparmor:master into master 2025-06-02 13:50:13 +00:00
John Johansen
e80ebea43f Merge Allow noexec mounts in fusermount3 profile
The permissive flags should be revisited once we have rule delegation

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1704
Approved-by: John Johansen <john@jjmx.net>
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2025-06-01 05:24:31 +00:00
John Johansen
df41185eb2 profiles: provide backwards compat for hwctl profile
The hwctl profile is being carried upstream, so we can keep it in
sync, but is being packaged from the regular profile set so that it
can be part of a package that is SRUed (ubuntu stable release update)
separate from the rest of apparmor, and its profiles.

Provide backwards compat with older parser to reduce the amount of
distro patching that is needed.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-05-30 13:24:17 -07:00
John Johansen
421558041b Merge Add additional mount regression tests for options= options in combo
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1703
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2025-05-30 18:26:10 +00:00