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

1809 Commits

Author SHA1 Message Date
John Johansen
d94ff137ef Merge parser: enable create perm when label is defined
Due to how labeling is implemented, during the creation it is not yet
defined, so we need to grant create permissions without attaching the
label yet. Also, adjust tests to pass when label support is
implemented in the kernel.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1623
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-05-12 08:00:11 +00:00
John Johansen
e6bedaac1d Merge parser: fix handling of norelatime mount rule flag
Specifying norelatime should set the corresponding MS_RELATIME flag clear
bit. Instead, it ORed in MS_NORELATIME, which expands to 0. Properly set
the clear bit by using MS_RELATIME.

Fixes: c9e31b7f "Add mount rules"

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1679
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-05-08 08:50:39 +00:00
John Johansen
330d202586 Merge branch 'master' into 'override'
# Conflicts:
#   parser/libapparmor_re/expr-tree.h
2025-05-07 23:04:59 +00:00
John Johansen
ec2549be2a Merge refactor(bison): replace deprecated name-prefix with %define api.prefix
%name-prefix is deprecated in Bison 2.6.  
<https://savannah.gnu.org/news/?id=7269>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1668
Approved-by: Ryan Lee <rlee287@yahoo.com>
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-05-07 22:54:06 +00:00
John Johansen
b50ec6ca36 Merge fix: avoid using namespace std; in header files
using directive in a header file is a bad practice because it may lead
to unexpected results.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rs-using-directive

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1664
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-05-07 22:53:26 +00:00
John Johansen
06e349345e parser: fix failure to properly apply deny clearing in perms accumulation
The internal permission accumulation is currently broken in that
the ordering of rules matter to whether deny is clearing accumulated
perms.

If a deny node comes before an allow node the deny bits will get set
but the following allow bits won't get cleared by the deny node.

This isn't currently an actual issue for mediation as the deny
bit will be applied at one of
  1. apply_and_clear_deny
  2. permission remapping
  3. run time mediation

but it does result in the internal state having sometimes having both
allow and deny bits set, dependent on order of computation, resulting
in state machines with different sizes because minimization
partitioning is based on the internal permissions.

This means that dfa minimization may not result in a truly minimal
state machine, and even worse can cause inconsistenty and failure in
tests that rely on internal state like the equality and minimization
test, as seen in https://gitlab.com/apparmor/apparmor/-/issues/513

The failure was due to musl stl sets implementation producing a
different ordering of the nodes than glibc. So when the permissions
where accumulated the internal set of permissions were different.

Fix this by giving the different node classes their own internal priority.
This will ensure the bits are properly cleared for that priority before
accumulating.

Note: other ways of fixing.

1. Fixup internal accumulation to use accumulating perms of "higher"
   priority as part of the mask (deny and allow mask prompt).
2. Do a hard masking apply at the end after all bits have been accumulated
   (ie, in accept_perms after the for loop).

the priority route was chosen because it is a little smaller and
scales better if we get new Node types we have to deal with
(eg. planned complain node).

BugLink: https://gitlab.com/apparmor/apparmor/-/issues/513
Fixes: 1ebd99115 ("parser: change priority so that it accumulates based on permissions")
Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-05-07 01:41:59 -07:00
Ryan Lee
711bbac5eb parser: fix handling of norelatime mount rule flag
Specifying norelatime should set the corresponding MS_RELATIME flag clear
bit. Instead, it ORed in MS_NORELATIME, which expands to 0. Properly set
the clear bit by using MS_RELATIME.

Fixes: c9e31b7f "Add mount rules"

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-05-06 16:01:53 -07:00
Ryan Lee
7d33bde1ea Merge Split priority rules with unsafe keyword to separate tests
This helps to limit the amount of rules skipped in the utils tests
(because the utils don't support the `unsafe` keyword)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1671
Approved-by: Maxime Bélair <maxime.belair@canonical.com>
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Ryan Lee <rlee287@yahoo.com>
2025-05-06 08:40:32 -07:00
Ryan Lee
3b1819db37 fix incorrect mount flag documentation in apparmor.d man page
The documentation was wrong about how options=(list) and options in (list) are combined

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-05-05 17:16:06 -07:00
Christian Boltz
94c5cf047f
Split priority rules with unsafe keyword to separate tests
This helps to limit the amount of rules skipped in the utils tests
(because the utils don't support the `unsafe` keyword)
2025-05-05 20:53:53 +02:00
Ryan Lee
17ee87ad6b 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>
2025-05-05 10:12:29 -07:00
Eisuke Kawashima
5526138483
fix(inconsistent-missing-override): add missed override specifiers 2025-05-05 17:52:52 +09:00
Eisuke Kawashima
18c0d003ef
fix(non-virtual-dtor): add missed virtual destructor 2025-05-05 17:52:48 +09:00
Eisuke Kawashima
9c6ae3cf5c
refactor(bison): replace deprecated name-prefix with %define api.prefix
%name-prefix is deprecated in Bison 2.6.
https://savannah.gnu.org/news/?id=7269
2025-05-05 17:47:29 +09:00
Eisuke Kawashima
7d5a021023
fix: avoid using namespace std; in header files
using directive in a header file is a bad practice because it may lead
to unexpected results.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rs-using-directive
2025-05-04 23:14:36 +09:00
Eisuke Kawashima
b50f516a78
chore: fix vim modelines
- set filetype, instead of syntax, in vim modelines
- replace filetype of subdomain with apparmor
- move modelines in the first or last five lines of each file so that
  vim can recognize them
2025-05-04 23:01:43 +09:00
John Johansen
fcd814bc51 parser: Dump more partition debug information
We need to be able to dump the initial partition assignments, and then
the partitions after minimization but before remapping to be able to
check on what is being done by minimization.

Add these as part of -D dfa-minimize-partitions

Ideally we would rework the code so that the existing mininimization
dump could share the dump routine but, its interwined with computation
state and information is thrown away before reaching the end.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-30 01:19:13 -07:00
John Johansen
d4a76c456d Merge profiles: force read permission to their attachment path
Unconfined delegates access to open file descriptors. Therefore when running a confined binary from unconfined, it will work even when the attachment path is not read-allowed.

However, as soon as these confined binaries are run from another confined process, this delegation is not permitted anymore and the program breaks.

This has been the cause of several bugs such as https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2107455 or https://github.com/canonical/snapd/pull/15181 .

This MR makes sure every confining AppArmor profiles explicitly allow (at least) read access to their attachment path.

This Merge request:
 - Introduce `test_profile.sh`, a helper script that ensures confining AppArmor profiles explicitly allow (at least) read access to their attachment path.
 - Modifies a lot of profiles so that all profiles have r/mr access to their attachment path
 - Extends `make check` to automatically ensure all AppArmor profile grant explicit read access to their attachment path, preventing future omissions.
 - Modifies apparmor_parser to show attachment in --debug output

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1637
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-04-28 12:02:18 +00:00
John Johansen
e3840b0dad parser: fix rlimit ofile when built on musl libc
glibc defines bsd's rlimit ofile as nofile, however musl.

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>
2025-04-22 23:26:54 -07:00
Maxime Bélair
68c0dddf23 Add a script to verify attachment-path permissions
Unconfined delegates access to open file descriptors. Therefore when
running a confined binary from unconfined, it will work even when the
attachment path is not read-allowed.

However, as soon as these confined binaries are run from another
confined process, this delegation is not permitted anymore and the
program breaks.

This has been the cause of several bugs such as
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2107455 or
https://github.com/canonical/snapd/pull/15181 .

Introduce `test_profile.sh`, a helper script that ensures confining
AppArmor profiles explicitly allow (at least) read access to their
attachment path.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-04-18 12:41:54 +02:00
Maxime Bélair
5d7fe96fd0 apparmor_parser: show attachment in --debug output
When showing the content of profiles with `apparmor_parser --debug`, the
attachment path is now displayed within the 'Debugging built structures'
section.

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2025-04-18 10:26:20 +02:00
Georgia Garcia
b718c53b97 parser: add label to mqueue debug output
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-04-14 09:48:15 -03:00
Georgia Garcia
306b656ba2 parser: enable create perm when label is defined
Due to how labeling is implemented, during the creation it is not yet
defined, so we need to grant create permissions without attaching the
label yet.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-04-14 09:48:10 -03:00
John Johansen
f34a7d0b28 Merge parser: add an abi <default> that is equivalent to not specifying an abi
I am unsure how to test this equivalency due to how abi declarations interact with feature file command line arguments, so advice on that would be welcome.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1585
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-04-12 10:30:28 +00:00
John Johansen
491def4385 parser: make abi=<kenrel> respect the command line specied kernel features
Currently abi=<kernel> always grabs the kernels actual features but
it should respect --kernel-features=. This is causing the simple
tests to fail when abi=<kernel> is specified.

Fix it so abi=<kernel> respects the kernel abi specified in the configs
or on the command line.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-04-12 03:07:53 -07:00
Ryan Lee
fe9c305ccd Move the "unsafe" rules of front_perms_ok simple tests to separate test file
This enables us to exercise the front perms parse logic in the utils rule parsing through the simple tests as well

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-04-10 11:19:05 -07:00
John Johansen
541c8ad94d Merge 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.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1617
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2025-04-08 09:32:56 +00:00
John Johansen
89e8fe9c1c 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>
2025-04-07 03:07:06 -07:00
Christian Boltz
b5894687ed
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.
2025-04-06 15:19:30 +02:00
Christian Boltz
171e0b1fa9
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.
2025-04-06 15:19:01 +02:00
Ryan Lee
63857a7972 parser: add a detached mount equality test
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-04-05 00:19:09 -07:00
Ryan Lee
315d999013 parser: add detached move mounts to simple tests
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-04-05 00:19:09 -07:00
John Johansen
fa0746f2e2 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>
2025-04-05 00:19:09 -07:00
John Johansen
3b3dada5d9 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>
2025-04-02 18:03:09 +00:00
Ryan Lee
6da10ef98f parser: move equality tests not using priorities outside of priority helper
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-04-02 10:10:03 -07:00
Ryan Lee
1f32c1175e parser: move error count print of equality tesets to run_tests end
The original location in the middle of the priority function helper was
completely nonsensical. We can instead do this check just once after
running all the tests.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-04-02 10:10:03 -07:00
Maxime Bélair
dbf4c27154 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>
2025-04-02 18:32:03 +02:00
Tim McCormack
b398ec61c9 Fix attach_disconnected typo in docs 2025-03-27 19:30:25 -04:00
Ryan Lee
64b920607b parser: add abi <default> to the apparmor.d man page
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-03-20 11:03:28 -07:00
Ryan Lee
94ed11edff parser: add abi <kernel> to the ABI grammar of apparmor.d.pod man page
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-03-20 10:49:17 -07:00
Ryan Lee
4473a42af7 parser: add abi <default> as a simple test
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-03-20 10:31:25 -07:00
Ryan Lee
ad3ecbd60a parser: add abi <kernel> as a simple test
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-03-20 10:31:17 -07:00
Ryan Lee
c9c29f02b1 parser: add an abi <default> that is equivalent to not specifying an abi
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-03-19 17:24:34 -07:00
John Johansen
f11c2032da 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>
2025-03-19 05:18:45 +00:00
Ryan Lee
8beac326a5 Use the $(AWK) variable for the awk binary in the Makefiles
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
2025-03-18 09:28:52 -07:00
Georgia Garcia
541d3f4489 parser: add attach_disconnected.ipc parser tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-03-13 14:51:18 -03:00
Georgia Garcia
d9b3603f48 parser: add support for attach_disconnected.ipc flag
The attach_disconnected.ipc flag allows the use of disconnected paths
on posix mqueues. This flag is a subset of attach_disconnected, and it
does not allow disconnected paths for all files.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2025-03-13 14:51:18 -03:00
Ryan Lee
dbe13a0b9d Merge Avoid blhc "CPPFLAGS missing" false positive
Similarly to apparmor/apparmor!403, we don't really need to pass these flags
here, but if we don't, blhc raises a false positive, and I don't want to get
used to ignoring blhc failures on Debian's GitLab CI.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1558
Approved-by: Alex Murray <alex.murray@canonical.com>
Approved-by: Ryan Lee <rlee287@yahoo.com>
Merged-by: Ryan Lee <rlee287@yahoo.com>
2025-02-24 17:02:27 +00:00
John Johansen
2a87a92136 Import translations from launchpad
This imports translations from launchpad up to commit

revno: 2523
committer: Launchpad Translations on behalf of apparmor-dev
branch nick: apparmor
timestamp: Fri 2025-02-21 09:32:26 +0000
message:
  Launchpad automatic translations update.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2025-02-24 01:28:04 -08:00
intrigeri
187c244056 Avoid blhc "CPPFLAGS missing" false positive
Similarly to apparmor/apparmor!403, we don't really need to pass these flags
here, but if we don't, blhc raises a false positive, and I don't want to get
used to ignoring blhc failures on Debian's GitLab CI.
2025-02-20 22:35:37 +00:00