Commit graph

6540 commits

Author SHA1 Message Date
John Johansen
d788af0891 Merge aa-load
aa-load is a tool that loads cached (compiled) policies into
the kernel. It can receive as argument a file, a cache directory
containing the hash subtree, and a directory containing cached
files directly underneath - no hash.

This tool can be used in the as a guide for other init
systems to load the cached policies directly.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/770
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-29 21:24:25 +00:00
John Johansen
a7dc938188 Merge Fix "use-after-free" of 'tmp' in procattr_open()
This Fixes coverity CID 254463:  Memory - illegal accesses  (USE_AFTER_FREE)
which was introduced in 35e58273 / https://gitlab.com/apparmor/apparmor/-/merge_requests/713 (merged)

The coverity report it self is wrong because while the pointer use is
after free. It is deliberately a pointer comparison to see if the
value was pointing to proc_attr_base_old. This is not actually
problematic as far as it goes. However it does surface a bug in the
logic, and regardless if it is allowed doing a post-free pointer
comparison like this will confuse static checkers and humans alike.

procattr_path() will never return proc_attr_base_old, it will return a
copy of it (if it did return it, we couldn't free it). So the test tmp
!= proc_attr_base_old is bad, in that it will always be true even if
tmp was a copy of proc_attr_base_old.

Fix this by makint tmp auto free, and switching to a string comparison.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1042
Aked-by: time-out
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-29 21:23:27 +00:00
John Johansen
1ff74fed4b Merge abstactions/kde: allow reading global Debian KDE settings
New denials detected on Debian Sid:

```
type=AVC msg=audit(1687372581.246:738): apparmor="DENIED" operation="open" class="file" profile="qtox" name="/usr/share/desktop-base/kf5-settings/kdeglobals" pid=17988 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0FSUID="vincas" OUID="root"
```

Debian package `desktop-base` contains some global KDE settings files:

```
$ dpkg -L desktop-base | fgrep kf5
/usr/share/desktop-base/kf5-settings
/usr/share/desktop-base/kf5-settings/baloofilerc
/usr/share/desktop-base/kf5-settings/kdeglobals
/usr/share/desktop-base/kf5-settings/kscreenlockerrc
```

Add file rules to allow reading global KDE settings.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1056
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-29 21:21:32 +00:00
Vincas Dargis
155be0ffc4 abstactions/kde: allow reading global Debian KDE settings
New denials detected on Debian Sid:

```
type=AVC msg=audit(1687372581.246:738): apparmor="DENIED" operation="open" class="file" profile="qtox" name="/usr/share/desktop-base/kf5-settings/kdeglobals" pid=17988 comm="qtox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0FSUID="vincas" OUID="root"
```

Debian package `desktop-base` contains some global KDE settings files:

```
$ dpkg -L desktop-base | fgrep kf5
/usr/share/desktop-base/kf5-settings
/usr/share/desktop-base/kf5-settings/baloofilerc
/usr/share/desktop-base/kf5-settings/kdeglobals
/usr/share/desktop-base/kf5-settings/kscreenlockerrc
```

Add file rules to allow reading global KDE settings.
2023-06-26 20:09:55 +03:00
John Johansen
d4b0fef10a parser: fix rule flag generation change_mount type rules
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048
made it so rules like

  mount slave /snap/bin/** -> /**,

  mount /snap/bin/** -> /**,

would get passed into change_mount_type rule generation when they
shouldn't have been. This would result in two different errors.

1. If kernel mount flags were present on the rule. The error would
   be caught causing an error to be returned, causing profile compilation
   to fail.

2. If the rule did not contain explicit flags then rule would generate
   change_mount_type permissions based on souly the mount point. And
   the implied set of flags. However this is incorrect as it should
   not generate change_mount permissions for this type of rule. Not
   only does it ignore the source/device type condition but it
   generates permissions that were never intended.

   When used in combination with a deny prefix this overly broad
   rule can result in almost all mount rules being denied, as the
   denial takes priority over the allow mount rules.

Fixes: https://bugs.launchpad.net/apparmor/+bug/2023814
Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1211989
Fixes: 9d3f8c6cc ("parser: fix parsing of source as mount point for propagation type flags")
Fixes: MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1054

Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit 86d193e183)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-21 01:18:14 -07:00
John Johansen
b0354ef714 Merge detailed_processes(): initialize ret
... to avoid returning it uninitialized.

Found by coverity: CID 320935:  Uninitialized variables  (UNINIT)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1053
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-13 23:31:16 +00:00
John Johansen
b192da49c2 Fix "use-after-free" of 'tmp' in procattr_open()
This Fixes coverity CID 254463:  Memory - illegal accesses  (USE_AFTER_FREE)
which was introduced in 35e58273 / https://gitlab.com/apparmor/apparmor/-/merge_requests/713 (merged)

The coverity report it self is wrong because while the pointer use is
after free. It is deliberately a pointer comparison to see if the
value was pointing to proc_attr_base_old. This is not actually
problematic as far as it goes. However it does surface a bug in the
logic, and regardless if it is allowed doing a post-free pointer
comparison like this will confuse static checkers and humans alike.

procattr_path() will never return proc_attr_base_old, it will return a
copy of it (if it did return it, we couldn't free it). So the test tmp
!= proc_attr_base_old is bad, in that it will always be true even if
tmp was a copy of proc_attr_base_old.

Fix this by makint tmp auto free, and switching to a string comparison.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-13 16:25:44 -07:00
Christian Boltz
8bf58a79b1
detailed_processes(): initialize ret
... to avoid returning it uninitialized.

Found by coverity: CID 320935:  Uninitialized variables  (UNINIT)
2023-06-13 22:11:21 +02:00
Christian Boltz
b6be7b6204 Merge Enable coverity scans for master
... so that each change in master gets scanned (until we reach the scan
limit).

This will give us more timely results than only scanning the coverity
branch whenever someone manually updates it.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1052
Approved-by: John Johansen <john@jjmx.net>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-06-13 18:46:13 +00:00
Christian Boltz
34a46bd8f2
Enable coverity scans for master
... so that each change in master gets scanned (until we reach the scan
limit).

This will give us more timely results than only scanning the coverity
branch whenever someone manually updates it.
2023-06-13 20:35:07 +02:00
Christian Boltz
a4575a688c Merge usr.sbin.sshd: Add permissions masked by internal-sftp section
I have been testing the `usr.sbin.sshd` profile with the [three "for internal-sftp" rules](ad3750058d/profiles/apparmor/profiles/extras/usr.sbin.sshd (L138-140)) commented out, as they are quite broad. This has turned up a few oversights, a couple of which have been fixed in abstractions. This MR brings in the missing rules that don't currently seem to have a better place to go, and addresses a couple of other minor issues in the profile.

Here are the associated syslog messages:
```
Jun  8 21:09:11 testvm kernel: [   28.211637] audit: type=1400 audit(1686272951.369:66): apparmor="DENIED" operation="sendmsg" profile="/usr/sbin/sshd" name="/run/systemd/notify" pid=830 comm="sshd" requested_mask="w" denied_mask="w" fsuid=0 ouid=0
Jun  9 00:27:24 testvm kernel: [10846.886139] audit: type=1400 audit(1686284844.516:1268): apparmor="DENIED" operation="mkdir" profile="/usr/sbin/sshd" name="/home/username/.cache/" pid=5815 comm="sshd" requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000
Jun  9 00:28:57 testvm kernel: [10940.152625] audit: type=1400 audit(1686284937.780:1337): apparmor="DENIED" operation="mknod" profile="/usr/sbin/sshd" name="/home/username/.cache/motd.legal-displayed" pid=5979 comm="sshd" requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000
```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1051
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-06-11 14:27:13 +00:00
Daniel Richard G
15112b3a49 usr.sbin.sshd: Add permissions masked by internal-sftp section
Also replace /(var/)run with @{run} and /sys with @{sys}, and fix a
typo (etc.legal)
2023-06-10 16:49:24 -04:00
John Johansen
ad3750058d Merge abstractions/base: Add transparent hugepage support
Found in testing a slimmed-down `usr.sbin.sshd` profile:
```
Jun  8 21:09:38 testvm kernel: [   54.847014] audit: type=1400 audit(1686272978.009:68): apparmor="DENIED" operation="open" profile="/usr/sbin/sshd" name="/sys/kernel/mm/transparent_hugepage/hpage_pmd_size" pid=1035 comm="sshd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
```
Not sure what glibc/system call uses this, but it seems pretty broadly applicable, and read access is presumably harmless. [THP reference](https://www.kernel.org/doc/html/latest/admin-guide/mm/transhuge.html)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1050
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-09 08:46:31 +00:00
John Johansen
b41fcdce16 Merge abstractions/authentication: Add GSSAPI mechanism modules config
Found in testing a slimmed-down `usr.sbin.sshd` profile:
```
Jun  8 21:09:37 testvm kernel: [   54.770501] audit: type=1400 audit(1686272977.933:67): apparmor="DENIED" operation="open" profile="/usr/sbin/sshd" name="/etc/gss/mech.d/" pid=1036 comm="sshd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
```
([Reference](https://web.mit.edu/kerberos/krb5-1.21/doc/admin/host_config.html#gssapi-mechanism-modules) for  GSSAPI mechanism modules)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1049
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-09 08:45:20 +00:00
Daniel Richard G
3844e45220 abstractions/base: Add transparent hugepage support 2023-06-09 01:14:13 -04:00
Daniel Richard G
4b9ba3977b abstractions/authentication: Add GSSAPI mechanism modules config 2023-06-09 00:47:32 -04:00
John Johansen
6e0d776f65 Merge profiles: allow reading of /etc/ld-musl-*.path
/etc/ld-musl-*.path is required to perform dynamic linking on musl libc.
The wildcard is to match all CPU architectures, like x86_64.

type=AVC msg=audit(1686087677.497:67): apparmor="DENIED" operation="open" class="file" profile="syslog-ng" name="/etc/ld-musl-x86_64.path" pid=25866 comm="syslog-ng" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Closes #333

Signed-off-by: Nikita Romaniuk <kelvium@yahoo.com>

Closes #333
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1047
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-09 01:59:53 +00:00
John Johansen
8ef7e91a38 Merge Improvements from the Ubuntu 20.04 Firefox profile
This brings in numerous improvements from the Firefox AppArmor profile that Ubuntu ships in 20.04/focal. The raw profile may be viewed [here](https://bazaar.launchpad.net/~mozillateam/firefox/firefox-trunk.head/view/head:/debian/usr.bin.firefox.apparmor.14.10) (or alternately [here](https://bazaar.launchpad.net/~mozillateam/firefox/firefox.focal/view/head:/debian/usr.bin.firefox.apparmor.14.10)).

To review, you may not only want to compare this new version against HEAD, but also against the Ubuntu profile, which has a smaller diff. I suggest preprocessing the latter with the following to reduce extraneous diffs:
```
sed 's,@{PROC}/\[0-9\]\*/,@{PROC}/@{pid}/,g; s,/@{pid}/task/\[0-9\]\*/,/@{pid}/task/@{tid}/,g; s/#\(include\)/\1/'
```

I've made a few minor edits along the way, such as using AppArmor variables instead of preprocessing directives (like `@MOZ_LIBDIR@`) that are substituted in the Firefox package build. Any feature/stylistic downgrades in the Ubuntu profile should have been filtered out.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1043
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-09 01:57:25 +00:00
John Johansen
1e0d7bcbb7 Merge parser: fix parsing of source as mount point for propagation type flags
Before 300889c3a, mount rules would compile policy when using source
as mount point for rules that contain propagation type flags, such as
unbindable, runbindable, private, rprivate, slave, rslave, shared, and
rshared. Even though it compiled, the rule generated would not work as
expected.

This commit fixes both issues. It allows the usage of source as mount
point for the specified flags, albeit with a deprecation warning, and
it correctly generates the mount rule.

The policy fails to load when both source and mount point are
specified, keeping the original behavior (reference
parser/tst/simple_tests/mount/bad_opt_10.sd for example).

Fixes: https://bugs.launchpad.net/bugs/1648245
Fixes: https://bugs.launchpad.net/bugs/2023025

It should be backported to versions 2.13, 3.0, 3.1.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-09 01:52:40 +00:00
Georgia Garcia
9d3f8c6cc0 parser: fix parsing of source as mount point for propagation type flags
Before 300889c3a, mount rules would compile policy when using source
as mount point for rules that contain propagation type flags, such as
unbindable, runbindable, private, rprivate, slave, rslave, shared, and
rshared. Even though it compiled, the rule generated would not work as
expected.

This commit fixes both issues. It allows the usage of source as mount
point for the specified flags, albeit with a deprecation warning, and
it correctly generates the mount rule.

The policy fails to load when both source and mount point are
specified, keeping the original behavior (reference
parser/tst/simple_tests/mount/bad_opt_10.sd for example).

Fixes: https://bugs.launchpad.net/bugs/1648245
Fixes: https://bugs.launchpad.net/bugs/2023025

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-06-07 20:16:50 -03:00
Nikita Romaniuk
d8e25ce915
profiles: allow reading of /etc/ld-musl-*.path
/etc/ld-musl-*.path is required to perform dynamic linking on musl libc.
The wildcard is to match all CPU architectures, like x86_64.

type=AVC msg=audit(1686087677.497:67): apparmor="DENIED" operation="open" class="file" profile="syslog-ng" name="/etc/ld-musl-x86_64.path" pid=25866 comm="syslog-ng" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Closes #333

Signed-off-by: Nikita Romaniuk <kelvium@yahoo.com>
2023-06-07 01:09:33 +03:00
Georgia Garcia
a00ece5b6e Merge profiles: add lock file permission to snap browsers
When opening snap browsers with evince using the snap_browsers
abstraction, we get the following AppArmor denials which prevent the
browsers from opening

audit: type=1400 audit(1685996894.479:225): apparmor="DENIED" operation="open" class="file" profile="/usr/bin/evince//snap_browsers" name="/var/lib/snapd/inhibit/firefox.lock" pid=13282 comm="snap" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

audit: type=1400 audit(1685997517.142:259): apparmor="DENIED" operation="file_lock" class="file" profile="/usr/bin/evince//snap_browsers" name="/var/lib/snapd/inhibit/firefox.lock" pid=14200 comm="snap" requested_mask="k" denied_mask="k" fsuid=1000 ouid=0

This MR should be cherry-picked into 2.13, 3.0, 3.1

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1045
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-06-06 11:14:43 +00:00
Georgia Garcia
daec4bc82a profiles: add lock file permission to snap browsers
When opening snap browsers with evince using the snap_browsers
abstraction, we get the following AppArmor denials which prevent the
browsers from opening

audit: type=1400 audit(1685996894.479:225): apparmor="DENIED" operation="open" class="file" profile="/usr/bin/evince//snap_browsers" name="/var/lib/snapd/inhibit/firefox.lock" pid=13282 comm="snap" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

audit: type=1400 audit(1685997517.142:259): apparmor="DENIED" operation="file_lock" class="file" profile="/usr/bin/evince//snap_browsers" name="/var/lib/snapd/inhibit/firefox.lock" pid=14200 comm="snap" requested_mask="k" denied_mask="k" fsuid=1000 ouid=0

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-06-05 17:39:28 -03:00
Daniel Richard G
d367adf1f1 Improvements from the Ubuntu 20.04 Firefox profile
The Ubuntu profile is available at (trunk and branch locations)
  https://bazaar.launchpad.net/~mozillateam/firefox/firefox-trunk.head/view/head:/debian/usr.bin.firefox.apparmor.14.10
  https://bazaar.launchpad.net/~mozillateam/firefox/firefox.focal/view/head:/debian/usr.bin.firefox.apparmor.14.10
2023-05-30 15:22:25 -04:00
John Johansen
8d6358fa6d Merge Fix use-after-free of 'name' in parser_regex.c
'name' gets used in the error message. Make sure it only gets freed
afterwards.

This bug was introduced in be0d2fa947 /
https://gitlab.com/apparmor/apparmor/-/merge_requests/727

Fixes coverity CID 254465:  Memory - illegal accesses  (USE_AFTER_FREE)

I propose this fix for 3.0..master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1040
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-05-29 22:38:17 +00:00
John Johansen
dc8cbebdef Merge Fix order of if conditions to avoid unreachable code
If `else if (preprocess_only)` is true, the more strict condition
`else if (!include_file && preprocess_only)` won't be reached if it gets
checked after the shorter condition.

Exchange the two sections so that both code paths can be reached.

Fixes coverity CID 312499:  Control flow issues  (DEADCODE)

This was probably introduced in 7dcf013bca / https://gitlab.com/apparmor/apparmor/-/merge_requests/743 which means we'll need to backport this fix to 3.0 and 3.1.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1039
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-05-29 22:29:06 +00:00
John Johansen
b92bad44d7 Merge Fix missing uint32_t type declaration in rule.h
... by including cstdint.

Credits go to the new gcc in Tumbleweed for proposing this patch.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1038
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-05-29 22:28:04 +00:00
Christian Boltz
e408d03a5b
Fix use-after-free of 'name' in parser_regex.c
'name' gets used in the error message. Make sure it only gets freed
afterwards.

This bug was introduced in be0d2fa947 /
https://gitlab.com/apparmor/apparmor/-/merge_requests/727

Fixes coverity CID 254465:  Memory - illegal accesses  (USE_AFTER_FREE)
2023-05-29 22:16:09 +02:00
Christian Boltz
eabbc61509
Fix order of if conditions to avoid unreachable code
If `else if (preprocess_only)` is true, the more strict condition
`else if (!include_file && preprocess_only)` won't be reached if it gets
checked after the shorter condition.

Exchange the two sections so that both code paths can be reached.

Fixes coverity CID 312499:  Control flow issues  (DEADCODE)
2023-05-29 21:33:54 +02:00
Christian Boltz
c5c0ecb508
Fix missing uint32_t type declaration in rule.h
... by including cstdint.

Credits go to the new gcc in Tumbleweed for proposing this patch.
2023-05-29 21:24:31 +02:00
John Johansen
d700f87d3e Merge extend test profiles for mount
- in bad_?.sd, explain why the profile is bad (conflicting options)
- add a good profile with two space-separated options

This is a follow-up for https://gitlab.com/apparmor/apparmor/-/merge_requests/1029

If we backport !1029, we should also backport these test changes.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1035
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-05-23 21:40:06 +00:00
John Johansen
88d2bf45a4 Merge aa-status: Fix malformed json output
In some cases (if profiles in complain _and_ enforce mode are loaded), the `i` loop runs more
than once, which also means `j == 0` is true in the middle of the json.
This causes invalid json.

This patch fixes this.

This is a regression related to 22aa9b6161
/ https://gitlab.com/apparmor/apparmor/-/merge_requests/964 /
https://gitlab.com/apparmor/apparmor/-/issues/295
which fixed another case of invalid json if a process was unconfined
while having a profile defined.

Note: I also tested this patch for the "unconfined, but has a profile
defined" case to ensure it doesn't break what
22aa9b6161 fixed.

This fix is needed in all branches that also got !964 (which means 3.1 and 3.0).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1036
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-05-19 20:33:20 +00:00
Christian Boltz
f72c001643
aa-status: Fix malformed json output
In some cases (if profiles in complain and enforce mode are loaded), the
`i` loop runs more than once, which also means `j == 0` is true in the
middle of the json. This causes invalid json.

This patch fixes this.

This is a regression related to 22aa9b6161
/ https://gitlab.com/apparmor/apparmor/-/merge_requests/964 /
https://gitlab.com/apparmor/apparmor/-/issues/295
which fixed another case of invalid json if a process was unconfined
while having a profile defined.

Note: I also tested this patch for the "unconfined, but has a profile
defined" case to ensure it doesn't break what
22aa9b6161 fixed.
2023-05-19 22:25:05 +02:00
Christian Boltz
9a9af71d83
extend test profiles for mount
- in bad_?.sd, explain why the profile is bad (conflicting options)
- add a good profile with two space-separated options

This is a follow-up for https://gitlab.com/apparmor/apparmor/-/merge_requests/1029
2023-05-18 20:05:42 +02:00
John Johansen
e7f1b882f7 Merge aa-status: extend to support filtering
Enhance aa-status by adding posix regex filter support and support for new modes

this MR adds the following command line options
```
      --show={profiles,processes,all}
      --count
      --filter.mode=filter
      --filter.processs=filter
      --filter.profiles=filter
      --filter.pid=filter
```

Where currently filters use the basic posix regexs, do we want to go with extended regex, or apparmor globbing

An example of using the new filters
```
$ sudo ./aa-status --filter.exe="firefox" --show=processes
apparmor module is loaded.
65 processes have profiles defined.
25 processes are in enforce mode.
   /snap/firefox/2605/usr/lib/firefox/firefox (4406) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (4686) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (4721) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (4826) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (19204) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (19206) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (23159) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (23195) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (23292) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (30929) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (31487) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (31528) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (71708) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2271631) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2271969) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2272030) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2272347) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2654995) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2655042) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2655082) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2655152) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2655237) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2656215) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2656334) snap.firefox.firefox
   /snap/firefox/2605/usr/lib/firefox/firefox (2657837) snap.firefox.firefox
0 processes are in complain mode.
0 processes are in prompt mode.
0 processes are in kill mode.
0 processes are unconfined but have a profile defined.
0 processes are in mixed mode.
```

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1016
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-05-18 16:59:08 +00:00
John Johansen
f629340d1b Merge chromium_browser: Inherit updates from apparmor-profiles repo
Bring in updates and improvements that have been made to the Chromium profile at `apparmor-profiles/ubuntu/20.04/usr.bin.chromium-browser`.

The changes are largely as follows:

* Use `@{pid}` or `@{tid}` instead of `[0-9]*`

* Use the discrete `lsb_release` profile instead of a subprofile

* Add a few additional libraries to the `sandbox` subprofile

Once this is in, the Chromium profiles in `apparmor-profiles` can be considered deprecated, and I would advise slating them for removal altogether.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1032
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>
2023-05-18 16:57:59 +00:00
Christian Boltz
dec3815f07 Merge nscd: add permission to allow supporting unscd
`unscd` is a drop-in replacement for `nscd` that uses the same binary location (`/usr/sbin/nscd`) and config file (`/etc/nscd.conf`). The `usr.sbin.nscd` profile only needs one additional permission to support it.

```
May 9 18:07:42 darkstar kernel: [ 2706.138823] audit: type=1400
audit(1683670062.580:839): apparmor="DENIED" operation="sendmsg"
profile="nscd" name="/run/systemd/notify" pid=4343 comm="nscd"
requested_mask="w" denied_mask="w" fsuid=125 ouid=0
```

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1031
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-05-10 10:54:22 +00:00
Daniel Richard G
bd0d401b3d nscd: add permission to allow supporting unscd
May 9 18:07:42 darkstar kernel: [ 2706.138823] audit: type=1400
audit(1683670062.580:839): apparmor="DENIED" operation="sendmsg"
profile="nscd" name="/run/systemd/notify" pid=4343 comm="nscd"
requested_mask="w" denied_mask="w" fsuid=125 ouid=0
2023-05-10 00:31:06 -04:00
Daniel Richard G
4507bdc020 chromium_browser: Inherit updates from apparmor-profiles repo
Bring in updates and improvements that have been made to the Chromium
profile at apparmor-profiles/ubuntu/20.04/usr.bin.chromium-browser
2023-05-10 00:19:55 -04:00
Jon Tourville
c46bf8944a Merge Check for newer mount options in regression test
The mount options MS_LAZYTIME and MS_NOSYMFOLLOW were added in
kernels 4.0 and 5.10, respectively. Update the mount test script
and helper to skip testing those options if they are not available.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1024
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-03 11:40:32 +00:00
Jon Tourville
9a760def8d Check for newer mount options in regression test
The mount options MS_LAZYTIME and MS_NOSYMFOLLOW were added in
kernels 4.0 and 5.10, respectively. Update the mount test script
and helper to skip testing those options if they are not available.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-03 08:51:28 +00:00
John Johansen
2434838136 aa-status: update man page with filter information
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-03 01:22:33 -07:00
John Johansen
09b35f836b Merge Abstractions: better integration
This is the first MR of a possibly very long list of MR in order to upstream stable abstraction & profiles previously tested in https://github.com/roddhjav/apparmor.d

This first MR focuses on integrating abstraction completion from the `*.d` directory in [apparmor.d/abstractions](https://github.com/roddhjav/apparmor.d/tree/main/apparmor.d/abstractions)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/995
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-05-02 12:34:04 +00:00
John Johansen
5ff6686ea7 aa-status: rename filters so they have the filters. prefix
To emphasize that the
  --mode
  --processs
  --profiles
  --pid

options are filters rename them to
  --filter.mode
  --filter.processs
  --filter.profiles
  --filter.pid

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 03:06:36 -07:00
John Johansen
5453f985ba aa-status: add support for prompt mode
Support prompt mode. Note that the kernel uses "user" instead of
"prompt" that policy uses.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:57:11 -07:00
John Johansen
c065570c6f aa-status: Add filter for the executable
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:57:09 -07:00
John Johansen
a5852c41df aa-status: add ability to filter on pid
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:55:45 -07:00
John Johansen
195877b732 fixup profile filter 2023-05-02 02:53:51 -07:00
John Johansen
016183cbf4 aa-status: add profile filter
Extend filtering to be able to screen for different profiles by name

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:45:49 -07:00
John Johansen
ee66319d0b aa-status: Make filtering more generic
In preparation for more filters than just mode prepare a basic filtering
infrastructure.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-05-02 02:45:01 -07:00