Commit graph

7075 commits

Author SHA1 Message Date
Maxime Bélair
60acc4a405 MountRule: Aligning behavior with apparmor_parser
Mount Rules with options in { remount, [make-] { [r]unbindable, [r]shared, [r]private, and [r]slave }} do not support specifying a source. This commit aligns utils implementation to apparmor_parser's, which prohibits having a both source and a destination simultaneously, instad of just prohibiting source.

Therefore, both `mount options=(unbindable) /a,` and `mount options=(unbindable) -> /a,` are now supported (and equivalent for apparmor_parser). However, `mount options=(unbindable) /a -> /b,` is invalid.

For the same reason, specifying a fstype in these cases is also prohibited.

Similarly, we prohibit to specify a fstype for bind mount rules.

Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2065685

Signed-off-by: Maxime Bélair <maxime.belair@canonical.com>
2024-05-21 15:45:51 +02:00
Christian Boltz
a4df6cba6a
Add support for asking about pivot_root to aa-logprof 2024-05-20 20:45:19 +02:00
Christian Boltz
a15a33474d
Use PivotRootRule and PivotRootRuleset
... for handling pivot_root rules.

This replaces the old code that just stores the full rule as text.

We also get rid of the old ['allow'] and ['deny'] items in
ProfileStorage, the handling of old write functions, and the last usage
of _Raw_Rule (and therefore _Raw_Rule itsself).

Also delete the old test-pivot_root_parse.py which relied on the ancient
code, and even used a wrong syntax in its test rules.
2024-05-20 20:44:19 +02:00
Christian Boltz
c48f7b625a
Add PivotRootRule class
... and tests for it.
2024-05-20 20:42:50 +02:00
Christian Boltz
b65fbda092
Add 'details' labeled section to RE_PROFILE_PIVOT_ROOT 2024-05-20 20:42:47 +02:00
Christian Boltz
c8b53b07b8 Merge utils: replace pyflakes3 with flake8 to improve python checks
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1235
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-05-20 18:41:31 +00:00
Georgia Garcia
e511b05c59 utils: switch pyflakes3 to flake8 to improve python checks
The following exceptions were added to flake8 since they have several
expected uses in the tools and their tests:

E501: Line lengths are recommended to be no greater than 79 characters.
E241: Multiple spaces after ','
W503: Line break occurred before a binary operator

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-20 13:56:37 -03:00
Georgia Garcia
cec9ae6dff utils: fix coding style to match PEP8
Annotate exceptions with '  # noqa: ERROR'

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-20 13:56:37 -03:00
Christian Boltz
e1bda6d1a2 Merge ProfileStorage: incldue profile header in __repr__()
ProfileStorage knows a whole profile, therefore it should also include the profile header in `__repr__()`.

Also add a test for this.

While on it, add a test for an invalid type change for a type that doesn't have special handling in `__setitem__()` to increase test coverage.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1233
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-05-17 14:02:45 +00:00
Christian Boltz
5936c775ef Merge Drop unused Raw_Mount_Rule and Raw_Unix_Rule
These are no longer needed because we have MountRule and UnixRule
classes now.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1230
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-05-17 14:01:37 +00:00
Georgia Garcia
e1de0bb5d5 Merge Add fcitx5 dbus interface to fcitx abstraction
Similar reference in snapd https://github.com/snapcore/snapd/pull/12924

Reference upstream implementation: 

https://github.com/fcitx/fcitx/blob/master/src/frontend/ipcportal/ipcportal.h
https://github.com/fcitx/fcitx5/blob/master/src/frontend/dbusfrontend/dbusfrontend.cpp

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1222
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-17 12:47:21 +00:00
Georgia Garcia
452f7fa739 Merge libapparamor: Define a portable version of gnu basename
Since musl 1.2.5, basename(3) prototype is only provided in libgen.h
(as mandated by POSIX) and not in strings.h. Also there is a major
difference between the gnu basename and the one defined in libgen.h,
the latter modify the argument string making them incompatible.

Fix this by defining a portable version of basename using strchr.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1234
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-17 07:16:04 +00:00
Jules Maselbas
7fb040bde6 libapparamor: Define a portable version of gnu basename
Since musl 1.2.5, basename(3) prototype is only provided in libgen.h
(as mandated by POSIX) and not in strings.h. Also there is a major
difference between the gnu basename and the one defined in libgen.h,
the latter modify the argument string making them incompatible.

Fix this by defining a portable version of basename using strchr.
2024-05-16 21:22:23 +02:00
Christian Boltz
74316fe152 Merge Include abi/4.0 when creating a new profile
... with aa-genprof or aa-autodep

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

I propose this patch for 4.0 and master.

Closes #392
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1231
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-05-14 19:11:10 +00:00
Christian Boltz
6c8ef381e6
Include abi/4.0 when creating a new profile
... with aa-genprof or aa-autodep

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/392
2024-05-14 20:55:59 +02:00
Christian Boltz
eb3550c1b4
ProfileStorage: test invalid type change
... for a type that doesn't have special handling in __setitem__()
2024-05-12 12:37:41 +02:00
Christian Boltz
c5f301f976
ProfileStorage: incldue profile header in __repr__()
ProfileStorage knows a whole profile, therefore it should also include
the profile header in __repr__().

Also add a test for this.
2024-05-12 12:36:09 +02:00
Georgia Garcia
48a936e985 Merge Handle mount events/log entries without class
audit.log entries for mount events don't always include `class=mount`,
but can still be the base for mount rules.

Change logparser.py to also consider `operation=mount` as a mount event.

Actually we already had such a log and profile in our collection
(testcase_mount_01), but since it existed years before MountRule was
implemented, it was excluded in test-libapparmor-test_multi.py.
Therefore we didn't notice that it failed to produce a profile rule when
MountRule was introduced.

Remove testcase_mount_01 from the list of known failures so that it gets
tested - and fix the syntax error in the hand-written
testcase_mount_01.profile.

Also add testcase_mount_02 which is a mount event without fstype,
srcname and class.

I propose this fix for 4.0 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1229
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-10 12:31:30 +00:00
Christian Boltz
498cc08232
Drop unused Raw_Mount_Rule and Raw_Unix_Rule
These are no longer needed because we have MountRule and UnixRule
classes now.
2024-05-09 13:02:34 +02:00
Christian Boltz
b475ed0dec
Handle mount events/log entries without class
audit.log entries for mount events don't always include `class=mount`,
but can still be the base for mount rules.

Change logparser.py to also consider `operation=mount` as a mount event.

Actually we already had such a log and profile in our collection
(testcase_mount_01), but since it existed years before MountRule was
implemented, it was excluded in test-libapparmor-test_multi.py.
Therefore we didn't notice that it failed to produce a profile rule when
MountRule was introduced.

Remove testcase_mount_01 from the list of known failures so that it gets
tested - and fix the syntax error in the hand-written
testcase_mount_01.profile.

Also add testcase_mount_02 which is a mount event without fstype,
srcname and class.
2024-05-08 21:56:42 +02:00
Christian Boltz
d9207e39eb Merge Profile updates from testing on Ubuntu 24.04/noble
Did some testing on a fresh post-release image of noble, and uncovered some new denials:

#### Xorg

`2024-05-06T19:55:36.782484-04:00 image-ubuntu64 kernel: audit: type=1400 audit(1715039736.765:174): apparmor="DENIED" operation="link" class="file" profile="Xorg" name="/tmp/.X0-lock" pid=1366 comm="Xorg" requested_mask="r" denied_mask="r" fsuid=0 ouid=0 target="/tmp/.tX0-lock"`

#### chromium_browser

`2024-05-06T21:17:09.674963-04:00 image-ubuntu64 kernel: audit: type=1400 audit(1715040834.256:168): apparmor="DENIED" operation="userns_create" class="namespace" profile="chromium_browser" pid=2133 comm="chromium" requested="userns_create" denied="userns_create"`

#### firefox

`2024-05-06T21:33:09.387356-04:00 image-ubuntu64 kernel: audit: type=1400 audit(1715045589.369:505): apparmor="DENIED" operation="userns_create" class="namespace" profile="firefox" pid=3610 comm="firefox" requested="userns_create" denied="userns_create"`

`2024-05-06T21:36:48.911280-04:00 image-ubuntu64 kernel: audit: type=1400 audit(1715045808.884:682): apparmor="DENIED" operation="open" class="file" profile="firefox" name="/sys/fs/cgroup/user.slice/user-1000.slice/session-c2.scope/cpu.max" pid=4348 comm="firefox" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0`

`2024-05-06T21:42:34.152955-04:00 image-ubuntu64 dbus-daemon[1628]: apparmor="DENIED" operation="dbus_bind"  bus="session" name="org.mpris.MediaPlayer2.firefox.instance_1_82" mask="bind" pid=4348 label="firefox"`


#### Xorg (second commit)

I neglected to set `abi/4.0` when this went in originally. (I was using the profile on jammy, hence the `3.0`.)

Also, testing on an older laptop that *doesn't* support KMS revealed that Xorg needs some pretty serious permissions then. I've added them in commented-out form, with an explanatory comment. (The `#nokms#` bit is meant to simplify uncommenting those two lines mechanically, e.g. `sed -i 's/#nokms#//'`)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1227
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-05-08 18:35:53 +00:00
Daniel Richard G
ebc24ffbe2 Xorg: Bump ABI to 4.0, and document access needed on non-KMS systems 2024-05-08 03:48:32 -04:00
Daniel Richard G
d13f4b4417 profiles: updates from testing on Ubuntu 24.04/noble 2024-05-08 03:48:14 -04:00
Weng Xuetian
8605e68674
Add fcitx5 dbus interface to fcitx abstraction
The new dbus interface is using session bus and supported by both fcitx4
& fcitx5.
2024-05-06 23:34:45 -07:00
John Johansen
644aea8fc1 Merge Adjust alpha/beta versions for setuptools
Latest python setuptools don't accept a `~` in the version, and fail the
build. Replace `~` with `-` to avoid this.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1217
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-05-06 16:02:36 +00:00
Steve Beattie
0135bd1176 utils/tests/: Merge Don't rely on argparse saying "options:"
Some argparse versions (for example on openSUSE Leap 15.5) instead say
"optional arguments:"

Don't rely on the "options:" line to allow both wordings.

I propose this patch for 4.0 and master.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1226
Approved-by: Steve Beattie <steve+gitlab@nxnw.org>
Merged-by: Steve Beattie <steve+gitlab@nxnw.org>
2024-05-06 10:17:38 +00:00
Christian Boltz
715cb711ba
Don't rely on argparse saying "options:"
Some argparse versions (for example on openSUSE Leap 15.5) instead say
"optional arguments:"

Don't rely on the "options:" line to allow both wordings.
2024-05-05 22:05:43 +02:00
Georgia Garcia
d605463b66 Merge profiles: fix location for wike profile and add unconfined profile for balena-etcher
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1221
Approved-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-02 18:23:25 +00:00
Georgia Garcia
70125895f3 profiles: add unconfined balena-etcher profile
Balena Etcher runs in a degraded sandbox mode when unprivileged userns
is not available. Add an unconfined profile so it's properly
sandboxed.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-02 08:56:32 -03:00
Georgia Garcia
a5a1ecfe5c profiles: fix wike profile location to apparmor.d
Fixes: e7c5796a ("profiles: add unconfined wike profile")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-05-02 08:56:32 -03:00
Steve Beattie
8c9ac7a84e Merge gitlab-ci.yml: fix pipeline for ubuntu:latest (noble)
Since we are using ubuntu:latest, and noble was released, some tests
are failing.

shellcheck needs python3 to run, which was possibly installed by
default in previous ubuntu images and is no longer the case.

Ignore dist-packages python files during our coverage tests.

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

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

Closes #388
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1223
Merged-by: Steve Beattie <steve+gitlab@nxnw.org>
2024-04-30 23:24:38 +00:00
Georgia Garcia
aaad725ac0 apparmor.systemd: fix shellcheck false positive
Shellcheck is complaining that some of the functions are never called,
but they are called from rc.apparmor.functions, causing a false
positive.

This issue only appears in shellcheck version 0.9.0, which is the one
used in ubuntu 24.04, that's why it only failed in the pipeline now.

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

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-04-30 18:30:01 -03:00
Georgia Garcia
731880def8 gitlab-ci.yml: fix pipeline for ubuntu:latest (noble)
Since we are using ubuntu:latest, and noble was released, some tests
are failing.

shellcheck needs python3 to run, which was possibly installed by
default in previous ubuntu images and is no longer the case.

Ignore dist-packages python files during our coverage tests.

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

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-04-30 17:58:21 -03:00
Christian Boltz
dc3bd62c74 Merge NetworkRule: Add support for fine-grained mediation rules
Adding the support for access, local expression and peer expression in network rules

Example of fine-grained rule: `network (connect, rw) stream ip=192.168.122.2 port=22 peer=(ip=192.168.122.3 port=22),`

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1216
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-04-23 20:07:19 +00:00
Maxime Bélair
5b08e06186 NetworkRule: Add support for fine-grained mediation rules 2024-04-23 20:07:19 +00:00
John Johansen
1457eada8b Merge profiles: add fixes for samba from issue #386
Signed-off-by: Alex Murray <alex.murray@canonical.com>

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/386
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1219
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-04-22 23:46:45 +00:00
Alex Murray
f6bba7bccc profiles: add fixes for samba from issue #386
squash 2nd patch addressing issue in original patch in MR to have a clean MR.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/386
2024-04-22 23:46:44 +00:00
John Johansen
79226675fd Merge Fix redefinition of _
... which unsurprisingly broke using the translations.

This was a regression introduced in 4f51c93f9d

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

This fix is needed in 4.0 and master. (3.x branches are not affected.)

Closes #387
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1218
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-04-22 23:41:26 +00:00
John Johansen
99d22c447e Merge parser: add error=EXX flag support
Add a flag that allows setting the error code AppArmor will send when
an operation is denied. This should not be used normally.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1215
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-04-22 23:33:49 +00:00
Christian Boltz
6f9e841e74
Fix redefinition of _
... which unsurprisingly broke using the translations.

This was a regression introduced in 4f51c93f9d

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/387
2024-04-21 19:02:17 +02:00
Christian Boltz
405da7aa33
Adjust alpha/beta versions for setuptools
Latest python setuptools don't accept a '~' in the version, and fail the
build. Replace '~' with '-' to avoid this.
2024-04-21 17:22:18 +02:00
John Johansen
a07a0f4428 Fix version, changing from beta0 to alpha0
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-04-18 14:45:31 -07:00
John Johansen
71b869bf16 Update Version on master branch
Update the match branch version to reflect that it is now develeopment
for the 4.1 release.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-04-18 14:43:18 -07:00
Daniel Richard G
e4a395b620 profiles/Makefile: Clean up rules to better support extra profiles
Rename the "check-extras" target to "check-local" as it is no longer
limited to the extra profiles, and also fix a local include in the
sbuild-shell profile so that it passes the newly-applied CI check.
2024-04-16 01:57:16 -04:00
Georgia Garcia
aee0492491 parser: add error=EXX flag support
Add a flag that allows setting the error code AppArmor will send when
an operation is denied. This should not be used normally.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-04-15 16:32:16 -03:00
John Johansen
678d6294d7 Merge Add profile for Xorg (X server)
This is a profile to contain the Xorg X11 server, which still runs as root in many scenarios (not least under [LightDM](https://github.com/canonical/lightdm/issues/18)).

I've tested this under every X display manager available in Debian/Ubuntu, as well as plain `startx(1)`. Both rootful and rootless modes are covered. The hardware I've tried this on predominantly uses Intel integrated graphics, with one Nouveau system represented. If someone has an Nvidia GPU running the proprietary driver, that would be a good data point to double-check, owing to the different driver architecture.

As you can see, I avoided going too far into the weeds enumerating everything the X server needs to run. The general pattern I found was that it needs read access to a lot of things, but write access to relatively few.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1075
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-04-12 04:03:03 +00:00
John Johansen
93c4c6fb9f Merge regression tests: add mount test for CVE-2016-1585
Add infrastructure for calling the mount test binary with an fstype
instead of using the default hardcoded ext2 type, and then use that in a
test that exercises CVE-2016-1585, ensuring that mounting a procfs
filesystem isn't permitted when the only mount rule is

  mount options=(rw,make-slave) -> **,

to try to ensure that the generated and enforced policy is restricted to
what is intended.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1597017

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1211
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-04-12 03:57:35 +00:00
John Johansen
ab9e6311f3 Merge parser: add network inet mediation documentation to apparmor.d
This updates the man page for the recent inet mediation patch.

This is an extension of MR 1202, it adds a patch that changes the anonymous ip address anon to be ip address none which is a better fit.

This patch adds documentation of the recent network changes which extended all network rules to support access permissions, and added address and port matching for inet and inet6 families.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1213
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-04-12 03:46:23 +00:00
John Johansen
689df6d3cd switch inet mediation from using anon to none
inet mediation allows specifying rules for sockets that don't have
a known address, whether because it is unbound or because the
kernel doesn't make the address available.

The current code uses the word anon for anonymous, but that has
proven to be unclear. Switch from using anon to none, to emphasize
that this is a case where there just isn't an address to use as
part of mediation.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-04-11 19:03:43 -07:00
John Johansen
3c43c314dc Merge profiles: add unconfined wike profile
Wike (deb package/compiled version) does not run in Ubuntu 24.04
due to some interference between apparmor and webkit.

Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2060810
Signed-off-by: John Johansen <john.johansen@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1212
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-04-11 22:59:58 +00:00