2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00
Commit Graph

7580 Commits

Author SHA1 Message Date
Georgia Garcia
ab44dddba9 utils: add allow keyword to list of unsupported modifiers
Some classes don't support modifiers like audit and deny. Only rlimit
has been checking for the allow keyword, but the others shouldn't
support it as well. Since they all do the same check, refactor them
into a method from BaseRule in case more modifiers are added.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
(cherry picked from commit 3389230437)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-05-07 02:15:18 -07:00
Christian Boltz
3d14d51253 Merge parser: fix if condition at the bottom of equality.sh
The lack of a space after $testtype is a syntax error and was causing the
equality tests on Ubuntu Xenial to be silently skipped and marked PASS.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1670
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit bd46a02e47)

17ee87ad parser: fix if condition at the bottom of equality.sh

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2025-05-05 19:03:50 +00:00
John Johansen
e026d4a95d Merge [cherry-pick] binutils/aa-status: don't exit if no profiles are loaded
Downstream report: https://github.com/NixOS/nixpkgs/issues/347490

Output of `aa-status` is nondescriptive if no profiles are loaded.

Worse yet, the json output isn't even valid json. It would make sense to just return a json object with no entries, instead of returning a non-json `eprint` to stderr.

**Ideally** output of non-json would be more descriptive.

Currently:

```
apparmor module is loaded.
Failed to get profiles: 2....
```

What i would prefer:

```
apparmor module is loaded.
Failed to get profiles: No policies loaded
```

However, i am unfamiliar with how the translation framework works, and thus not confident to do this change blindly. I am happy to add a commit doing so if i know where to change all that.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1652
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 6f480cb819)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1656
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-04-30 08:01:56 +00:00
Grimmauld
699ef083a6 binutils/aa-status: don't exit if no profiles are loaded
Downstream report: https://github.com/NixOS/nixpkgs/issues/347490

Output of `aa-status` is nondescriptive if no profiles are loaded.

Worse yet, the json output isn't even valid json.
It would make sense to just return a json object with no entries,
instead of returning a non-json `eprint` to stderr.
2025-04-28 09:16:53 +02:00
Steve Beattie
c0f6085952 Merge parser: fix rlimit ofile when built on musl libc
glibc defines bsd's rlimit ofile as nofile, however musl does not define
rlimit ofile at all.

Instead of just dropping ofile which would be bad for policy portability
make sure it is defined to be nofile.

This is a partial fie for
https://gitlab.com/apparmor/apparmor/-/issues/513

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1648
Approved-by: Steve Beattie <steve+gitlab@nxnw.org>
Merged-by: Steve Beattie <steve+gitlab@nxnw.org>
(cherry picked from commit 887ff42043)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-23 00:47:54 -07:00
John Johansen
1dba775f1d Merge make AMD GPUs work better
Proposed by darix

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1642
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 7702b40359)
2025-04-21 12:31:09 -07:00
Christian Boltz
6ca0353efd make AMD GPUs work better
Proposed by darix

(cherry picked from commit 5d71e19753)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-21 12:31:09 -07:00
John Johansen
d8bacb87b4 Merge abstractions/nameservice: allow kanidm-unixd
If kanidm is configured in nsswitch.conf(5), access to the kanidm-unixd
configuration is needed for applications to resolve entries.

For example:

```
type=AVC apparmor="DENIED" operation="open" class="file" profile="php-fpm"
name="/etc/kanidm/unixd" comm="php-fpm" requested_mask="r" denied_mask="r"
```

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1638
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 8504cda668)
2025-04-21 12:30:07 -07:00
Georg Pfuetzenreuter
955d302fec abstractions/nameservice: allow kanidm-unixd
If kanidm is configured in nsswitch.conf(5), access to the kanidm-unixd
configuration is needed for applications to resolve entries.

For example:

```
type=AVC apparmor="DENIED" operation="open" class="file" profile="php-fpm"
name="/etc/kanidm/unixd" comm="php-fpm" requested_mask="r" denied_mask="r"
```

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
(cherry picked from commit 675a99ac7b)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-21 12:30:07 -07:00
John Johansen
1da593aa2e Merge add path for plasmashell with qt6 based QtWebEngineProcess in debian derivatives
we are using this path in a local profile shipped with plasma-workspace in KDE neon

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1633
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit ee08bfbc90)
2025-04-21 12:27:58 -07:00
carlosdem
97d64497f1 fix typo
(cherry picked from commit d8ddd665fc)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-21 12:27:58 -07:00
carlosdem
dd9485b5be add path for plasmashell with qt6 based QtWebEngineProcess in debian derivatives
(cherry picked from commit 393444b7ba)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-21 12:27:58 -07:00
Christian Boltz
1e95e32252 Merge utils: fix unix qualifier clean rule generation
The wrong clean rule is generated when unix rules contain qualifiers,
with the order inverted with the rule name.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/511
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

Closes #511
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1639
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>


(cherry picked from commit c5642f9d43)

8c84b36b utils: fix unix qualifier clean rule generation

Co-authored-by: Christian Boltz <apparmor@cboltz.de>
2025-04-18 19:11:55 +00:00
John Johansen
4d76854372 Merge unprivileged_userns profile: Allow full file system access
Fixes https://gitlab.com/apparmor/apparmor/-/issues/505

The profile previously permitted access to `/**`, which excludes the root
directory (`/`). This commit also gives `/` access, aligning with the
intended behavior.

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

Closes #505
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1626
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 8138bc60d1)
2025-04-12 02:21:12 -07:00
Maxime Bélair
29f6ac644f unprivileged_userns profile: Allow full file system access
Fixes https://gitlab.com/apparmor/apparmor/-/issues/505

The profile previously permitted access to `/**`, which excludes the root
directory (`/`). This commit also gives `/` access, aligning with the
intended behavior.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
(cherry picked from commit 182db98c2a)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-12 02:21:12 -07:00
John Johansen
53074bb906 Preoarse for AppArmor 4.1 release
- update version file
- bump library version

Signed-off-by: John Johansen <john.johansen@canonical.com>
v4.1.0
2025-04-08 09:20:05 -07:00
John Johansen
62aeb03d99 Merge tests: regressions: fix unix_socket_pathname.sh for upstream kernels
FS based unix sockets have a complicatd interaction with socket
mediation some of the mediation happens in file hooks while other
parts happen in network hooks.

When the kernel doesn't have the unix socket mediation patches the
interactions become largely mediated through the network hooks, as
unix rules get downgraded to socket rules. However some filesystem
operations are needed, and some hooks like bind may be called
differently based on the unix socket type, and not just the address.
Without the kernel patches these variations are not taken into
account.

Changes in the parser networking permission mappings have also
affected the downgrade path, as the parser now supports permissions on
socket rules, downgrades can use permissions and be more faithful to
the original rule but this can also break tests that didn't add all
the permissions needed for the downgrade case.

update unix_socket_pathname.sh to detect whether rule downgrades are
being used, and adjust permissions and expectations based on this.

Fixes: 7ce768244 ("tests: regression: fix regression test for upstream kernels")

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1622
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit d9ecaf60bc)
2025-04-08 09:06:24 -07:00
John Johansen
cb67e865cf tests: regression: increase unix socket test timeout
The tests on slower systems are occassionally timing out leading to
inconsistent pass/fail runs. The time out failure depending on which
test it occurs in can result in false passes, or failres.

Double the timeout, which hopefully will be enough to avoid the
timeout issue without making the tests wait too long.

Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit 2c784709b2)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-08 09:06:24 -07:00
John Johansen
3cc7bf844e tests: regressions: fix unix_socket_pathname.sh for upstream kernels
FS based unix sockets have a complicatd interaction with socket
mediation some of the mediation happens in file hooks while other
parts happen in network hooks.

When the kernel doesn't have the unix socket mediation patches the
interactions become largely mediated through the network hooks, as
unix rules get downgraded to socket rules. However some filesystem
operations are needed, and some hooks like bind may be called
differently based on the unix socket type, and not just the address.
Without the kernel patches these variations are not taken into
account.

Changes in the parser networking permission mappings have also
affected the downgrade path, as the parser now supports permissions on
socket rules, downgrades can use permissions and be more faithful to
the original rule but this can also break tests that didn't add all
the permissions needed for the downgrade case.

update unix_socket_pathname.sh to detect whether rule downgrades are
being used, and adjust permissions and expectations based on this.

Fixes: 7ce768244 ("tests: regression: fix regression test for upstream kernels")
Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit 08f9466d1c)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-08 09:06:24 -07:00
Zygmunt Krynicki
fff99a1c6a Add support for running image-garden as a snap
The new image-garden snap offers a one-stop-shop for integration
testing, bundling qemu, spread and image-garden build recipes.

Extend the documentation, the run-spread.sh helper script as well as
spread.yaml to support this new method.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
(cherry picked from commit bd500e2391)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-08 05:57:02 -07:00
Christian Boltz
3023e6cd09 Check for mount rules with multiple 'fstype'
... and adjust the tools to raise an exception if such a rule is found.
While this is not nice, it's better than the previous behaviour where
only the last 'fstype' was kept, and the others were lost when writing
the rule.

(cherry picked from commit b5894687ed)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-08 05:55:53 -07:00
Christian Boltz
9178bfc444 Check for mount rules with multiple 'options'
... and adjust the tools to raise an exception if such a rule is found.
While this is not nice, it's better than the previous behaviour where
only the last 'options' was kept, and the others were lost when writing
the rule.

(cherry picked from commit 171e0b1fa9)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-08 05:55:53 -07:00
John Johansen
959b1e0405 Merge tests: regression: fix regression test for upstream kernels
The attach_disconnected.sh and deleted.sh tests added expanded their
testing by using unix sockets. This however ever needs support of
unix socket mediation.

Provide a minimal fix by setting bailouts for the the tests if the
requirement is not present. Long term it would be better if the
expected/needed permissions sets could be tweaked to take into
account the permissions required by the use of unix sockets.

The fix f47d5c70a fix af_unix tests for v8 networking, was never
correct, though it worked and was closer before support for fine
grained inet mediation landed. Before finegrained inet mediation
landed unix rules would allow specifying the permission but inet would
not only allowing coarse socket mediation rules. While the backend
supported finegrained permissions in v8 socket mediation the parser
did not.

If af_unix mediation was not supported by the kernel the af_unix
mediation rule would be downgrade to a network rule. All network
socket rules allowed full permission because the parser didn't
support permissions on socket rules. So the "unix create," rule
was being downgraded to a "unix," rule. Thus the "unix create",
rule was enough permissions, in the downgrade even though it
actually wasn't enough permissions.

With support for fine grained inet permissions, support for permissions
on socket rules also landed. When this happend "unix create," was not
enough permissions any more because it was not downgraded to "unix,",
this resulted in failed mediation.

Fixes: cb4a397b1 ("tests: add attach_disconnected tests")
Fixes: f47d5c70a ("fix af_unix tests for v8 networking")

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1621
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 0a13a56f5c)
2025-04-07 18:19:22 -07:00
John Johansen
67dc25ac6d tests: regression: fix regression test for upstream kernels
The attach_disconnected.sh and deleted.sh tests added expanded their
testing by using unix sockets. This however ever needs support of
unix socket mediation.

Provide a minimal fix by setting bailouts for the the tests if the
requirement is not present. Long term it would be better if the
expected/needed permissions sets could be tweaked to take into
account the permissions required by the use of unix sockets.

The fix f47d5c70a fix af_unix tests for v8 networking, was never
correct, though it worked and was closer before support for fine
grained inet mediation landed. Before finegrained inet mediation
landed unix rules would allow specifying the permission but inet would
not only allowing coarse socket mediation rules. While the backend
supported finegrained permissions in v8 socket mediation the parser
did not.

If af_unix mediation was not supported by the kernel the af_unix
mediation rule would be downgrade to a network rule. All network
socket rules allowed full permission because the parser didn't
support permissions on socket rules. So the "unix create," rule
was being downgraded to a "unix," rule. Thus the "unix create",
rule was enough permissions, in the downgrade even though it
actually wasn't enough permissions.

With support for fine grained inet permissions, support for permissions
on socket rules also landed. When this happend "unix create," was not
enough permissions any more because it was not downgraded to "unix,",
this resulted in failed mediation.

Fixes: cb4a397b1 ("tests: add attach_disconnected tests")
Fixes: f47d5c70a ("fix af_unix tests for v8 networking")

Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit 7ce768244d)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-07 18:19:22 -07:00
John Johansen
a974ad85fc Merge parser: Fix special casing for detached move mounts
MR: 1561 Added the ability to specify special a keyword to allow
detached mounts. Unfortunately it updated remount to use the device
and devbuffer when remounts current encoding doesn't support it.

This caused the mount.sh regression test to fail in the following
way.

```
$ sudo bash mount.sh
[sudo] password for jj:
    using mount rules ...
Error: mount failed. Test 'MOUNT (confined cap bind mount remount rprivate conflict)' was expected to 'pass'. Reason for failure 'FAIL: mount /tmp/sdtest.358520-12403-ASaOnn/mountpoint2 on /tmp/sdtest.358520-12403-ASaOnn/mountpoint failed - Permission denied'
    not supported by parser - skipping mount options=(nodirsync),
Error: mount failed. Test 'MOUNT (confined cap mount remount option)' was expected to 'pass'. Reason for failure 'FAIL: mount /dev/loop40 on /tmp/sdtest.358520-12403-ASaOnn/mountpoint failed - Permission denied'
Error: mount failed. Test 'MOUNT (confined cap mount remount)' was expected to 'pass'. Reason for failure 'FAIL: mount /dev/loop40 on /tmp/sdtest.358520-12403-ASaOnn/mountpoint failed - Permission denied'
Error: mount passed. Test 'MOUNT (confined cap mount remount deny option)' was expected to 'fail'
```

Revert the change to remount. This fixes the regression failure.
fa0746f2e parser: add special casing for detached move mounts
Signed-off-by: John Johansen <john.johansen@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1618
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 90938de5c4)
2025-04-07 05:22:57 -07:00
John Johansen
99fd58ee09 parser: Fix special casing for detached move mounts
MR: 1561 Added the ability to specify special a keyword to allow
detached mounts. Unfortunately it updated remount to use the device
and devbuffer when remounts current encoding doesn't support it.

This caused the mount.sh regression test to fail in the following
way.

```
$ sudo bash mount.sh
[sudo] password for jj:
    using mount rules ...
Error: mount failed. Test 'MOUNT (confined cap bind mount remount rprivate conflict)' was expected to 'pass'. Reason for failure 'FAIL: mount /tmp/sdtest.358520-12403-ASaOnn/mountpoint2 on /tmp/sdtest.358520-12403-ASaOnn/mountpoint failed - Permission denied'
    not supported by parser - skipping mount options=(nodirsync),
Error: mount failed. Test 'MOUNT (confined cap mount remount option)' was expected to 'pass'. Reason for failure 'FAIL: mount /dev/loop40 on /tmp/sdtest.358520-12403-ASaOnn/mountpoint failed - Permission denied'
Error: mount failed. Test 'MOUNT (confined cap mount remount)' was expected to 'pass'. Reason for failure 'FAIL: mount /dev/loop40 on /tmp/sdtest.358520-12403-ASaOnn/mountpoint failed - Permission denied'
Error: mount passed. Test 'MOUNT (confined cap mount remount deny option)' was expected to 'fail'
```

Revert the change to remount. This fixes the regression failure.
fa0746f2e parser: add special casing for detached move mounts
Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit 89e8fe9c1c)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-07 05:22:57 -07:00
John Johansen
8252aa572b utils: tests: fixup: bad merge conflict resolutin of test mount/ok_opt_86.sd
The picking of 31569f9f7 ("mount: accept fstype and options in any order")
to apparmor-4.1 had a merge conflict, and unfortunately the
mount/ok_opt_86.sd being removed from syntax_failure got dropped.
Remove it.

Since this was already pushed ot the publc tree this is being handled
as a fixup patch instead of revising the original pick as should
normally be done.

Fixes: 31569f9f7 ("mount: accept fstype and options in any order")
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 20:09:53 -07:00
John Johansen
adbe66f118 Merge mount: accept fstype and options in any order
Note: If multiple fstype= or options= are given, this is not detected as
an error (to keep the regex simpler). When writing back such a rule,
only one fstype and options will "survive".

Adjust the exclude list in test-parser-simple-tests.py accordingly:
- several valid mount rules no longer fail
- two invalid mount rules which so far accidentally raised an exception
  because of the fstype/options order no longer raise this exception
  (conflicting mount options, which are the real reason why these rules
  are invalid, are not detected in the tools)

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

I propose this fix for 4.0, 4.1 and master. (Note: excluding
`mount/ok_opt_86.sd` was added in !1561, so we either need to also
backport this, or have to slightly adjust this MR for backporting.)

Closes #501
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1616
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 37666dd736)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 14:20:57 -07:00
Christian Boltz
31569f9f7d mount: accept fstype and options in any order
Note: If multiple fstype= or options= are given, this is not detected as
an error (to keep the regex simpler). When writing back such a rule,
only one fstype and options will "survive".

Adjust the exclude list in test-parser-simple-tests.py accordingly:
- several valid mount rules no longer fail
- two invalid mount rules which so far accidentally raised an exception
  because of the fstype/options order no longer raise this exception
  (conflicting mount options, which are the real reason why these rules
  are invalid, are not detected in the tools)

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/501
(cherry picked from commit 7726c86b79)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 14:20:30 -07:00
John Johansen
f70e8998ba Merge parser: add special casing for detached move mounts
upsteam move_mount mediation now allows for a detached (disconnected)
mount to be move mounted into a namespace.

Add support for this by detecting 'detached' as a keyword for the
source/device and using it to create a null match. Because existing
mount encoding using a null separator between the mount terms null
match followed by the null seperator will separate detached mounts
within the existing encoding.

```
Eg.
  mount detached -> /destination,
  mount options=(ro) fstype=ext4 detached -> /destination,
```

This is functionally equivalent to using
```
  mount "" -> /destination,
```

However using ```""``` does not provide any context that about what
the rule is allowing or why so the ```detached``` form is preferred.

This is not a perfect solution, but is what can be currently supported
by the kernel without more LSM hooks.

On kernels that don't support detached mount detection, rules using
the detached source conditional will be ignored (never matched).

This encoding also allows the existing

```
  mount,
  mount options=(move),
  mount options=(move) -> /destination,
```

to continue to work with both detached and regular mounts on kernels
that support the move_mount() syscall.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1561
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
(cherry picked from commit 2df4bbd39b)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 14:14:08 -07:00
John Johansen
a8c45527f1 utils: tests: mark detached mount as tools wrong
The tools are wrong in parsing the detached mount test.

Until that can be fixed, mark the tools as wrong.

Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit 2b9f2d2cb7)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 14:13:22 -07:00
Ryan Lee
40d7eeec32 parser: add a detached mount equality test
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
(cherry picked from commit 63857a7972)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 14:11:12 -07:00
Ryan Lee
17adb705a9 parser: add detached move mounts to simple tests
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
(cherry picked from commit 315d999013)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 14:11:12 -07:00
Ryan Lee
18245d5e3a regression: uncomment the detached keyword mount tests
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
(cherry picked from commit d4f75cec2b)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 14:11:12 -07:00
John Johansen
20aa4a3ee2 parser: add special casing for detached move mounts
upsteam move_mount mediation now allows for a detached (disconnected)
mount to be move mounted into a namespace.

Add support for this by detecting 'detached' as a keyword for the
source/device and using it to create a null match. Because existing
mount encoding using a null separator between the mount terms null
match followed by the null seperator will separate detached mounts
within the existing encoding.

Eg.
  mount detached -> /destination,
  mount options=(ro) fstype=ext4 detached -> /destination,

This is functionally equivalent to using

  mount "" -> /destination,

However using "" does not provide any context that about what the rule is allowing or why so the 'detached' form is preferred.

This is not a perfect solution, but is what can be currently supported
by the kernel without more LSM hooks.

On kernels that don't support detached mount detection, rules using
the detached souce conditional will be ignored (never matched).

This encoding also allows the existing

  mount,
  mount options=(move),
  mount options=(move) -> /destination,

to continue to work with both detached and regular mounts on kernels
that support the move_mount() syscall.

Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit fa0746f2e2)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 14:11:12 -07:00
John Johansen
b4b6e8103a Merge util: enhance AARE file path validation
Fixes https://bugs.launchpad.net/apparmor/+bug/2106033

Improve the validation of AARE file paths by introducing a new regex
that supports paths starting with '{' (e.g. '{/,/org/freedesktop/DBus}').
These paths are notably used in snap.lxd.* profiles.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1607
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 3b3dada5d9)
2025-04-06 14:06:55 -07:00
Maxime Bélair
e6c9371a2a util: enhance AARE file path validation
Fixes https://bugs.launchpad.net/apparmor/+bug/2106033

Improve the validation of AARE file paths by introducing a new regex
that supports paths starting with '{' (e.g. '{/,/org/freedesktop/DBus}').
These paths are notably used in snap.lxd.* profiles.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
(cherry picked from commit dbf4c27154)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 14:06:54 -07:00
John Johansen
ef74bce3b6 Merge Use the $(AWK) variable for the awk binary in the Makefiles
Followup that replaces !1576.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1581
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit f11c2032da)
2025-04-06 13:45:12 -07:00
Ryan Lee
14e03dcf40 Use the $(AWK) variable for the awk binary in the Makefiles
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
(cherry picked from commit 8beac326a5)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 13:45:12 -07:00
John Johansen
f9c90d57af Merge Fix typo in aa-exec manpage
Follow-up of https://gitlab.com/apparmor/apparmor/-/merge_requests/1570, which was merged without fixing this.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1583
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit a3d3a96ec5)
2025-04-06 13:43:38 -07:00
Christian Boltz
204cce791f Fix typo in aa-exec manpage
(cherry picked from commit 8c12d358b0)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 13:43:38 -07:00
John Johansen
262743cdc5 Merge utils/test/test-aa-notify.py: update last cmd for lxd VMs
When doing testing via LXD VMs and in particular when using "lxc exec" to run
commands in the VM, there is no controlling tty and so the output of last is
missing this column of data. Instead try even harder to parse the timestamp from
the output of "last".

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1582
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit e030ff7ea9)
2025-04-06 04:36:02 -07:00
Alex Murray
d7563e745d utils/test/test-aa-notify.py: update last cmd for lxd VMs
When doing testing via LXD VMs and in particular when using "lxc exec" to run
commands in the VM, there is no controlling tty and so the output of last is
missing this column of data. Instead try even harder to parse the timestamp from
the output of "last".

Signed-off-by: Alex Murray <alex.murray@canonical.com>
(cherry picked from commit b6654416b0)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 04:36:02 -07:00
John Johansen
2af2fb935b Merge: Merge Add ncurses abstraction with terminfo paths
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1550
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Ryan Lee <rlee287@yahoo.com>
(cherry picked from commit a82b16f059)
Signed-off-by: John Johansen <john.johansen@canonical.com>

Merge branch 'cherry-pick-a82b16f05928a565fc07141630f452ee3921a99b' into apparmor-4.1
2025-04-06 04:28:41 -07:00
Ryan Lee
953d384691 Replace terminfo lines in profiles with the terminfo abstraction
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
(cherry picked from commit 1b87b7be5e)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 04:25:46 -07:00
Ryan Lee
13d6779c0b Add terminfo abstraction with terminfo paths searched by ncurses
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
(cherry picked from commit c45ce5502e)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 04:24:58 -07:00
John Johansen
1e5adc354b Merge utils: don't skip disabled profiles for aa-enforce
When running aa-disable and then aa-enforce passing the binary path as
the argument, aa-enforce fails to enforce the profile with the error:

$ sudo aa-disable /home/foo/test
skipping disabled profile test
Profile for /home/foo/test not found, skipping

According to the man page for aa-enforce, it should work for disabled
profiles.

Note that this does not happen when passing the profile directly to
the tools, so there's a workaround for this issue:

$ sudo /aa-enforce /etc/apparmor.d/test
Setting /etc/apparmor.d/test to enforce mode.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1579
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit 819802cdb3)
2025-04-06 03:49:59 -07:00
Georgia Garcia
2a78af408a utils: don't skip disabled profiles for aa-enforce
When running aa-disable and then aa-enforce passing the binary path as
the argument, aa-enforce fails to enforce the profile with the error:

$ sudo aa-disable /home/foo/test
skipping disabled profile test
Profile for /home/foo/test not found, skipping

According to the man page for aa-enforce, it should work for disabled
profiles.

Note that this does not happen when passing the profile directly to
the tools, so there's a workaround for this issue:

$ sudo /aa-enforce /etc/apparmor.d/test
Setting /etc/apparmor.d/test to enforce mode.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
(cherry picked from commit b0b45b01c0)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 03:49:59 -07:00
John Johansen
970a035e86 Merge utils: Improve regex for mount source and target
* Make glob_pattern more readable
    - replace filename and variable regex parts with RE_PROFILE_PATH_OR_VAR
    - split to multiline string

* Move `[\w-]+` into inner match group by removing/moving the ')' after the empty source.

* Prepare source_fileglob_pattern and dest_fileglob_pattern to be customizable by moving adding the closing ')))' into each of them.

* Allow empty source and any word only in mount source

See the individual commits for details.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1574
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>

(cherry picked from commit e065dfb35a)
2025-04-06 03:48:35 -07:00
Christian Boltz
1b2f46ab11 Allow empty source and any word only in mount source
(cherry picked from commit ae20b62c31)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-06 03:48:34 -07:00