Commit graph

7350 commits

Author SHA1 Message Date
John Johansen
db66b36064 parser: move perm to accept mapping into State
Let the state deal with permission mappings and what to do if outputting
an index.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-14 12:37:02 -07:00
John Johansen
b4bb880ad3 Merge utils: move app path from primary window to more info
In this change, I'm also removing the messagebox window and reusing
the more info GUI already implemented

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1302
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-14 16:27:53 +00:00
Georgia Garcia
adacb25bb4 utils: fix rule being shown when profile file does not exist
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-14 13:11:45 -03:00
Georgia Garcia
ad37401681 utils: change font color of "show info" window to the default
I couldn't figure out why the show info window was using a different
font color than the theme default but this forces its use.
Also, add padding when "Show Current Profile" button is not shown.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-14 13:11:45 -03:00
Georgia Garcia
1d4010fbcf utils: move app path from primary window to more info
In this change, I'm also removing the messagebox window and reusing
the more info GUI already implemented

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-14 13:07:31 -03:00
Georgia Garcia
2083994513 profiles: enable php-fpm in /usr/bin and /usr/sbin
To enable the profile in distros that merge sbin into bin.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/421
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-14 10:52:53 -03:00
Georgia Garcia
a50283bad0 Merge profiles: runc: allow /usr/bin/runc as well as /usr/sbin/runc
Docker, Inc's `containerd.io` package installs runc onto `/usr/bin/runc` rather than `/usr/sbin/runc`.

```
$ wget https://download.docker.com/linux/ubuntu/dists/noble/pool/stable/amd64/containerd.io_1.7.20-1_amd64.deb
$ dpkg -c containerd.io_1.7.20-1_amd64.deb | grep /runc
-rwxr-xr-x root/root   9806280 2024-08-08 23:20 ./usr/bin/runc
```

Similar to 9ab45d "profiles: support distributions which merge sbin into bin".

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1300
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-14 12:30:26 +00:00
Akihiro Suda
2333fbcf74
profiles: runc: allow /usr/bin/runc as well as /usr/sbin/runc
Docker, Inc's `containerd.io` package installs runc onto `/usr/bin/runc`
rather than `/usr/sbin/runc`.

```
$ wget https://download.docker.com/linux/ubuntu/dists/noble/pool/stable/amd64/containerd.io_1.7.20-1_amd64.deb
$ dpkg -c containerd.io_1.7.20-1_amd64.deb | grep /runc
-rwxr-xr-x root/root   9806280 2024-08-08 23:20 ./usr/bin/runc
```

Similar to 9ab45d "profiles: support distributions which merge sbin into bin".

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2024-08-14 18:32:35 +09:00
Akihiro Suda
bf5db67284
profiles: slirp4netns: allow pivot_root
`pivot_root` is required for running `slirp4netns --enable-sandbox` inside LXD.
- https://github.com/rootless-containers/slirp4netns/issues/348
- https://github.com/rootless-containers/slirp4netns/blob/v1.3.1/sandbox.c#L101-L234

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2024-08-14 17:29:13 +09:00
John Johansen
2596e582f5 Merge aa-notify: Enhanced Graphical User Interfaces
aa-notify: Enhanced Graphical User Interfaces

- Added support for --prompt-filter=userns: a popup GUI now appears when an unprivileged, unconfined process attempts to create a user namespace, enabling automatic generation of specific unconfined profiles.
- Added GUIs for easy rule addition.
- Upgraded notifications to two-button format, enabling extended information display and direct rule addition.
- Initial support for customized notification messages based on rule type.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1281
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2024-08-13 16:58:25 +00:00
Maxime Bélair
ff1baf3851 aa-notify: Enhanced Graphical User Interfaces 2024-08-13 16:58:25 +00:00
Christian Boltz
d9e9bb1a55 Merge logparser: Add tests for create_rule_from_ev
- Add tests to check that create_rule_from_ev can create any rule type
- create_rule_from_ev: if the rule cannot be created, always return None

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1297
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-08-13 14:02:22 +00:00
Maxime Bélair
713787e188 logparser: Add tests for create_rule_from_ev
- Add tests to check that create_rule_from_ev can create any rule type
- create_rule_from_ev: if the rule cannot be created, always return None
2024-08-13 11:35:58 +02:00
John Johansen
86b3d60073 Merge logparser.py hashlog: rename 'path' to 'file'
... which is the name we use everywhere else.

With this, we can drop the special casing for 'path' in aa.py
collapse_hashlog.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1296
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-12 22:44:54 +00:00
John Johansen
055d0f80b5 Merge logparser: adding support for comm in capability events
In order to act on capability denials, we need to parse comm.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1294
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-12 22:43:55 +00:00
Christian Boltz
1d5fc6f2a6
logparser.py hashlog: rename 'path' to 'file'
... which is the name we use everywhere else.

With this, we can drop the special casing for 'path' in aa.py
collapse_hashlog.
2024-08-12 21:36:51 +02:00
Georgia Garcia
8f7da77142 Merge logparser: Small fix for get_event_type
ReadLog.ruletypes uses 'file' and not 'path' as a key. We update get_event_type accordingly

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1295
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-12 13:23:30 +00:00
Maxime Bélair
76b399310c logparser: adding support for comm in capability events
In order to act on capability denials, we need to parse comm.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2024-08-12 10:23:40 +02:00
Maxime Bélair
82062eb9b7 logparser: Small fix for get_event_type
ReadLog.ruletypes uses 'file' and not 'path' as a key. We update get_event_type accordingly

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2024-08-12 09:50:16 +02:00
John Johansen
11630b7f08 Merge Pass --fullnames to last in test-aa-notify.py
Code assumes full username would be printed, but this actually requires an extra command line option:

![image](/uploads/ea007c6bba3f486af73f00b36d17ad31/image.png)

Please double check that this is the only place where `last` is called as a binary before merging this MR.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1293
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-07 22:58:54 +00:00
Ryan Lee
3b1cc3c079 Pass --fullnames to last in test-aa-notify.py
Code assumes full username would be printed, but this actually requires an extra command line option

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2024-08-07 15:18:58 -07:00
John Johansen
e787f4d69d Merge abstractions/base: allow reading of fips_enabled
Commonly used by applications to determine if Linux is running in
FIPS mode. As we already allow access to FIPS specific library files
as part of base, allow this there as well.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1286
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-07 07:37:51 +00:00
Georgia Garcia
7715b79e3f Merge Explicitly initialize component in test_walk_one
This removes the assumption that the stack is zeroed and silences the corresponding compiler warning

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1292
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-06 20:23:29 +00:00
Georgia Garcia
0880f3545d Merge Fix SWIG prototype declaration of aa_getpeercon_raw
Unsigned int vs int probably wouldn't have caused issues, but just in case

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1291
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-06 20:23:13 +00:00
Georgia Garcia
d1da63dc5a Merge Fix incorrect strnlen length in aa_load.c load_policy_dir
POSIX states that d_name has up to NAME_MAX (255) characters, and glibc
stores d_name as an array of size NAME_MAX+1 (256). Thus, supplying
PATH_MAX (4096) as the max length could trigger a buffer overrun. This
could be an even bigger issue on other libcs, as POSIX states that d_name
can be unsized.

Fortunately, this does not seem to cause actual issues, as the length is
only used to compare d_name to a short fixed string. However, it'd be better
to pass the actual correct max length to strnlen.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1290
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-06 20:13:52 +00:00
Ryan Lee
91bac34afd Fix SWIG prototype declaration of aa_getpeercon_raw
Unsigned int vs int probably wouldn't have caused issues, but just in case

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2024-08-06 13:04:53 -07:00
Ryan Lee
322a98c8c9 Fix incorrect strnlen length in aa_load.c load_policy_dir
POSIX states that d_name has up to NAME_MAX (255) characters, and glibc
stores d_name as an array of size NAME_MAX+1 (256). Thus, supplying
PATH_MAX (4096) as the max length could trigger a buffer overrun. This
could be an even bigger issue on other libcs, as POSIX states that d_name
can be unsized.

Fortunately, this does not seem to cause actual issues, as the length is
only used to compare d_name to a short fixed string. However, it'd be better
to pass the actual correct max length to strnlen.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2024-08-06 13:04:17 -07:00
Ryan Lee
552d9d9f7a Explicitly initialize component in test_walk_one
This removes the assumption that the stack is zeroed and silences the corresponding compiler warning

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2024-08-06 13:02:52 -07:00
John Johansen
65f7432383 Merge utils/emacs: add apparmor-mode.el
Imported from https://github.com/alexmurray/apparmor-mode with just a minimal
change to update the URL field to point to the upstream apparmor repo.

Signed-off-by: Alex Murray <alex.murray@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1289
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-06 05:54:03 +00:00
Alex Murray
65b0f83aea
utils/emacs: add apparmor-mode.el
Imported from https://github.com/alexmurray/apparmor-mode with just a minimal
change to update the URL field to point to the upstream apparmor repo.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2024-08-06 13:36:32 +09:30
John Johansen
ed3bc55d35 Merge libapparmor: fix undefined reference to aa_split_overlay_str
The linkage of aa-load with the dynamic libapparmor fails with:
aa_load.c:273: undefined reference to `aa_split_overlay_str'

That is because when aa_split_overlay_str was added to libapparmor,
the function was not added to the library map.

Fixes: 50054ff0 ("add aa_split_overlay_str")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1288
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-05 16:10:13 +00:00
Georgia Garcia
2eae692b05 libapparmor: fix undefined reference to aa_split_overlay_str
The linkage of aa-load with the dynamic libapparmor fails with:
aa_load.c:273: undefined reference to `aa_split_overlay_str'

That is because when aa_split_overlay_str was added to libapparmor,
the function was not added to the library map.

Fixes: 50054ff0 ("add aa_split_overlay_str")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-05 10:27:37 -03:00
Georg Pfuetzenreuter
2a9fe26459
abstractions/base: allow reading of fips_enabled
Commonly used by applications to determine if Linux is running in
FIPS mode. As we already allow access to FIPS specific library files
as part of base, allow this there as well.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2024-08-04 20:25:05 +02:00
John Johansen
fac2e25219 Merge firefox: add fcitx portal rules from Ubuntu 20.04/focal
The Ubuntu 20.04/focal packaging of Firefox added these rules to their AppArmor profile recently, relating to the [Fcitx portal](https://fcitx-im.org/wiki/Using_Fcitx_with_container).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1280
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-02 07:44:46 +00:00
Daniel Richard G
6223497f65 firefox: add fcitx abstraction 2024-08-01 21:47:25 -04:00
John Johansen
b1a35e6cbd Merge Revert "parser: fix potential padding bug." and fix code to for correct padding
This reverts commit 78ae956087.

And the add the correct padding fix, so that the header size and what is written match.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1274
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2024-08-01 18:46:28 +00:00
John Johansen
bc68bc51ca Merge test: detect if setuid environ test in running under nosuid
If the test ran under a fs mounted with nosuid option, then these bits
would be ignored and the test would fail. In that case, detect it and
run the test in a tmpfs mountpoint without nosuid.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1285
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-01 18:45:58 +00:00
Georgia Garcia
f8e3273766 test: detect if setuid environ test in running under nosuid
If the test ran under a fs mounted with nosuid option, then these bits
would be ignored and the test would fail. In that case, detect it and
run the test in a tmpfs mountpoint without nosuid.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-08-01 15:25:02 -03:00
John Johansen
1fc944bb67 Merge fix regression test failures for when /tmp is mounted as tmpfs
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1283
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-08-01 04:36:20 +00:00
Georgia Garcia
4feb517003 tests: enable swap test when /tmp is tmpfs
When /tmp is of type tmpfs, the test didn't run because you can't
mount a swapfile on it. This patch mounts an ext2 mountpoint on
$tmpdir so that the swapfile can be mounted on top of it instead of
tmpfs.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-07-31 19:30:08 -03:00
Georgia Garcia
6a20eb0dd5 tests: remount $tmpdir as private instead of /
When /tmp is mounted, remounting / as private for tests that don't
work when shared still fail because /tmp remains as shared. The option
-T in findmnt helps determine the mountpoint in a certain directory,
so use that with $tmpdir to determine the root.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-07-31 19:30:05 -03:00
Georgia Garcia
5a735d593f tests: refactor logic that makes mntpoint private for tests
The tests that use pivot_root or move mountpoints with mount have to
make sure that / is private for the tests to work. Refactor that logic
into a file to be sourced by the test scripts

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-07-31 17:10:07 -03:00
John Johansen
eac9f23404 lib: fix versioning of library EXPECTED_SO_NAME
the revision was reset and the EXPECTED_SO_NAME should match it.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-07-23 16:42:36 -07:00
John Johansen
00dfcedb69 lib: sync library version with 4.0.2 release
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-07-23 16:06:52 -07:00
Christian Boltz
f789503131 Merge utils: Simplify logparsing and rule creation from hashlog/event
utils: Simplify logparsing and rule creation from hashlog/event

- Allows to create all rules classes thanks to from_hashlog and hashlog_from_event
- These new functions simplify event/log parsing in logparser.py and aa.py

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1276
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-07-23 16:09:53 +00:00
Maxime Bélair
f0e87cc726 utils: Simplify logparsing and rule creation from hashlog/event 2024-07-23 16:09:53 +00:00
John Johansen
1f23f3ea71 Merge MqueueRule: allow / as mqueue name
... and not only `/something`

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/413#note_2008929033

While on it, table-format the MessageQueueTestParse tests.

I propose this fix for master and 4.0.

Closes #413
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1278
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-07-21 16:36:37 +00:00
Christian Boltz
02edb649fa
MqueueRule: allow / as mqueue name
... and not only `/something`

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/413#note_2008929033
2024-07-21 16:00:18 +02:00
Christian Boltz
93870323a0
test-mqueue: table-format MessageQueueTestParse 2024-07-21 15:58:01 +02:00
John Johansen
d0d75abd02 Merge parser: ensure mqueue obeys abi
The abi is not being respected by mqueue rules in many cases. If policy
does ot specify an mqueue rule the abi is correctly applied but if
an mqueue rule is specified explicitly or implicitly (eg. allow all).
without setting the mqueue type OR setting the mqueue type to sysv.
The abi will be ignored and mqueue will be enforced for policy regadless.

Known good mqueue rule that respects abi
  mqueue type=posix,

  # and all variations that keep type=posix

Known bad mqueue rules that do not respect abi

  mqueue,
  # and all variants that do not specify the type= option

  mqueue type=sysv,
  # and all variants that specify the type=sysv option

Issue: https://gitlab.com/apparmor/apparmor/-/issues/412
Fixes: d98c5c4cf ("parser: add parser support for message queue mediation")

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1277
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-07-20 20:05:47 +00:00