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

Compare commits

...

152 Commits

Author SHA1 Message Date
John Johansen
353ba896d4 Prepare for AppArmor 4.0 beta2 release
- update version file

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-03-06 17:06:45 -08:00
John Johansen
c13007f7fc Merge libapparmor: check if AX_CHECK_COMPILE_FLAG is available
The error message when autoconf-archive is not installed is not very
intuitive:

```
./configure: line 14422: EXTRA_WARNINGS: command not found
./configure: line 14423: syntax error near unexpected token `-flto-partition=none,'
./configure: line 14423: `AX_CHECK_COMPILE_FLAG(-flto-partition=none, , , -Werror)'
```

So, check if AX_CHECK_COMPILE_FLAG is defined and if not, complain
that autoconf-archive is missing.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1174
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-03-06 21:21:54 +00:00
John Johansen
88a420853e Merge parser: fix policy generation for non-af_inet rules
The layout for AF_INET and AF_INET6 rules were being applied to all
families, which causes failures in their mediation.

Fixes: ddefe11a ("parser: add fine grained conditionals to network rule")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1175
Merged-by: John Johansen <john@jjmx.net>
2024-03-06 21:19:21 +00:00
Georgia Garcia
2db41acd1b parser: fix generic perms in network rules
The permission for network rules when the inet mediation was not
available, or for when the family was not af_inet or af_inet6 was
being generated as one that would allow anything. Make them specific
using perms.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-06 10:33:54 -03:00
Georgia Garcia
a10d9044b8 parser: fix policy generation for non-af_inet rules
The layout for AF_INET and AF_INET6 rules were being applied to all
families, which causes failures in their mediation.

Fixes: ddefe11a ("parser: add fine grained conditionals to network rule")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-06 10:07:17 -03:00
Christian Boltz
b53441a689 Merge Update ancient paths in apparmor and apparmor.d manpage
- replace example calls of /etc/init.d/apparmor with apparmor.service
- drop /etc/init.d/apparmor in filelist
- replace /var/lib/apparmor/ with /var/cache/apparmor/

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1171
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-06 12:24:13 +00:00
Christian Boltz
7452f34279 Update ancient paths in apparmor and apparmor.d manpage
- replace example calls of /etc/init.d/apparmor with apparmor.service
- drop /etc/init.d/apparmor in filelist
- replace /var/lib/apparmor/ with /var/cache/apparmor/
2024-03-05 22:59:18 +01:00
Georgia Garcia
aedb8a5b00 libapparmor: check if AX_CHECK_COMPILE_FLAG is available
The error message when autoconf-archive is not installed is not very
intuitive:

./configure: line 14422: EXTRA_WARNINGS: command not found
./configure: line 14423: syntax error near unexpected token `-flto-partition=none,'
./configure: line 14423: `AX_CHECK_COMPILE_FLAG(-flto-partition=none, , , -Werror)'

So, check if AX_CHECK_COMPILE_FLAG is defined and if not, complain
that autoconf-archive is missing.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 10:27:34 -03:00
Christian Boltz
6695944c2c Merge utils: fix coding style in mount
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1173
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-04 13:05:41 +00:00
Georgia Garcia
01090dcf1b utils: fix coding style in mount
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 09:24:58 -03:00
Georgia Garcia
3ea2bfec56 Merge Small fixes in MountRule
- Removed unnecessary variable source_is_path in mount rules
- Changed a string to a r-string to avoid an 'invalid escape sequence \s' warning

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1172
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:53:51 +00:00
Georgia Garcia
3d1a867c0a Merge Update mailinglist and homepage in changehat READMEs
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1170
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:53:10 +00:00
Georgia Garcia
dfb02cbd93 Merge MountRule: check for unknown fstype and options keywords, and fix issues uncovered by that
* **MountRule: sync flags_keywords with parser code**

    ... based on /mount.cc mnt_opts_table

    Several keywords and aliases were missing in flags_keywords:
    - B
    - M
    - make-private
    - make-rprivate
    - make-rshared
    - make-rslave
    - make-runbindable
    - make-shared
    - make-slave
    - make-unbindable
    - r
    - R
    - read-only
    - w

    Also sort the keywords in the same order as in mount.cc.

    Note: AARE handling is still a TODO.

    After that, update the list of known parsing failures:
    - several valid profiles are now correctly parsed
    - some `"make-*" mount opt and an invalid src` bad profiles are no
      longer detected as being invalid

* **test-mount.py: fix MountRule instance creation**

    If fstype or options is a str, it has to be exactly one keyword, because
    \__init__() / check_and_split_list() won't parse a str.

    Our "normal" code already honors this, and only hands over fstype and
    options as sets or a single-keyword str.

    However, a few tests (wrongly) handed over a str that would need further
    parsing. Adjust the tests to no longer do this.

* **MountRule: check for unknown fstype and options**

    ... now that the previous commits fixed issues that ended up as unknown
    keywords.

    Also add mount/ok_12.sd as known-failing test. It uses fstype=AARE which
    MountRule doesn't support (yet?).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1169
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:52:53 +00:00
Georgia Garcia
90f056c1c6 Merge Several MountRule fixes and improvements
* Fix writing 'mount {options,fstype} in ...' rules

We need spaces around the 'in' keyword.

Also add some tests for this.

* Make error check more readable

* MountRule: make get_clean() more readable

... by getting rid of two mostly-identical, big return statements.

Also add tests for bare umound and remount rules to ensure full test
coverage.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1168
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-04 11:52:33 +00:00
Maxime Bélair
0daf3e8c9b Changing string to r-string to avoid warning 2024-03-04 09:02:24 +01:00
Maxime Bélair
a86c1bd45a Remove unnecessary variable source_is_path in mount rules 2024-03-04 09:00:58 +01:00
Christian Boltz
8f4073ecd9 MountRule: check for unknown fstype and options
... now that the previous commits fixed issues that ended up as unknown
keywords.

Also add mount/ok_12.sd as known-failing test. It uses fstype=AARE which
MountRule doesn't support (yet?).
2024-03-03 21:30:49 +01:00
Christian Boltz
440be71c12 Update mailinglist and homepage in changehat READMEs 2024-03-03 18:12:06 +01:00
Christian Boltz
8d21f01924 test-mount.py: fix MountRule instance creation
If fstype or options is a str, it has to be exactly one keyword, because
__init__() / check_and_split_list() won't parse a str.

Our "normal" code already honors this, and only hands over fstype and
options as sets or a single-keyword str.

However, a few tests (wrongly) handed over a str that would need further
parsing. Adjust the tests to no longer do this.
2024-03-03 15:52:14 +01:00
Christian Boltz
4e546291a5 MountRule: sync flags_keywords with parser code
... based on /mount.cc mnt_opts_table

Several keywords and aliases were missing in flags_keywords:
- B
- M
- make-private
- make-rprivate
- make-rshared
- make-rslave
- make-runbindable
- make-shared
- make-slave
- make-unbindable
- r
- R
- read-only
- w

Also sort the keywords in the same order as in mount.cc.

Note: AARE handling is still a TODO.

After that, update the list of known parsing failures:
- several valid profiles are now correctly parsed
- some `"make-*" mount opt and an invalid src` bad profiles are no
  longer detected as being invalid
2024-03-03 15:37:59 +01:00
Christian Boltz
8c026077d6 MountRule: make get_clean() more readable
... by getting rid of two mostly-identical, big return statements.

Also add tests for bare umound and remount rules to ensure full test
coverage.
2024-03-03 13:09:43 +01:00
Christian Boltz
5e4c4a0cb3 Make error check more readable 2024-03-03 12:53:49 +01:00
Christian Boltz
9c27a7c435 Fix writing 'mount {options,fstype} in ...' rules
We need spaces around the 'in' keyword.

Also add some tests for this.
2024-03-03 12:49:57 +01:00
Christian Boltz
a367c07437 Merge Add useful error message in test-mount.py
If /proc/filesystems contains a filesystem that is not listed in
MountRule valid_fs, print a useful error message that says what exactly
is going on, instead of only saying "False is not True".

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1166
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-01 21:30:33 +00:00
Christian Boltz
2200013088 Merge Cleanup old handling of mount rules
Now that we have MountRule and MountRuleset, drop the old "just store
the whole rule" code for mount rules.

Also drop some old tests that used that "store the whole mount rule"
code, and adjust the regex_matches tests to import the regex directly
from apparmor.regex.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1165
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-01 21:29:48 +00:00
Christian Boltz
d5afc33c40 Merge MountRule: Fix typo in 'btrfs', and add '9p' filesystem
The `9p` filesystem is available during the build in build.opensuse.org.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1164
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-01 21:27:44 +00:00
Christian Boltz
517e7c96c8 MountRule: add '9p' filesystem
This filesystem is available during the build in build.opensuse.org
2024-03-01 21:36:26 +01:00
Christian Boltz
a7cd59819e Add useful error message in test-mount.py
If /proc/filesystems contains a filesystem that is not listed in
MountRule valid_fs, print a useful error message that says what exactly
is going on, instead of only saying "False is not True".
2024-03-01 20:34:11 +01:00
Christian Boltz
e7f5ee3271 MountRule: Fix typo in 'btrfs' 2024-03-01 19:49:21 +01:00
Christian Boltz
da75b1c8d8 Cleanup old handling of mount rules
Now that we have MountRule and MountRuleset, drop the old "just store
the whole rule" code for mount rules.

Also drop some old tests that used that "store the whole mount rule"
code, and adjust the regex_matches tests to import the regex directly
from apparmor.regex.
2024-03-01 19:46:02 +01:00
Georgia Garcia
b264bb62c9 Prepare for AppArmor 4.0 beta1 release
- update version file
- update library version

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 19:24:53 -03:00
John Johansen
35287c8e1c Merge add fine grained network mediation support
Similar to https://gitlab.com/apparmor/apparmor/-/merge_requests/1095, but this time simplified.
This version removes support for ip and port ranges and subnets. This can be added later.

It also contains an updated version of the network layout required by the kernel side of AppArmor.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1160
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-29 21:58:24 +00:00
Georgia Garcia
119e3f38f9 parser: maintain compatibility for fine grained inet network mediation
A simple rule without conditionals need to be generated for when the
kernel does not support fine grained inet network mediation.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 18:27:20 -03:00
Georgia Garcia
dd0d145a19 tests: add fine grained network regression tests 2024-02-29 17:09:19 -03:00
Georgia Garcia
f6ad1cbe1e tests: add multi string support in requires_parser_support
By not having quotes in $@, the string splits by the whitespace.
That prevents us from checking if the parser supports rules
that have spaces in them.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 16:25:59 -03:00
Georgia Garcia
8a5e7227db parser: add parser tests for specified perms
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 16:25:59 -03:00
Georgia Garcia
79ee3eb180 parser: add parser tests for local conditional 2024-02-29 16:25:59 -03:00
Georgia Garcia
052dd987b3 parser: add network conditional parser tests 2024-02-29 16:25:59 -03:00
Georgia Garcia
7e25be7b0b parser: change network conditionals to allow unquoted ids
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 16:25:59 -03:00
Georgia Garcia
ddefe11a40 parser: add fine grained conditionals to network rule
Options available are ip= and port= inside the peer group or outside,
representing local addresses and ports:

network peer=(ip=127.0.0.1 port=8080),
network ip=::1 port=8080 peer=(ip=::2 port=8081),

The 'ip' option supports both IPv4 and IPv6. Examples would be
ip=192.168.0.4, or ip=::578d

The 'port' option accepts a 16-bit unsigned integer. An example would
be port=1234

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 16:25:59 -03:00
John Johansen
b83cf90b82 Merge Fix some DENIES for smbd when honouring pam restrictions
with smbd.conf param 'obey pam restrictions = yes'

on tumbleweed we get some new DENIES (which can prevent login)

e.g.

type=AVC msg=audit(1709113104.674:533): apparmor="DENIED" operation="exec" class="file" profile="smbd" name="/usr/sbin/unix_chkpwd" pid=3509 comm="smbd[127.0.0.1]" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:345): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/usr/etc/security/limits.d/" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:346): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/proc/3746/loginuid" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:347): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/usr/etc/environment" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1220032

Signed-off-by: Noel Power <noel.power@suse.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1159
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-29 18:00:40 +00:00
John Johansen
e3cb9e1669 Merge Adding userspace support for mount rules in aa-genprof/aa-logprof
Adding userspace support for mount rules in aa-genprof/aa-logprof

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1153
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-29 17:59:51 +00:00
Maxime Bélair
924b335dfc Adding userspace support for mount rules in aa-genprof/aa-logprof 2024-02-29 17:59:50 +00:00
John Johansen
a2da64304f Merge profiles: add nautilus unconfined profile
Nautilus uses user namespaces to load thumbnails, hence it needs an
unconfined profile when user namespaces are restricted from unconfined
like other applications in MR #1123

Although nautilus has extensions that would allow opening a terminal
from the nautilus interface, they do not inherit nautilus' AppArmor
label, therefore the use of unconfined does not allow arbitrary use of
unprivileged user namespaces using the nautilus label.

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify them instead
of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

Fixes: https://bugs.launchpad.net/bugs/2047256
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1161
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-29 12:02:44 +00:00
Georgia Garcia
bb53886211 profiles: add nautilus unconfined profile
Nautilus uses user namespaces to load thumbnails, hence it needs an
unconfined profile when user namespaces are restricted from unconfined
like other applications in MR #1123

Although nautilus has extensions that would allow opening a terminal
from the nautilus interface, they do not inherit nautilus' AppArmor
label, therefore the use of unconfined does not allow arbitrary use of
unprivileged user namespaces using the nautilus label.

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify them instead
of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

Fixes: https://bugs.launchpad.net/bugs/2047256
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 08:21:25 -03:00
Georgia Garcia
746f76d3e1 parser: add ability to specify permission in network rules
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-28 21:42:18 -03:00
Georgia Garcia
35f25a251b parser: fix coverity issues found in snapshot 70858
This commit add fixes for issues found in coverity's snapshot 70858.
  - CID 323127:  Performance inefficiencies  (COPY_INSTEAD_OF_MOVE)
  - CID 323125:  Uninitialized members  (UNINIT_CTOR)

I'm also removing Novell, Inc. from the copyright notice added by a
copy-paste error, and an unused variable left over from debugging.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-28 10:24:08 -03:00
Noel Power
c09f58a364 Fix some DENIES for smbd when honouring pam restrictions
with smbd.conf param 'obey pam restrictions = yes'

on tumbleweed we get some new DENIES (which can prevent login)

e.g.

type=AVC msg=audit(1709113104.674:533): apparmor="DENIED" operation="exec" class="file" profile="smbd" name="/usr/sbin/unix_chkpwd" pid=3509 comm="smbd[127.0.0.1]" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:345): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/usr/etc/security/limits.d/" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:346): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/proc/3746/loginuid" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
type=AVC msg=audit(1709110904.602:347): apparmor="DENIED" operation="open" class="file" profile="smbd" name="/usr/etc/environment" pid=3746 comm="smbd[127.0.0.1]" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1220032

Signed-off-by: Noel Power <noel.power@suse.com>
2024-02-28 09:59:55 +00:00
Christian Boltz
909e330fd0 Merge aa-notify: precompile filter regexes
Precompile each filter regex with re.compile so they don't need to be
recompiled for each log message when using re.match directly.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1158
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-02-26 17:15:26 +00:00
Georgia Garcia
88907253e4 aa-notify: precompile filter regexes
Precompile each filter regex with re.compile so they don't need to be
recompiled for each log message when using re.match directly.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-26 10:24:46 -03:00
Christian Boltz
124e73ec93 Merge profiles: update visual studio code so that it can be run from gnome
The current attachment works from the commandline but not from
gnome as it uses an alternate path.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/368
Signed-off-by: John Johansen <john.johansen@canonical.com>

Closes #368
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1156
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-02-25 10:11:30 +00:00
John Johansen
4b1bc85022 Merge aa-unconfined: Fix race when reading proc/*/attr/current
aa-unconfined can fault if it looses the race between checkking if
proc/*/attr/{apparmor/,}current exists, and actually opening the file.
Catch open/file errors and ignore them like the file doesn't exist.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/355
Signed-off-by: John Johansen <john.johansen@canonical.com>

Closes #355
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1157
Acked-by: seth.arnold@gmail.com
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-25 07:36:16 +00:00
John Johansen
c4f649da92 aa-unconfined: Fix race when reading proc/*/attr/current
aa-unconfined can fault if it looses the race between checkking if
proc/*/attr/{apparmor/,}current exists, and actually opening the file.
Catch open/file errors and ignore them like the file doesn't exist.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/355
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-02-24 20:33:35 -08:00
John Johansen
108f489f2b profiles: update visual studio code so that it can be run from gnome
The current attachment works from the commandline but not from
gnome as it uses an alternate path.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/368
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-02-24 20:27:13 -08:00
John Johansen
4d2172e82e Merge aa-notify: add notification filtering
Allow notification filtering of the fields profile, operation, name,
denied_mask, net_family and net_socket using regex. Both command line
and config options in notify.conf are available.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1154
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-25 04:07:00 +00:00
John Johansen
95d9ba8d8b Merge makefiles: test for support of flto-partition flag
Test for compiler support of "-flto-partition=none" flag before passing
it.

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

Closes #310
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1155
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-25 03:31:01 +00:00
Félix Poisot
420d3395fc makefiles: test for support of flto-partition flag
Test for compiler support of "-flto-partition=none" flag before passing
it.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/310
2024-02-24 16:07:55 +00:00
Georgia Garcia
4608d32628 aa-notify: add notification filtering
Allow notification filtering of the fields profile, operation, name,
denied_mask, net_family and net_socket using regex. Both command line
and config options in notify.conf are available.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-23 17:20:18 -03:00
John Johansen
2394ca82c5 Merge utils: fix aa-notify last login test
The tests for aa-notify that were related to the last login were
assuming that the machine had been logged in at least once in the last
30 days, but that might not be the case.

Update the test to check for the last login date and update the test
logs considering that value.

Fixes: https://bugs.launchpad.net/bugs/1939022

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1152
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-21 22:38:35 +00:00
Georgia Garcia
105b50502b utils: fix aa-notify last login test
The tests for aa-notify that were related to the last login were
assuming that the machine had been logged in at least once in the last
30 days, but that might not be the case.

Update the test to check for the last login date and update the test
logs considering that value.

Fixes: https://bugs.launchpad.net/bugs/1939022

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-21 18:18:26 -03:00
John Johansen
105bdfdeb9 Merge fix test failures on regex, exec and userns.
Failures on regex and exec are related to /usr/bin and /bin merge.
The userns failure is related to the addition of the unprivileged_userns
profile and the kernel ability to transition to it when an unconfined
unprivileged user namespace is created.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1146
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-21 13:22:03 +00:00
John Johansen
f9d38c9b2c Merge binutils: fix aa-status filters help message
The help message from aa-status referenced -h filter when it should
have been -h filters. Also added some whitespaces for consistency.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1151
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-21 13:18:00 +00:00
Georgia Garcia
3ea050eb30 binutils: fix aa-status filters short help message
The short form of the help parameter was not accepting an optional
argument as described in the help message. Update the help message to
remove the extra whitespace in between -h and the options since
getopt(1) says that

"If the option has an optional argument, it must be written directly
after the option character if present."

even though that's not described in getopt(3).

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-21 09:58:16 -03:00
Georgia Garcia
b49822a48d binutils: fix aa-status filters help message
The help message from aa-status referenced -h filter when it should
have been -h filters. Also added some whitespaces for consistency.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-21 09:37:36 -03:00
Georgia Garcia
32bba24468 Merge add element-desktop unconfined profile
element-desktop needs to use user namespaces, hence it needs an unconfined profile when user namespaces are restricted from unconfined
like other applications in MR #1123

!1123

In addition this serves as a handle to uniquely identify them instead
of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
!1109
is merged.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1150
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-20 12:38:27 +00:00
Maxime Bélair
fd25954c56 add element-desktop unconfined profile 2024-02-20 12:38:26 +00:00
John Johansen
ca3afe1691 Merge add more unconfined profiles
These applications need to use user namespaces, hence it needs an
unconfined profile when user namespaces are restricted from unconfined
like other applications in MR #1123

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify them instead
of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1149
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-02-07 09:37:08 +00:00
Christian Boltz
2577fbf077 Merge abstractions/openssl: allow version specific engdef & engines paths
Some openssl distributions use version specific engdef and engines paths
to support multi-version installations.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1219571

Signed-off-by: David Disseldorp <ddiss@suse.de>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1147
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-02-07 08:49:58 +00:00
David Disseldorp
2b8cf1be80 abstractions/openssl: allow version specific engdef & engines paths
Some openssl distributions use version specific engdef and engines paths
to support multi-version installations.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1219571
Signed-off-by: David Disseldorp <ddiss@suse.de>
2024-02-07 10:31:34 +11:00
Georgia Garcia
89a9f76733 add more unconfined profiles
These applications need to use user namespaces, hence it needs an
unconfined profile when user namespaces are restricted from unconfined
like other applications in MR #1123

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify them instead
of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-06 15:10:20 -03:00
Georgia Garcia
4621af8ead tests: handle unprivileged_userns transition in userns tests
There is a kernel feature, available under
namespaces/userns_create/pciu&, that enables the transition of
unconfined tasks to a special profile called unprivileged_userns when
they try to create an unprivileged user namespace with
clone/unshare. This transition allows the creation of the unprivileged
user namespace but hinders its privileges by not allowing
capabilities. Refer to the unprivileged_userns profile to check what
rules are allowed.

If either the feature is not present in the kernel, or the
unprivileged_userns profile is not loaded, then the defined behavior
is to deny the creation of the unprivileged user namespace

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-06 09:04:59 -03:00
Georgia Garcia
668f5af436 tests: fix usr-merge failures on exec and regex tests
Some of the tests are failing because of /usr/bin/true vs /bin/true.
Similarly to what was done in 8c09b328, to make the tests more
reliable, copy the true binary to $tmpdir and use this path on the
tests instead.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-06 09:04:59 -03:00
Georgia Garcia
48d475036a Merge add keybase unconfined profile
Keybase needs to use user namespaces, hence it needs an unconfined
profile when user namespaces are restricted from unconfined like other
applications in MR #1123

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify keybase
instead of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1145
Approved-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-02 21:23:34 +00:00
Georgia Garcia
0e378f52a8 add keybase unconfined profile
Keybase needs to use user namespaces, hence it needs an unconfined
profile when user namespaces are restricted from unconfined like other
applications in MR #1123

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify keybase
instead of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-02 16:53:58 -03:00
Georgia Garcia
15337db4af Prepare for AppArmor 4.0 alpha 4 release
- update version file

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-02 15:21:41 -03:00
Georgia Garcia
ce3c97df0f Merge add profiles for applications that create user namespaces
These are profiles for applications that create user namespaces, both
the actual policy and unconfined profiles, like it was done in MR
1123.

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify these
applications instead of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1144
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-02 18:18:40 +00:00
Georgia Garcia
789cda2f08 add special unprivileged_userns profile
Unprivileged user namespace creation is allowed an will result in a
transition into the unprivileged_userns profile. The
unprivileged_userns profile with then deny all capabilities within the
profile. Execution of applications is allowed within the
unprivileged_userns profile but, they will result in a stack with the
unprivileged_userns profile, that is to say the unprivileged_userns
profile can not be dropped (capabilities can not be gained).

If the unprivileged_userns profile does not exist, unprivileged user
namespace creation is denied as before.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-02 10:52:26 -03:00
Georgia Garcia
6add80d83f add profiles for applications that create user namespaces
These are profiles for applications that create user namespaces, both
the actual policy and unconfined profiles, like it was done in MR
1123.

https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify these
applications instead of unconfined to peers in policy.

Note that unconfined mode should be changed for default_allow when
https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is merged.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-02 10:51:06 -03:00
John Johansen
3e28d0a254 Merge doc(fix): Fix wrong syntax for profile stacking
Add missing change_profile entry required for the example

Signed-off-by: Mostafa Emami <mustafaemami@gmail.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1141
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-01-30 09:45:36 +00:00
John Johansen
e63c1e3a76 Merge Prevent ANSI terminal injection in aa-unconfined
/proc/$pid/cmdline can be changed by an application, therefore escape it
before printing.

The program name in /proc/$pid/exe can also contain any characters
(except \0 and shashes) and needs escaping.

Note: repr() wraps the string into single quotes, which we have to
remove to avoid changing the output format.

The test program from issue 364 now gets displayed as

    28443 /path/to/issue364 (/\x1b]0;X\x07) not confined

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

I propose this patch for 2.13..master

Closes #364
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1142
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-01-30 09:43:23 +00:00
John Johansen
b03abbd75f Merge manpages: Add ENOPROTOOPT error in aa_getcon() manpage
The call aa_getpeercon() can return ENOPROTOOPT error in some cases, specifically when the kernel lacks 'fine grained unix mediation'. Currently, this capability isn't available in upstream kernels, but only in patched ones (for example, the regular Ubuntu kernels). Unfortunately, the manpage lacks this info. This patch fixes this.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/366
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1143
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-01-30 09:33:48 +00:00
Sergio Costas
6e81104bbf manpages: Add ENOPROTOOPT error in aa_getcon() manpage 2024-01-30 09:33:47 +00:00
Christian Boltz
6cc3a3642d Prevent ANSI terminal injection in aa-unconfined
/proc/$pid/cmdline can be changed by an application, therefore escape it
before printing.

The program name in /proc/$pid/exe can also contain any characters
(except \0 and shashes) and needs escaping.

Note: repr() wraps the string into single quotes, which we have to
remove to avoid changing the output format.

The test program from issue 364 now gets displayed as

    28443 /path/to/issue364 (/\x1b]0;X\x07) not confined

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/364
2024-01-20 23:42:30 +01:00
Mostafa Emami
166ebdb3bc doc(fix): Fix wrong syntax for profile stacking
Add missing change_profile entry required for the example

Signed-off-by: Mostafa Emami <mustafaemami@gmail.com>
2024-01-17 22:15:41 +01:00
John Johansen
253eace573 Merge tests: parse result of multiple lines in output
There are some tests like attach_disconnected and posix_mq that can
have a program that calls another. For example, posix_mq_rcv calls
posix_mq_snd. Both of them write to the same output file, but the code
that checks the result expects only one line. This change enables
checking multiple lines in the output file and passing or failing
accordingly.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1140
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-01-17 10:28:15 +00:00
Georgia Garcia
c2487f017f tests: cleanup debugging message from unix_fd_server.sh
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-01-15 17:51:49 -03:00
Georgia Garcia
dc73f0fc0b tests: parse result of multiple lines in output
There are some tests like attach_disconnected and posix_mq that can
have a program that calls another. For example, posix_mq_rcv calls
posix_mq_snd. Both of them write to the same output file, but the code
that checks the result expects only one line. This change enables
checking multiple lines in the output file and passing or failing
accordingly.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-01-15 17:51:49 -03:00
Georgia Garcia
3578b07aeb Merge tests: fix move_mount test failure caused by returned error
The move_mount tests were returning -1 in case of failure causing it
to become 255 in some systems, but checktestbg in the testsuite
considers any return value greater than 128 to be a signal error.
That would cause tests that should fail to display the following test
error:
... was expected to 'fail'. Reason for failure 'killed by
signal 127'

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1139
Approved-by: Steve Beattie <steve+gitlab@nxnw.org>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-01-12 21:39:48 +00:00
Georgia Garcia
28e67c7ba8 tests: fix move_mount test failure caused by returned error
The move_mount tests were returning -1 in case of failure causing it
to become 255 in some systems, but checktestbg in the testsuite
considers any return value greater than 128 to be a signal error.
That would cause tests that should fail to display the following test
error:
... was expected to 'fail'. Reason for failure 'killed by
signal 127'

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-01-12 17:12:43 -03:00
John Johansen
c8a2dc34d9 Merge firefox: remove owner restrictions for /proc/$pid/net/*
On openSUSE, these files are owned by root.

This partially reverts 70809fc716 / https://gitlab.com/apparmor/apparmor/-/merge_requests/1131

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1132
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-01-12 08:32:00 +00:00
John Johansen
350f9cf3dd Merge tests: add move_mount regression tests
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1138
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-01-12 08:31:17 +00:00
Georgia Garcia
f889f9f434 tests: add move_mount regression tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-01-04 18:18:58 -03:00
Georgia Garcia
5ca2ea3621 Merge ask_exec(): no longer skip exec events in hats
Instead of ignoring all exec events that happen in a hat/child profile,
only disallow child exec. ix and px are valid options inside a hat and
are now offered to the user.

(When the tools support nested child profiles one day, we can even allow
child exec again.)

[This MR is for master only. I opened separate MRs for 3.1 and 3.0]

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1133
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-01-03 13:38:33 +00:00
Christian Boltz
2c5bc5a09b Merge profiles: add brave browser to the snap_browsers abstraction
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1137
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-01-02 18:33:57 +00:00
Georgia Garcia
dc821ef762 profiles: add brave browser to the snap_browsers abstraction
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-01-02 15:25:49 -03:00
Christian Boltz
31c9cf6845 Merge regression tests: fix stack tests for new proc interface
the stacking tests need to be able to read and write the new apparmor
dir in proc, if that interface has been selected. Update the tests to
make sure they have the permissions needed.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1136
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-12-30 12:02:47 +00:00
John Johansen
66484687e8 regression tests: fix stack tests for new proc interface
the stacking tests need to be able to read and write the new apparmor
dir in proc, if that interface has been selected. Update the tests to
make sure they have the permissions needed.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-12-29 14:55:10 -08:00
Christian Boltz
dfb6f90aee ask_exec(): no longer skip exec events in hats
Instead of ignoring all exec events that happen in a hat/child profile,
only disallow child exec. ix and px are valid options inside a hat and
are now offered to the user.

(When the tools support nested child profiles one day, we can even allow
child exec again.)
2023-12-28 23:12:10 +01:00
Christian Boltz
fcd46063fd firefox: remove owner restrictions for /proc/$pid/net/*
On openSUSE, these files are owned by root.

This partially reverts 70809fc716 / https://gitlab.com/apparmor/apparmor/-/merge_requests/1131
2023-12-24 17:19:10 +01:00
John Johansen
f10e106a08 Merge parser: Add support for a default_allow mode
Add support for a default_allow mode that facillitates writing profiles
in that allow everything by default. This is not normally recomended
but fascilitates creating basic profiles while working to transition
policy away from unconfined.

This mode is being added specifically to replace the use of the
unconfined flag in these transitional profiles as the use of unconfined
in policy is confusing and does not reflect the semantics of what is
being done.

Generally the goal for policy should be to remove all default_allow
profiles once the policy is fully developed.

Note: this patch only adds parsing of default_allow mode. Currently
it sets the unconfined flag to achieve default allow but this
prevents deny rules from being applied. Once dominance is fixed a
subsequent patch will transition default_allow away from using
the unconfined flag.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1109
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-12-23 08:38:18 +00:00
John Johansen
d778fbef57 Merge firefox: add "owner" keywords, updates from usage monitoring
Happy holidays, been meaning to push these updates out for some time:

* Add `owner` keyword to several rules to tighten them up. I've tested these for several months in normal usage and encountered no denials;

* Add new DBus access rules for the following:

  ```
  Oct 18 06:26:06 darkstar kernel: [4369444.223230] audit: type=1107 audit(1697624766.349:2448): pid=745 uid=102 auid=4294967295 ses=4294967295 subj=unconfined msg='apparmor="DENIED" operation="dbus_signal"  bus="system" path="/org/freedesktop/login1" interface="org.freedesktop.DBus.Properties" member="PropertiesChanged" name=":1.1" mask="receive" pid=1484746 label="firefox" peer_pid=773 peer_label="unconfined"

  Oct 19 19:18:20 darkstar kernel: [4502177.573224] audit: type=1107 audit(1697757500.040:2456): pid=745 uid=102 auid=4294967295 ses=4294967295 subj=unconfined msg='apparmor="DENIED" operation="dbus_method_call"  bus="system" path="/org/freedesktop/login1" interface="org.freedesktop.DBus.Properties" member="GetAll" mask="send" name=":1.1" pid=1677547 label="firefox" peer_pid=773 peer_label="unconfined"

  Oct 19 19:18:20 darkstar kernel: [4502177.700071] audit: type=1107 audit(1697757500.168:2457): pid=745 uid=102 auid=4294967295 ses=4294967295 subj=unconfined msg='apparmor="DENIED" operation="dbus_method_call"  bus="system" path="/org/freedesktop/timedate1" interface="org.freedesktop.DBus.Properties" member="GetAll" mask="send" name=":1.5878" pid=1484746 label="firefox" peer_pid=1677582 peer_label="unconfined"
  ```

* Deny write access to `/etc/**`, due to this odd bit:
  ```
  Jul 27 15:23:21 darkstar kernel: [6530015.183715] audit: type=1400 audit(1690485801.308:128963): apparmor="DENIED" operation="mknod" profile="firefox" name="/etc/igfx_user_feature_next.txt" pid=2618266 comm="vaapitest" requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000
  ```

* Allow read access to a cgroup `cpu.max` variable. I lost the relevant log bit here, I'm afraid;

* Relocate the ptrace rule, as it relates to the crash reporter, not (as far as I've found) the Widevine plugin.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1131
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-12-23 08:36:47 +00:00
Daniel Richard G
70809fc716 firefox: add "owner" keywords, updates from usage monitoring
Also relocate the ptrace rule so it belongs to the crash reporter,
not the Widevine plugin
2023-12-22 19:25:01 -05:00
John Johansen
15d8e21945 Merge Fix typo in apparmor_parser manpage
man apparmor_parser gives examples for the --warn command line option as

             apparmor_parser --warn=rules-not-enforced ...
and
             apparmor_parser --warn=no-rules-not-enforced ...

but the actual --warn options are rule-not-enforced / no-rule-not-enforced
(without s)

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1057453

I propose this fix for 2.13..master

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1128
Merged-by: John Johansen <john@jjmx.net>
2023-12-05 12:43:08 +00:00
Christian Boltz
3ee47af402 Fix typo in apparmor_parser manpage
man apparmor_parser gives examples for the --warn command line option as

             apparmor_parser --warn=rules-not-enforced ...
and
             apparmor_parser --warn=no-rules-not-enforced ...

but the actual --warn options are rule-not-enforced / no-rule-not-enforced
(without s)

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1057453
2023-12-05 13:27:09 +01:00
John Johansen
eb6fa02251 Merge fix subprofile name in profile serialization
Given the following profile:
    
profile foo {
  profile bar {
    profile baz {
    }
  }
}
    
The parser would correctly serialize the "foo" profile and the
"foo//bar" profile, but it would incorrectly name "bar//baz" when it
should be "foo//bar//baz". This would cause issues loading the profile
in certain kernels causing a "parent does not exist" error.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1127
Merged-by: John Johansen <john@jjmx.net>
2023-12-04 09:09:32 +00:00
Georgia Garcia
923cbcf3be parser: fix subprofile name in profile serialization
Given the following profile:

profile foo {
  profile bar {
    profile baz {
    }
  }
}

The parser would correctly serialize the "foo" profile and the
"foo//bar" profile, but it would incorrectly name "bar//baz" when it
should be "foo//bar//baz". This would cause issues loading the profile
in certain kernels causing a "parent does not exist" error.

Partially addresses #346.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-12-01 16:14:19 -03:00
Georgia Garcia
78a2c9f5f3 parser: constify unchanged strings in sd_write_*
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-12-01 15:18:51 -03:00
Christian Boltz
81bc26c934 Merge add steam profile for applications in unconfined mode
Steam needs to use user namespaces, hence it needs an unconfined
profile when user namespaces are restricted from unconfined like other
applications in MR1123

  https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify stream
instead of unconfined to peers in policy.

    Note that unconfined mode should be changed for default_allow
    when https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is
    merged.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1125
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-11-26 16:30:41 +00:00
Christian Boltz
71e28e9357 Merge profiles: convert local include to match profile name
The recently added unconfined profiles use the binary name for the
local include instead of the profile name. Switch to using the
profile name for the local include.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1126
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-11-26 16:29:14 +00:00
John Johansen
7c684f9d22 profiles: convert local include to match profile name
The recently added unconfined profiles use the binary name for the
local include instead of the profile name. Switch to using the
profile name for the local include.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-11-24 18:53:51 -08:00
John Johansen
6c01b90c13 add steam profile for applications in unconfined mode
Steam needs to use user namespaces, hence it needs an unconfined
profile when user namespaces are restricted from unconfined like other
applications in MR1123

  https://gitlab.com/apparmor/apparmor/-/merge_requests/1123

In addition this serves as a handle to uniquely identify stream
instead of unconfined to peers in policy.

    Note that unconfined mode should be changed for default_allow
    when https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is
    merged.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-11-24 15:48:53 -08:00
John Johansen
832bb8f417 parser: Add support for a default_allow mode
Add support for a default_allow mode that facillitates writing profiles
in that allow everything by default. This is not normally recomended
but fascilitates creating basic profiles while working to transition
policy away from unconfined.

This mode is being added specifically to replace the use of the
unconfined flag in these transitional profiles as the use of unconfined
in policy is confusing and does not reflect the semantics of what is
being done.

Generally the goal for policy should be to remove all default_allow
profiles once the policy is fully developed.

Note: this patch only adds parsing of default_allow mode. Currently
it sets the unconfined flag to achieve default allow but this
prevents deny rules from being applied. Once dominance is fixed a
subsequent patch will transition default_allow away from using
the unconfined flag.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-11-24 15:38:19 -08:00
John Johansen
e0bc90f5cf Merge Add profiles for applications in unconfined mode
Adding profiles for applications even if they allow all operations
will allow them to be referenced as peer by other policies. This is
a step towards a more comprehensive system policy, adding names,
instead of just unconfined, to peers of existing policy and to
applications that are known to use unprivileged user namespaces.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1123
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-11-23 23:14:22 +00:00
John Johansen
6a96067938 Merge parser: fix regex parser leak on parsing failure
When the regex parser failed, the Chars objects created/used in rules
charset and cset_chars would not be cleaned up properly and would
leak.

Closes #361

Closes #361
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1124
Merged-by: John Johansen <john@jjmx.net>
2023-11-23 23:12:21 +00:00
Georgia Garcia
dcad01ccc3 parser: fix regex parser leak on parsing failure
When the regex parser failed, the Chars objects created/used in rules
charset and cset_chars would not be cleaned up properly and would
leak.

Closes #361

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-11-23 17:37:46 -03:00
Georgia Garcia
2594d936ad add profiles for applications in unconfined mode
Adding profiles for applications even if they allow all operations
will allow them to be referenced as peer by other policies. This is a
step towards a more comprehensive system policy, adding names, instead
of just unconfined, to peers of existing policy and to applications
that are known to use unprivileged user namespaces.

Note that unconfined mode should be changed for default_allow
when https://gitlab.com/apparmor/apparmor/-/merge_requests/1109 is
merged.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-11-23 10:34:20 -03:00
Christian Boltz
9bba464d93 Merge Allow reading /run/systemd/sessions/
Several applications use it now that utmp and wtmp are
being removed because they are not Y2038 compliant

This is the case for example in openSUSE Tumbleweed and
openSUSE MicroOS:
https://microos.opensuse.org/blog/2023-11-06-utmp-and-wtmp-are-gone/

Closes https://gitlab.com/apparmor/apparmor/-/issues/360

Closes #360

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1216878

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1121
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-11-08 18:16:47 +00:00
Julio Gonzalez Gil
96b1aa549b Allow reading /run/systemd/sessions/
Several applications use it now that utmp and wtmp are
being removed because they are not Y2038 compliant

This is the case for example in openSUSE Tumbleweed and
openSUSE MicroOS:
https://microos.opensuse.org/blog/2023-11-06-utmp-and-wtmp-are-gone/

Closes https://gitlab.com/apparmor/apparmor/-/issues/360
2023-11-08 18:13:03 +01:00
John Johansen
dcc719c69c Merge tests: fix regression tests to run on kernels that only have network_v8
upstream kernels only have network_v8 unfortunately the tcp tests were
only being run against kernels that had network (which is v7). Kernels
that support both (Ubuntu) would be tested against v8, so v8 has been
tested but pure upstream kernels were failing to be tested correctly.

This patch will only make sure one of the supported verserions are
tested. This is determined by the parser which prefers v8. In the
future the tests need to be extended to run the tests against all
kernel supported versions.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1120
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>
2023-11-08 14:24:13 +00:00
John Johansen
6304d372bf tests: fix regression tests to run on kernels that only have network_v8
upstream kernels only have network_v8 unfortunately the tcp tests were
only being run against kernels that had network (which is v7). Kernels
that support both (Ubuntu) would be tested against v8, so v8 has been
tested but pure upstream kernels were failing to be tested correctly.

This patch will only make sure one of the supported versions are
tested. This is determined by the parser which prefers v8. In the
future the tests need to be extended to run the tests against all
kernel supported versions.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-11-06 02:33:31 -08:00
John Johansen
54915dabc4 Merge Allow reading /etc/authselect/nsswitch.conf
On systems with authselect installed, /etc/nsswitch.conf is a symlink to
/etc/authselect/nsswitch.conf.

Fixes: https://gitlab.com/apparmor/apparmor-profiles/-/issues/13

I propose this patch for 3.0..master.

Closes apparmor-profiles#13
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1119
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-11-03 03:22:05 +00:00
John Johansen
d55a1e6d5d Merge Validate capabilities against list of known capabilities
Teach CapabilityRule about the list of known capabilities, and ensure that only valid capabilities are allowed in profiles.

This comes with several test additions (and removals from the `exception_not_raised` list for the parser simple_tests), see the individual commits for details.

Reviewing each commit on its own is probably easier than reading the merged diff.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1117
Merged-by: John Johansen <john@jjmx.net>
2023-11-03 03:09:46 +00:00
John Johansen
6580331625 Merge Add Documentation=... to apparmor.service
This is taken from Debian's apparmor.service, and is the first (and
easiest) step to get the upstream and Debian file closer.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1116
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-11-03 02:55:46 +00:00
John Johansen
1e7f63415a Merge ubuntu-browsers.d/kde: fix plasma-browser-integration
Out of the box the KDE plasma-browser-integration package does not work
after a user installed the corresponding Firefox extension: The browser
can't start the native host binary. The same is probably true for
Chromium.

This was originally reported to KDE at https://bugs.kde.org/show_bug.cgi?id=397399

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1115
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-11-03 02:51:36 +00:00
Christian Boltz
d4dff5ce4e Allow reading /etc/authselect/nsswitch.conf
On systems with authselect installed, /etc/nsswitch.conf is a symlink to
/etc/authselect/nsswitch.conf.

Fixes: https://gitlab.com/apparmor/apparmor-profiles/-/issues/13
2023-11-01 17:03:06 +01:00
Christian Boltz
86c05357cf Add test for unknown capability
Even if this is very unlikely to happen (because of the previously added
test, and because CapabilityRule only allows to specify known severity
keywords), ensure proper behaviour if an unknown severity gets rated.
2023-10-29 22:10:07 +01:00
Christian Boltz
f17bd59904 Test severity of all capabilities
... to ensure that they are all listed in severity.db
2023-10-29 22:10:07 +01:00
Christian Boltz
d38c7b22ce CapabilityRule: simplify and improve __init__()
- convert a string parameter to a list to avoid duplication of the
  validation logic
- add separate check for empty cap_list
- remove check for empty strings - the previous commit already added
  such a check to the for loop. Also, move the comment to that check.
2023-10-29 21:42:57 +01:00
Christian Boltz
942202da17 CapabilityRule: Validate given caps against cap list
... and error out if an unknown capability is given.

This also means recognizing bad capabilities in the parser simple_tests
now works (so remove these from the exception_not_raised list), and that
we can no longer hand over an unknown capability in test-capability.py
to test their severity.
2023-10-29 21:31:43 +01:00
Christian Boltz
5c34655f4a CapabilityRule: Add list of known capabilities
... and add a test to ensure that the list is/stays complete.
2023-10-29 21:28:13 +01:00
Christian Boltz
57ba373213 test-capability: use valid capability names
... instead of non-existing ones.

This is a search-and-replace commit:

ptrace -> sys_ptrace

chgrp -> fowner (because fowner wasn't used in the test before)
2023-10-29 21:23:00 +01:00
Christian Boltz
5d9d4483fb Add Documentation=... to apparmor.service
This is taken from Debian's apparmor.service, and is the first (and
easiest) step to get the upstream and Debian file closer.
2023-10-29 10:49:33 +01:00
Malte S. Stretz
8b95030665 ubuntu-browsers.d/kde: fix plasma-browser-integration
Out of the box the KDE plasma-browser-integration package does not work
after a user installed the corresponding Firefox extension: The browser
can't start the native host binary. The same is probably true for
Chromium.

This was originally reported to KDE at https://bugs.kde.org/show_bug.cgi?id=397399
2023-10-18 11:37:18 +02:00
John Johansen
58a89284d5 Merge tools.py: the big cleanup
tools.py contained quite some things that need a big cleanup.

See the individual commits for details and more readable diffs.

Note: This MR "only" does cleanups and some refactoring. It does not change the (user-visible) behaviour of the code.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1114
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-14 00:54:15 +00:00
John Johansen
28f336cb91 Merge abstractions: pipewire rt conf
Pipewire also uses the client-rt.conf file, add this to the audio abstraction.

See pipewire source: https://github.com/PipeWire/pipewire/blob/master/src/daemon/client-rt.conf.in

Hit this during normal usage of Firefox.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1113
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-14 00:05:21 +00:00
Antonius Mulder
61fc6805a9 abstractions: pipewire rt conf
Pipewire also uses the client-rt.conf file, add this to
the audio abstraction.
2023-10-13 13:06:42 -07:00
Christian Boltz
f2f24884c3 get_next_to_profile(): ensure all branches set all variables
This also means we can get rid of most cleanprof-specific conditions
without changing the behaviour (because the other functions don't use
'profile' yet).

Also hand over prof_filename to clean_profile() so that it doesn't need
to find it out itsself.
2023-10-12 13:44:04 +02:00
Christian Boltz
5d8347bc26 clean_profile(): re-order code
Error out early (avoids a tab level), and handle the short branch first
in the if condition.
2023-10-12 13:11:30 +02:00
Christian Boltz
0c595ac801 clean_profile(): rename filename to prof_filename
... for consistency with the variable name in all the other functions.
2023-10-12 13:08:13 +02:00
Christian Boltz
1d5f90efcd Rename profile variable to prof_filename
... if it contains the profile filename. This avoids confusion with the
"real" 'profile' variable that contains a profile name.
2023-10-12 13:04:29 +02:00
Christian Boltz
4f51c93f9d get_next_to_profile(): return profile and prof_filename
Before, the 'profile' return value was either a profile name or a
profile filename, depending on the active module (cleanprof vs.
everything else).

Separate the return values so that it's clear what we get.

Notes:
- This commit doesn't change functionality, only the number of return
  values and some variable names.
- There's no guarantee that all return values are set. They can also be
  None. (This might change in the future.)

Also adjust the callers of get_next_to_profile(), and rename 'profile'
to 'prof_filename' in calling functions that actually use the profile
filename.
2023-10-12 12:36:09 +02:00
Christian Boltz
4d1c17b426 Drop enable_profile() and disable_profile()
enable_profile() was unused.

disable_profile() was only used once, inline it into cmd_disable()
2023-10-12 12:36:09 +02:00
Christian Boltz
918a15e244 Merge common parts of mode changes into get_next_for_modechange() 2023-10-12 12:36:09 +02:00
Christian Boltz
fc8c7722a1 tools.py: call apparmor.read_profiles() in __init__()
... instead of calling it in every cmd_* function.
2023-10-12 12:36:05 +02:00
John Johansen
7eff621fc7 Merge parser/rc.apparmor: Handle Incus
Add init function support to skip incus prefixed policy like is done for lxc and lxd
 
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1112
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-12 05:52:40 +00:00
Stéphane Graber
659a187687 parser/rc.apparmor: Handle Incus
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
2023-10-12 00:55:03 -04:00
John Johansen
cee501349e Merge ProfileList: merge self.attachments_AARE into self.attachments['re']
Since the unittests now compare a dict that contains an AARE, this also needs:

AARE: add `__eq__()` to allow checking aare1 == aare2

... and add some tests for it

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1111
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-12 04:44:24 +00:00
Christian Boltz
27de7ea0c2 ProfileList: merge self.attachments_AARE into self.attachments['re'] 2023-10-11 20:39:37 +02:00
Christian Boltz
bfd72c93be AARE: add __eq__() to allow checking aare1 == aare2
... and add some tests for it
2023-10-11 20:38:38 +02:00
John Johansen
6ac0e0236b Merge Fix aa-cleanprof to work with named profiles
This needed replacement of "program" with "profile" at various places in
tools.py (of course this description is over-simplified).

The changes in get_next_to_profile() (which is used by several aa-*
minitools) are restricted to cleanprof to avoid side effects in the
other aa-* minitools.

However, the other aa-* minitools possibly also suffer from problems
with named profiles, but checking and fixing that is left for another
commit ;-)

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

.

The fix needs an additional function in ProfileList (`profile_from_attachment()`) to get the profile name for a given attachment.

Since this is not very different from filename_from_attachment(), move
most of the code into a thing_from_attachment() function, and make
{profile,filename}_from_attachment wrappers for it.

Also adjust the tests to the changed internal data structure, and add
tests for profile_from_attachment().

I propose this patch for 3.0..master. (3.0 will probably need a slightly different patch - I'll submit a separate MR once this MR is merged.)

Closes #351
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1108
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-10-10 03:55:12 +00:00
Christian Boltz
151bf26bb9 Fix aa-cleanprof to work with named profiles
This needed replacement of "program" with "profile" at various places in
tools.py (of course this description is over-simplified).

The changes in get_next_to_profile() (which is used by several aa-*
minitools) are restricted to cleanprof to avoid side effects in the
other aa-* minitools.

However, the other aa-* minitools possibly also suffer from problems
with named profiles, but checking and fixing that is left for another
commit ;-)

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/351
2023-10-08 20:01:27 +02:00
Christian Boltz
26903320fd ProfileList: add profile_from_attachment()
... to get the profile name for a given attachment.

Since this is not very different from filename_from_attachment(), move
most of the code into a thing_from_attachment() function, and make
{profile,filename}_from_attachment wrappers for it.

Also adjust the tests to the changed internal data structure, and add
tests for profile_from_attachment().
2023-10-08 15:25:55 +02:00
367 changed files with 6157 additions and 543 deletions

3
.gitignore vendored
View File

@@ -264,7 +264,10 @@ tests/regression/apparmor/link_subset
tests/regression/apparmor/mkdir
tests/regression/apparmor/mmap
tests/regression/apparmor/mount
tests/regression/apparmor/move_mount
tests/regression/apparmor/named_pipe
tests/regression/apparmor/net_finegrained_rcv
tests/regression/apparmor/net_finegrained_snd
tests/regression/apparmor/net_raw
tests/regression/apparmor/open
tests/regression/apparmor/openat

View File

@@ -17,7 +17,7 @@ stages:
- uname -a
.install-c-build-deps: &install-c-build-deps
- apt-get install --no-install-recommends -y build-essential apache2-dev autoconf automake bison dejagnu flex libpam-dev libtool pkg-config python3-all-dev python3-setuptools ruby-dev swig zlib1g-dev
- apt-get install --no-install-recommends -y build-essential apache2-dev autoconf autoconf-archive automake bison dejagnu flex libpam-dev libtool pkg-config python3-all-dev python3-setuptools ruby-dev swig zlib1g-dev
build-all:
stage: build

View File

@@ -773,8 +773,8 @@ static int print_usage(const char *command, bool error)
" --pretty-json same data as --json, formatted for human consumption as well\n"
" --verbose (default) displays data points about loaded policy set\n"
" --quiet don't output error messages\n"
" -h [(legacy|filter)] this message, or info on the specified option\n"
" --help[=(legacy|filter)] this message, or info on the specified option\n",
" -h[(legacy|filters)] this message, or info on the specified option\n"
" --help[=(legacy|filters)] this message, or info on the specified option\n",
command);
exit(status);
@@ -830,7 +830,7 @@ static int parse_args(int argc, char **argv)
};
// Using exit here is temporary
while ((opt = getopt_long(argc, argv, "+vh", long_opts, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "+vh::", long_opts, NULL)) != -1) {
switch (opt) {
case ARG_ENABLED:
exit(aa_is_enabled() == 1 ? 0 : AA_EXIT_DISABLED);

View File

@@ -67,10 +67,10 @@ to syslog.
References
----------
Project webpage:
http://developer.novell.com/wiki/index.php/Novell_AppArmor
https://apparmor.net/
To provide feedback or ask questions please contact the
apparmor-dev@forge.novell.com mail list. This is the development list
apparmor@lists.ubuntu.com mail list. This is the development list
for the AppArmor team.
See also: change_hat(3), and the Linux-PAM online documentation at

View File

@@ -188,10 +188,9 @@ parent context.
8. Feedback/Resources
-----------------
To provide feedback or ask questions please contact the
apparmor-dev@forge.novell.com mail list. This is the development list for the
AppArmor team.
Project webpage:
https://apparmor.net/
To provide feedback or ask questions please contact the
apparmor@lists.ubuntu.com mail list. This is the development list
for the AppArmor team.

View File

@@ -188,10 +188,9 @@ parent context.
8. Feedback/Resources
-----------------
To provide feedback or ask questions please contact the
apparmor-dev@forge.novell.com mail list. This is the development list for the
AppArmor team.
Project webpage:
https://apparmor.net/
To provide feedback or ask questions please contact the
apparmor@lists.ubuntu.com mail list. This is the development list
for the AppArmor team.

View File

@@ -1 +1 @@
4.0.0~alpha3
4.0.0~beta2

View File

@@ -92,6 +92,14 @@ if test "$ac_cv_prog_cc_c99" = "no"; then
AC_MSG_ERROR([C99 mode is required to build libapparmor])
fi
m4_ifndef([AX_CHECK_COMPILE_FLAG], [AC_MSG_ERROR(['autoconf-archive' missing])])
EXTRA_CFLAGS="-Wall $(EXTRA_WARNINGS) -fPIC"
AX_CHECK_COMPILE_FLAG([-flto-partition=none], , , [-Werror])
AS_VAR_IF([ax_cv_check_cflags__Werror__flto_partition_none], [yes],
[EXTRA_CFLAGS="$EXTRA_CFLAGS -flto-partition=none"]
,)
AC_SUBST([AM_CFLAGS], ["$EXTRA_CFLAGS"])
AC_OUTPUT(
Makefile
doc/Makefile

View File

@@ -116,6 +116,14 @@ The specified I<file/task> does not exist or is not visible.
The confinement data is too large to fit in the supplied buffer.
=item B<ENOPROTOOPT>
The kernel doesn't support the SO_PEERLABEL option in sockets. This happens
mainly when the kernel lacks 'fine grained unix mediation' support. It also
can happen on LSM stacking kernels where another LSM has claimed this
interface and decides to return this error, although this is really a
corner case.
=back
=head1 NOTES

View File

@@ -109,12 +109,12 @@ To immediately stack a profile named "profile_a", as performed with
aa_stack_profile("profile_a"), the equivalent of this shell command can be
used:
$ echo -n "stackprofile profile_a" > /proc/self/attr/current
$ echo -n "stack profile_a" > /proc/self/attr/current
To stack a profile named "profile_a" at the next exec, as performed with
aa_stack_onexec("profile_a"), the equivalent of this shell command can be used:
$ echo -n "stackexec profile_a" > /proc/self/attr/exec
$ echo -n "stack profile_a" > /proc/self/attr/exec
These raw AppArmor filesystem operations must only be used when using
libapparmor is not a viable option.
@@ -184,6 +184,7 @@ with apparmor_parser(8):
/etc/passwd r,
# Needed for aa_stack_profile()
change-profile -> &i_cant_be_trusted_anymore,
/usr/lib/libapparmor*.so* mr,
/proc/[0-9]*/attr/current w,
}

View File

@@ -33,9 +33,9 @@ INCLUDES = $(all_includes)
# After changing the AA_LIB_* variables, also update EXPECTED_SO_NAME.
AA_LIB_CURRENT = 18
AA_LIB_REVISION = 0
AA_LIB_REVISION = 1
AA_LIB_AGE = 17
EXPECTED_SO_NAME = libapparmor.so.1.17.0
EXPECTED_SO_NAME = libapparmor.so.1.17.1
SUFFIXES = .pc.in .pc
@@ -45,7 +45,6 @@ include $(COMMONDIR)/Make.rules
BUILT_SOURCES = grammar.h scanner.h af_protos.h
AM_LFLAGS = -v
AM_YFLAGS = -d -p aalogparse_
AM_CFLAGS = -Wall $(EXTRA_WARNINGS) -fPIC -flto-partition=none
AM_CPPFLAGS = -D_GNU_SOURCE -I$(top_srcdir)/include/
scanner.h: scanner.l
$(LEX) -v $<

View File

@@ -0,0 +1 @@
type=AVC msg=audit(1709108389.303:12383): apparmor="DENIED" operation="mount" class="mount" info="failed mntpnt match" error=-13 profile="/home/user/test/testmount" name="/tmp/foo/" pid=14155 comm="testmount" flags="ro, remount"

View File

@@ -0,0 +1,15 @@
START
File: testcase_remount_01.in
Event type: AA_RECORD_DENIED
Audit ID: 1709108389.303:12383
Operation: mount
Profile: /home/user/test/testmount
Name: /tmp/foo/
Command: testmount
Info: failed mntpnt match
ErrorCode: 13
PID: 14155
Flags: ro, remount
Class: mount
Epoch: 1709108389
Audit subid: 12383

View File

@@ -0,0 +1,4 @@
/home/user/test/testmount {
mount options=(remount, ro) -> /tmp/foo/,
}

View File

@@ -0,0 +1 @@
type=AVC msg=audit(1709025786.045:43147): apparmor="DENIED" operation="umount" class="mount" profile="/home/user/test/testmount" name="/mnt/a/" pid=26697 comm="testmount"

View File

@@ -0,0 +1,12 @@
START
File: testcase_umount_01.in
Event type: AA_RECORD_DENIED
Audit ID: 1709025786.045:43147
Operation: umount
Profile: /home/user/test/testmount
Name: /mnt/a/
Command: testmount
PID: 26697
Class: mount
Epoch: 1709025786
Audit subid: 43147

View File

@@ -0,0 +1,4 @@
/home/user/test/testmount {
umount /mnt/a/,
}

View File

@@ -70,7 +70,10 @@ CFLAGS = -g -pg -fprofile-arcs -ftest-coverage
endif
endif #CFLAGS
CFLAGS += -flto-partition=none
HAVE_FLTO_PARTITION_NONE:=$(shell ${CC} -E -flto-partition=none /dev/null 1>/dev/null 2>&1 && echo true)
ifeq ($(HAVE_FLTO_PARTITION_NONE),true)
CFLAGS += -flto-partition=none
endif
EXTRA_CXXFLAGS = ${CFLAGS} ${CPPFLAGS} ${CXX_WARNINGS} -std=gnu++0x
EXTRA_CFLAGS = ${EXTRA_CXXFLAGS} ${CPP_WARNINGS}

View File

@@ -202,7 +202,7 @@ void unix_rule::downgrade_rule(Profile &prof) {
if (audit == AUDIT_FORCE)
prof.net.audit[AF_UNIX] |= mask;
const char *error;
network_rule *netv8 = new network_rule(AF_UNIX, sock_type_n);
network_rule *netv8 = new network_rule(perms, AF_UNIX, sock_type_n);
if(!netv8->add_prefix({audit, rule_mode, owner}, error))
yyerror(error);
prof.rule_ents.push_back(netv8);

View File

@@ -83,7 +83,7 @@ void all_rule::add_implied_rules(Profile &prof)
(void) rule->add_prefix(*prefix);
prof.rule_ents.push_back(rule);
rule = new network_rule(NULL);
rule = new network_rule(0, (struct cond_entry *)NULL, (struct cond_entry *)NULL);
(void) rule->add_prefix(*prefix);
prof.rule_ents.push_back(rule);

View File

@@ -117,7 +117,7 @@ B<PROFILE FLAGS> = I<PROFILE MODE> | I<AUDIT_MODE> | 'mediate_deleted'
| 'attach_disconnected' | 'attach_disconneced.path='I<ABS PATH> | 'chroot_relative'
| 'debug' | 'interruptible' | 'kill.signal='I<SIGNAL>
B<PROFILE MODE> = 'enforce' | 'complain' | 'kill' | 'unconfined' | 'prompt'
B<PROFILE MODE> = 'enforce' | 'complain' | 'kill' | 'default_allow' | 'unconfined' | 'prompt'
B<AUDIT MODE> = 'audit'
@@ -466,12 +466,36 @@ a signal to kill it.
permission the action will be allowed, but the violation will be logged
with a tag of the access being B<ALLOWED>.
=item B<default_allow> This mode changes the default behavior of
apparmor from default deny to default allow. When default_allow is
specified the resulting profile will allow operations that the profile
does not have a rule for. This mode is similar to I<unconfined> but
allows for allow and deny rules, specifying audit, and domain
transitions. Profiles in this mode may be be reported as being in
I<enforce> mode or I<allow> mode when introspected from the kernel.
Note: default_allow is similar and for many profiles will be equivalent
to specifying an I<allow all,> rule in the profile. The default_allow
flag does not provide all the same option that the I<allow all,> rule
provides.
=item B<unconfined> This mode allows a task confined by the profile to
behave as though they are I<unconfined>. This mode allow for an
unconfined behavior that can be later changed to confinement by using
profile replacement. This mode is should not be used under regular
deployment but can be useful during debugging and some system
initialization scenarios.
behave as though it is I<unconfined>. The unconfined behavior can be
later changed to confinement by using profile replacement. This mode
should not be used under regular deployment but can be useful during
debugging and some system initialization scenarios.
This mode is similar to default_allow and may be emulated by
default_allow in kernels that no longer support a true unconfined
mode. It does not generally allow for specifying deny rules, or allow
rules that override the default behavior, except in a few custom
kernels where unconfined restricts a few operations. It relies on
special customized behavior of the unconfined profile in the kernel
and as such should only be used for debugging.
Note: true unconfined is being phased out, with unconfined becoming a
replaceable profile. As such unconfined mode will be emulated by a
special profile compiled with the default_allow flag in newer kernels.
=item B<prompt> This mode allows task mediation to send an up call to
userspace to ask for a decision when there isn't a rule covering the
@@ -2013,8 +2037,6 @@ An example AppArmor profile:
=over 4
=item F</etc/init.d/boot.apparmor>
=item F</etc/apparmor.d/>
=back

View File

@@ -36,12 +36,11 @@ of resources. AppArmor's unique security model is to bind access control
attributes to programs rather than to users.
AppArmor confinement is provided via I<profiles> loaded into the kernel
via apparmor_parser(8), typically through the F</etc/init.d/apparmor>
SysV initscript, which is used like this:
via apparmor_parser(8), typically through the F<apparmor.service>
systemd unit, which is used like this:
# /etc/init.d/apparmor start
# /etc/init.d/apparmor stop
# /etc/init.d/apparmor restart
# systemctl start apparmor
# systemctl reload apparmor
AppArmor can operate in two modes: I<enforcement>, and I<complain or learning>:
@@ -273,11 +272,9 @@ Else, if auditd is running, see auditd(8) and auditd.conf(5).
=over 4
=item F</etc/init.d/apparmor>
=item F</etc/apparmor.d/>
=item F</var/lib/apparmor/>
=item F</var/cache/apparmor/>
=item F</var/log/audit/audit.log>

View File

@@ -6,6 +6,8 @@ After=systemd-journald-audit.socket
# profile cache: /var/cache/apparmor/ and /usr/share/apparmor/cache/
After=var.mount var-cache.mount usr.mount usr-share.mount
ConditionSecurity=apparmor
Documentation=man:apparmor(7)
Documentation=https://gitlab.com/apparmor/apparmor/wikis/home/
[Service]
Type=oneshot

View File

@@ -299,11 +299,11 @@ Enable various warnings during policy compilation. A single warn flag
can be specified per --warn option, but the --warn flag can be passed
multiple times.
apparmor_parser --warn=rules-not-enforced ...
apparmor_parser --warn=rule-not-enforced ...
A specific warning can be disabled by prepending I<no>- to the flag
apparmor_parser --warn=no-rules-not-enforced ...
apparmor_parser --warn=no-rule-not-enforced ...
Use --help=warn to see a full list of which warn flags are supported.

View File

@@ -12,8 +12,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, contact Novell, Inc. or Canonical
* Ltd.
* along with this program; if not, contact Canonical Ltd.
*/
#ifndef __AA_BIGNUM_H
@@ -29,10 +28,9 @@ class bignum
{
public:
std::vector<uint8_t> data;
uint64_t sad = 543;
uint8_t base;
bool negative = false;
bignum () {}
bignum () : base(0) {}
bignum (unsigned long val) {
if (val == 0)

View File

@@ -72,6 +72,7 @@ static inline Chars* insert_char_range(Chars* cset, transchar a, transchar b)
* parsing succeeds!
*/
%destructor { $$->release(); } expr terms0 terms qterm term
%destructor { delete $$; } charset cset_chars
%%

View File

@@ -234,6 +234,7 @@ struct mnt_keyword_table {
unsigned int clear;
};
// keep in sync with utils/apparmor/rule/mount.py flags_keywords
static struct mnt_keyword_table mnt_opts_table[] = {
{"ro", MS_RDONLY, 0},
{"r", MS_RDONLY, 0},

View File

@@ -20,6 +20,7 @@
#include <string>
#include <sstream>
#include <map>
#include <arpa/inet.h>
#include "lib.h"
#include "parser.h"
@@ -298,7 +299,59 @@ const struct network_tuple *net_find_mapping(const struct network_tuple *map,
return NULL;
}
void network_rule::move_conditionals(struct cond_entry *conds)
bool parse_ipv4_address(const char *input, struct ip_address *result)
{
struct in_addr addr;
if (inet_pton(AF_INET, input, &addr) == 1) {
result->family = AF_INET;
result->address.address_v4 = addr.s_addr;
return true;
}
return false;
}
bool parse_ipv6_address(const char *input, struct ip_address *result)
{
struct in6_addr addr;
if (inet_pton(AF_INET6, input, &addr) == 1) {
result->family = AF_INET6;
memcpy(result->address.address_v6, addr.s6_addr, 16);
return true;
}
return false;
}
bool parse_ip(const char *ip, struct ip_address *result)
{
return parse_ipv6_address(ip, result) ||
parse_ipv4_address(ip, result);
}
bool parse_port_number(const char *port_entry, uint16_t *port) {
char *eptr;
unsigned long port_tmp = strtoul(port_entry, &eptr, 10);
if (port_tmp >= 0 && port_entry != eptr &&
*eptr == '\0' && port_tmp <= UINT16_MAX) {
*port = port_tmp;
return true;
}
return false;
}
bool network_rule::parse_port(ip_conds &entry)
{
entry.is_port = true;
return parse_port_number(entry.sport, &entry.port);
}
bool network_rule::parse_address(ip_conds &entry)
{
entry.is_ip = true;
return parse_ip(entry.sip, &entry.ip);
}
void network_rule::move_conditionals(struct cond_entry *conds, ip_conds &ip_cond)
{
struct cond_entry *cond_ent;
@@ -306,10 +359,18 @@ void network_rule::move_conditionals(struct cond_entry *conds)
/* for now disallow keyword 'in' (list) */
if (!cond_ent->eq)
yyerror("keyword \"in\" is not allowed in network rules\n");
/* no valid conditionals atm */
yyerror("invalid network rule conditional \"%s\"\n",
cond_ent->name);
if (strcmp(cond_ent->name, "ip") == 0) {
move_conditional_value("network", &ip_cond.sip, cond_ent);
if (!parse_address(ip_cond))
yyerror("network invalid ip='%s'\n", ip_cond.sip);
} else if (strcmp(cond_ent->name, "port") == 0) {
move_conditional_value("network", &ip_cond.sport, cond_ent);
if (!parse_port(ip_cond))
yyerror("network invalid port='%s'\n", ip_cond.sport);
} else {
yyerror("invalid network rule conditional \"%s\"\n",
cond_ent->name);
}
}
}
@@ -322,7 +383,8 @@ void network_rule::set_netperm(unsigned int family, unsigned int type)
network_perms[family] |= 1 << type;
}
network_rule::network_rule(struct cond_entry *conds):
network_rule::network_rule(perms_t perms_p, struct cond_entry *conds,
struct cond_entry *peer_conds):
dedup_perms_rule_t(AA_CLASS_NETV8)
{
size_t family_index;
@@ -331,12 +393,25 @@ network_rule::network_rule(struct cond_entry *conds):
set_netperm(family_index, 0xFFFFFFFF);
}
move_conditionals(conds);
move_conditionals(conds, local);
move_conditionals(peer_conds, peer);
free_cond_list(conds);
free_cond_list(peer_conds);
if (perms_p) {
perms = perms_p;
if (perms & ~AA_VALID_NET_PERMS)
yyerror("perms contains invalid permissions for network rules\n");
else if ((perms & ~AA_PEER_NET_PERMS) && has_peer_conds())
yyerror("network 'create', 'shutdown', 'setattr', 'getattr', 'bind', 'listen', 'setopt', and/or 'getopt' accesses cannot be used with peer socket conditionals\n");
} else {
perms = AA_VALID_NET_PERMS;
}
}
network_rule::network_rule(const char *family, const char *type,
const char *protocol, struct cond_entry *conds):
network_rule::network_rule(perms_t perms_p, const char *family, const char *type,
const char *protocol, struct cond_entry *conds,
struct cond_entry *peer_conds):
dedup_perms_rule_t(AA_CLASS_NETV8)
{
const struct network_tuple *mapping = NULL;
@@ -355,15 +430,37 @@ network_rule::network_rule(const char *family, const char *type,
if (network_map.empty())
yyerror(_("Invalid network entry."));
move_conditionals(conds);
move_conditionals(conds, local);
move_conditionals(peer_conds, peer);
free_cond_list(conds);
free_cond_list(peer_conds);
if (perms_p) {
perms = perms_p;
if (perms & ~AA_VALID_NET_PERMS)
yyerror("perms contains invalid permissions for network rules\n");
else if ((perms & ~AA_PEER_NET_PERMS) && has_peer_conds())
yyerror("network 'create', 'shutdown', 'setattr', 'getattr', 'bind', 'listen', 'setopt', and/or 'getopt' accesses cannot be used with peer socket conditionals\n");
} else {
perms = AA_VALID_NET_PERMS;
}
}
network_rule::network_rule(unsigned int family, unsigned int type):
network_rule::network_rule(perms_t perms_p, unsigned int family, unsigned int type):
dedup_perms_rule_t(AA_CLASS_NETV8)
{
network_map[family].push_back({ family, type, 0xFFFFFFFF });
set_netperm(family, type);
if (perms_p) {
perms = perms_p;
if (perms & ~AA_VALID_NET_PERMS)
yyerror("perms contains invalid permissions for network rules\n");
else if ((perms & ~AA_PEER_NET_PERMS) && has_peer_conds())
yyerror("network 'create', 'shutdown', 'setattr', 'getattr', 'bind', 'listen', 'setopt', and/or 'getopt' accesses cannot be used with peer socket conditionals\n");
} else {
perms = AA_VALID_NET_PERMS;
}
}
ostream &network_rule::dump(ostream &os)
@@ -428,6 +525,79 @@ void network_rule::warn_once(const char *name)
rule_t::warn_once(name, "network rules not enforced");
}
std::string gen_ip_cond(const struct ip_address ip)
{
std::ostringstream oss;
int i;
if (ip.family == AF_INET) {
/* add a byte containing the size of the following ip */
oss << "\\x04";
u8 *byte = (u8 *) &ip.address.address_v4; /* in network byte order */
for (i = 0; i < 4; i++)
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned int>(byte[i]);
} else {
/* add a byte containing the size of the following ip */
oss << "\\x10";
for (i = 0; i < 16; ++i)
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned int>(ip.address.address_v6[i]);
}
return oss.str();
}
std::string gen_port_cond(uint16_t port)
{
std::ostringstream oss;
if (port > 0) {
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << ((port & 0xff00) >> 8);
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << (port & 0xff);
} else {
oss << "..";
}
return oss.str();
}
void network_rule::gen_ip_conds(std::ostringstream &oss, ip_conds entry, bool is_peer, bool is_cmd)
{
/* encode protocol */
if (!is_cmd) {
if (entry.is_ip) {
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << ((entry.ip.family & 0xff00) >> 8);
oss << "\\x" << std::setfill('0') << std::setw(2) << std::hex << (entry.ip.family & 0xff);
} else {
oss << "..";
}
}
if (entry.is_port) {
/* encode port type (privileged - 1, remote - 2, unprivileged - 0) */
if (!is_peer && perms & AA_NET_BIND && entry.port < IPPORT_RESERVED)
oss << "\\x01";
else if (is_peer)
oss << "\\x02";
else
oss << "\\x00";
oss << gen_port_cond(entry.port);
} else {
/* port type + port number */
if (!is_cmd)
oss << ".";
oss << "..";
}
if (entry.is_ip) {
oss << gen_ip_cond(entry.ip);
} else {
/* encode 0 to indicate there's no ip (ip size) */
oss << "\\x00";
}
oss << "\\-x01"; /* oob separator */
oss << default_match_pattern; /* label - not used for now */
oss << "\\x00"; /* null transition */
}
bool network_rule::gen_net_rule(Profile &prof, u16 family, unsigned int type_mask) {
std::ostringstream buffer;
std::string buf;
@@ -441,13 +611,59 @@ bool network_rule::gen_net_rule(Profile &prof, u16 family, unsigned int type_mas
buffer << "\\x" << std::setfill('0') << std::setw(2) << std::hex << ((type_mask & 0xff00) >> 8);
buffer << "\\x" << std::setfill('0') << std::setw(2) << std::hex << (type_mask & 0xff);
}
buf = buffer.str();
if (!prof.policy.rules->add_rule(buf.c_str(), rule_mode == RULE_DENY, map_perms(AA_VALID_NET_PERMS),
dedup_perms_rule_t::audit == AUDIT_FORCE ? map_perms(AA_VALID_NET_PERMS) : 0,
parseopts))
return false;
if (!features_supports_inet || (family != AF_INET && family != AF_INET6)) {
buf = buffer.str();
if (!prof.policy.rules->add_rule(buf.c_str(), rule_mode == RULE_DENY, map_perms(perms),
dedup_perms_rule_t::audit == AUDIT_FORCE ? map_perms(perms) : 0,
parseopts))
return false;
return true;
}
if (perms & AA_PEER_NET_PERMS) {
gen_ip_conds(buffer, peer, true, false);
buffer << "\\x" << std::setfill('0') << std::setw(2) << std::hex << CMD_ADDR;
gen_ip_conds(buffer, local, false, true);
buf = buffer.str();
if (!prof.policy.rules->add_rule(buf.c_str(), rule_mode == RULE_DENY, map_perms(perms),
dedup_perms_rule_t::audit == AUDIT_FORCE ? map_perms(perms) : 0,
parseopts))
return false;
}
if ((perms & AA_NET_LISTEN) || (perms & AA_NET_OPT)) {
gen_ip_conds(buffer, local, false, false);
if (perms & AA_NET_LISTEN) {
std::ostringstream cmd_buffer;
cmd_buffer << buffer.str();
cmd_buffer << "\\x" << std::setfill('0') << std::setw(2) << std::hex << CMD_LISTEN;
/* length of queue allowed - not used for now */
cmd_buffer << "..";
buf = cmd_buffer.str();
if (!prof.policy.rules->add_rule(buf.c_str(), rule_mode == RULE_DENY, map_perms(perms),
dedup_perms_rule_t::audit == AUDIT_FORCE ? map_perms(perms) : 0,
parseopts))
return false;
}
if (perms & AA_NET_OPT) {
std::ostringstream cmd_buffer;
cmd_buffer << buffer.str();
cmd_buffer << "\\x" << std::setfill('0') << std::setw(2) << std::hex << CMD_OPT;
/* level - not used for now */
cmd_buffer << "..";
/* socket mapping - not used for now */
cmd_buffer << "..";
buf = cmd_buffer.str();
if (!prof.policy.rules->add_rule(buf.c_str(), rule_mode == RULE_DENY, map_perms(perms),
dedup_perms_rule_t::audit == AUDIT_FORCE ? map_perms(perms) : 0,
parseopts))
return false;
}
}
return true;
}

View File

@@ -75,6 +75,10 @@
#define AA_PEER_NET_PERMS (AA_VALID_NET_PERMS & (~AA_LOCAL_NET_PERMS | \
AA_NET_ACCEPT))
#define CMD_ADDR 1
#define CMD_LISTEN 2
#define CMD_OPT 4
struct network_tuple {
const char *family_name;
unsigned int family;
@@ -104,22 +108,58 @@ int net_find_type_val(const char *type);
const char *net_find_type_name(int type);
const char *net_find_af_name(unsigned int af);
struct ip_address {
union {
uint8_t address_v6[16];
uint32_t address_v4;
} address;
uint16_t family;
};
class ip_conds {
public:
char *sip = NULL;
char *sport = NULL;
bool is_ip = false;
bool is_port = false;
uint16_t port;
struct ip_address ip;
void free_conds() {
if (sip)
free(sip);
if (sport)
free(sport);
}
};
class network_rule: public dedup_perms_rule_t {
void move_conditionals(struct cond_entry *conds);
void move_conditionals(struct cond_entry *conds, ip_conds &ip_cond);
public:
std::unordered_map<unsigned int, std::vector<struct aa_network_entry>> network_map;
std::unordered_map<unsigned int, perms_t> network_perms;
ip_conds peer;
ip_conds local;
bool has_local_conds(void) { return local.sip || local.sport; }
bool has_peer_conds(void) { return peer.sip || peer.sport; }
/* empty constructor used only for the profile to access
* static elements to maintain compatibility with
* AA_CLASS_NET */
network_rule(): dedup_perms_rule_t(AA_CLASS_NETV8) { }
network_rule(struct cond_entry *conds);
network_rule(const char *family, const char *type,
const char *protocol, struct cond_entry *conds);
network_rule(unsigned int family, unsigned int type);
network_rule(perms_t perms_p, struct cond_entry *conds,
struct cond_entry *peer_conds);
network_rule(perms_t perms_p, const char *family, const char *type,
const char *protocol, struct cond_entry *conds,
struct cond_entry *peer_conds);
network_rule(perms_t perms_p, unsigned int family, unsigned int type);
virtual ~network_rule()
{
peer.free_conds();
local.free_conds();
if (allow) {
free(allow);
allow = NULL;
@@ -138,9 +178,12 @@ public:
}
};
void gen_ip_conds(std::ostringstream &oss, ip_conds entry, bool is_peer, bool is_cmd);
bool gen_net_rule(Profile &prof, u16 family, unsigned int type_mask);
void set_netperm(unsigned int family, unsigned int type);
void update_compat_net(void);
bool parse_address(ip_conds &entry);
bool parse_port(ip_conds &entry);
virtual bool valid_prefix(const prefixes &p, const char *&error) {
if (p.owner) {

View File

@@ -341,6 +341,7 @@ extern int kernel_load;
extern int kernel_supports_setload;
extern int features_supports_network;
extern int features_supports_networkv8;
extern int features_supports_inet;
extern int kernel_supports_policydb;
extern int kernel_supports_diff_encode;
extern int features_supports_mount;

View File

@@ -69,6 +69,7 @@ int kernel_load = 1;
int kernel_supports_setload = 0; /* kernel supports atomic set loads */
int features_supports_network = 0; /* kernel supports network rules */
int features_supports_networkv8 = 0; /* kernel supports 4.17 network rules */
int features_supports_inet = 0; /* kernel supports inet network rules */
int features_supports_unix = 0; /* kernel supports unix socket rules */
int kernel_supports_policydb = 0; /* kernel supports new policydb */
int features_supports_mount = 0; /* kernel supports mount rules */

View File

@@ -276,7 +276,7 @@ static inline void sd_write_aligned_blob(std::ostringstream &buf, void *b, int b
buf.write((const char *) b, b_size);
}
static void sd_write_strn(std::ostringstream &buf, char *b, int size, const char *name)
static void sd_write_strn(std::ostringstream &buf, const char *b, int size, const char *name)
{
sd_write_name(buf, name);
sd_write8(buf, SD_STRING);
@@ -284,7 +284,7 @@ static void sd_write_strn(std::ostringstream &buf, char *b, int size, const char
buf.write(b, size);
}
static inline void sd_write_string(std::ostringstream &buf, char *b, const char *name)
static inline void sd_write_string(std::ostringstream &buf, const char *b, const char *name)
{
sd_write_strn(buf, b, strlen(b) + 1, name);
}
@@ -403,11 +403,7 @@ void sd_serialize_profile(std::ostringstream &buf, Profile *profile,
sd_write_struct(buf, "profile");
if (flattened) {
assert(profile->parent);
autofree char *name = (char *) malloc(3 + strlen(profile->name) + strlen(profile->parent->name));
if (!name)
return;
sprintf(name, "%s//%s", profile->parent->name, profile->name);
sd_write_string(buf, name, NULL);
sd_write_string(buf, profile->get_name(false).c_str(), NULL);
} else {
sd_write_string(buf, profile->name, NULL);
}

View File

@@ -517,12 +517,6 @@ GT >
}
}
<NETWORK_MODE>{
{IDS} {
yylval.id = strdup(yytext);
RETURN_TOKEN(TOK_ID);
}
}
<CHANGE_PROFILE_MODE>{
safe { RETURN_TOKEN(TOK_SAFE); }
@@ -558,7 +552,7 @@ GT >
{LT_EQUAL} { RETURN_TOKEN(TOK_LE); }
}
<UNIX_MODE>{
<UNIX_MODE,NETWORK_MODE>{
listen { RETURN_TOKEN(TOK_LISTEN); }
accept { RETURN_TOKEN(TOK_ACCEPT); }
connect { RETURN_TOKEN(TOK_CONNECT); }
@@ -567,7 +561,7 @@ GT >
shutdown { RETURN_TOKEN(TOK_SHUTDOWN); }
}
<UNIX_MODE,USERNS_MODE,MQUEUE_MODE>{
<UNIX_MODE,USERNS_MODE,MQUEUE_MODE,NETWORK_MODE>{
create { RETURN_TOKEN(TOK_CREATE); }
}
@@ -576,12 +570,12 @@ GT >
delete { RETURN_TOKEN(TOK_DELETE); }
}
<UNIX_MODE,MQUEUE_MODE>{
<UNIX_MODE,MQUEUE_MODE,NETWORK_MODE>{
getattr { RETURN_TOKEN(TOK_GETATTR); }
setattr { RETURN_TOKEN(TOK_SETATTR); }
}
<DBUS_MODE,UNIX_MODE>{
<DBUS_MODE,UNIX_MODE,NETWORK_MODE>{
bind { RETURN_TOKEN(TOK_BIND); }
}
@@ -589,7 +583,7 @@ GT >
eavesdrop { RETURN_TOKEN(TOK_EAVESDROP); }
}
<DBUS_MODE,SIGNAL_MODE,UNIX_MODE>{
<DBUS_MODE,SIGNAL_MODE,UNIX_MODE,NETWORK_MODE>{
send { RETURN_TOKEN(TOK_SEND); }
receive { RETURN_TOKEN(TOK_RECEIVE); }
}
@@ -600,7 +594,7 @@ GT >
tracedby { RETURN_TOKEN(TOK_TRACEDBY); }
}
<DBUS_MODE,SIGNAL_MODE,PTRACE_MODE,UNIX_MODE,MQUEUE_MODE>{
<DBUS_MODE,SIGNAL_MODE,PTRACE_MODE,UNIX_MODE,MQUEUE_MODE,NETWORK_MODE>{
read { RETURN_TOKEN(TOK_READ); }
write { RETURN_TOKEN(TOK_WRITE); }
{OPEN_PAREN} {
@@ -621,7 +615,7 @@ GT >
sqpoll { RETURN_TOKEN(TOK_SQPOLL); }
}
<MOUNT_MODE,DBUS_MODE,SIGNAL_MODE,PTRACE_MODE,UNIX_MODE,MQUEUE_MODE,IOURING_MODE>{
<MOUNT_MODE,DBUS_MODE,SIGNAL_MODE,PTRACE_MODE,UNIX_MODE,MQUEUE_MODE,IOURING_MODE,NETWORK_MODE>{
({IDS_NOEQ}|{LABEL}|{QUOTED_ID}) {
yylval.id = processid(yytext, yyleng);
RETURN_TOKEN(TOK_ID);

View File

@@ -919,6 +919,9 @@ void set_supported_features()
features_supports_networkv8 = features_intersect(kernel_features,
policy_features,
"network_v8");
features_supports_inet = features_intersect(kernel_features,
policy_features,
"network/af_inet");
features_supports_unix = features_intersect(kernel_features,
policy_features,
"network/af_unix");

View File

@@ -882,7 +882,7 @@ static std::string generate_regex_range(bignum start, bignum end)
std::ostringstream result;
std::vector<std::pair<bignum, bignum>> regex_range;
int j;
regex_range = regex_range_generator(start, end);
regex_range = regex_range_generator(std::move(start), std::move(end));
for (auto &i: regex_range) {
bignum sstart = i.first;
bignum send = i.second;
@@ -942,7 +942,7 @@ int convert_range(std::string& buffer, bignum start, bignum end)
pattern_t ptype;
int pos;
std::string regex_range = generate_regex_range(start, end);
std::string regex_range = generate_regex_range(std::move(start), std::move(end));
if (!regex_range.empty()) {
ptype = convert_aaregex_to_pcre(regex_range.c_str(), 0, glob_default, buffer, &pos);

View File

@@ -1083,27 +1083,48 @@ link_rule: TOK_LINK opt_subset_flag id_or_var TOK_ARROW id_or_var TOK_END_OF_RUL
$$ = entry;
};
network_rule: TOK_NETWORK opt_conds TOK_END_OF_RULE
network_rule: TOK_NETWORK opt_net_perm opt_conds opt_cond_list TOK_END_OF_RULE
{
network_rule *entry = new network_rule($2);
network_rule *entry;
if ($4.name) {
if (strcmp($4.name, "peer") != 0)
yyerror(_("network rule: invalid conditional group %s=()"), $4.name);
free($4.name);
}
entry = new network_rule($2, $3, $4.list);
$$ = entry;
}
network_rule: TOK_NETWORK TOK_ID opt_conds TOK_END_OF_RULE
network_rule: TOK_NETWORK opt_net_perm TOK_ID opt_conds opt_cond_list TOK_END_OF_RULE
{
network_rule *entry = new network_rule($2, NULL, NULL, $3);
free($2);
$$ = entry;
}
network_rule *entry;
network_rule: TOK_NETWORK TOK_ID TOK_ID opt_conds TOK_END_OF_RULE
{
network_rule *entry = new network_rule($2, $3, NULL, $4);
free($2);
if ($5.name) {
if (strcmp($5.name, "peer") != 0)
yyerror(_("network rule: invalid conditional group %s=()"), $5.name);
free($5.name);
}
entry = new network_rule($2, $3, NULL, NULL, $4, $5.list);
free($3);
$$ = entry;
}
network_rule: TOK_NETWORK opt_net_perm TOK_ID TOK_ID opt_conds opt_cond_list TOK_END_OF_RULE
{
network_rule *entry;
if ($6.name) {
if (strcmp($6.name, "peer") != 0)
yyerror(_("network rule: invalid conditional group %s=()"), $6.name);
free($6.name);
}
entry = new network_rule($2, $3, $4, NULL, $5, $6.list);
free($3);
free($4);
$$ = entry;
}
cond: TOK_CONDID
{
struct cond_entry *ent;

View File

@@ -28,6 +28,7 @@ const char *profile_mode_table[] = {
"kill",
"unconfined",
"prompt",
"default_allow",
"conflict" /* should not ever be displayed */
};

View File

@@ -64,9 +64,10 @@ enum profile_mode {
MODE_KILL = 3,
MODE_UNCONFINED = 4,
MODE_PROMPT = 5,
MODE_CONFLICT = 6 /* greater than MODE_LAST */
MODE_DEFAULT_ALLOW = 6,
MODE_CONFLICT = 7 /* greater than MODE_LAST */
};
#define MODE_LAST MODE_PROMPT
#define MODE_LAST MODE_DEFAULT_ALLOW
static inline enum profile_mode operator++(enum profile_mode &mode)
{
@@ -85,6 +86,9 @@ static inline enum profile_mode merge_profile_mode(enum profile_mode l, enum pro
static inline uint32_t profile_mode_packed(enum profile_mode mode)
{
/* until dominance is fixed use unconfined mode for default_allow */
if (mode == MODE_DEFAULT_ALLOW)
mode = MODE_UNCONFINED;
/* kernel doesn't have an unspecified mode everything
* shifts down by 1
*/

View File

@@ -105,11 +105,12 @@ is_container_with_internal_policy() {
return 1
fi
# LXD and LXC set up AppArmor namespaces starting with "lxd-" and
# "lxc-", respectively. Return non-zero for all other namespace
# identifiers.
# LXD, Incus and LXC set up AppArmor namespaces starting with "lxd-",
# "incus-" and "lxc-", respectively. Return non-zero for all other
# namespace identifiers.
read -r ns_name < "$ns_name_path"
if [ "${ns_name#lxd-*}" = "$ns_name" ] && \
[ "${ns_name#incus-*}" = "$ns_name" ] && \
[ "${ns_name#lxc-*}" = "$ns_name" ]; then
return 1
fi

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=127.0.0.1 port=test),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=127.0.0.1 port=65536),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=[invalid] port=80),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=::1 port=-1),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=::1 port=test),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=::1 port=65536),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(port=65536),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(port=-1),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(port=test),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=192.168.0.39-192.168.0.4),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=192.168.0.39-invalid),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=192.168.0.39-::58c2),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=2001:1884:d02e:2759:d30:f166:71c9:288f-192.168.0.39),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=80-192.168.0.39),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(port=80-65536),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(port=443-80),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network subnet test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=invalid/80),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network subnet test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=192.168.0.1/-1),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network subnet test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=192.168.0.1/invalid),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network subnet test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=192.168.0.1/33),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network subnet test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=2001:1884:d02e:2759:d30:f166:71c9:288f/-1),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network subnet test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=2001:1884:d02e:2759:d30:f166:71c9:288f/invalid),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network subnet test
#=EXRESULT FAIL
#
/usr/bin/foo {
network peer=(ip=2001:1884:d02e:2759:d30:f166:71c9:288f/129),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=127.0.0.1 port=test,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=127.0.0.1 port=test peer=(ip=127.0.0.1 port=test),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=127.0.0.1 port=65536,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=127.0.0.1 port=65536 peer=(ip=127.0.0.1 port=65536),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=[invalid] port=80,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=[invalid] port=80 peer=(ip=[invalid] port=80),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=::1 port=-1,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=::1 port=-1 peer=(ip=::1 port=-1),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=::1 port=test,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip - port conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=::1 port=test peer=(ip=::1 port=test),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=::1 port=65536,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=::1 port=65536 peer=(ip=::1 port=65536),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=65536,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=65536 peer=(port=65536),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=-1,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=-1 peer=(port=-1),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=test,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=10,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network port range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=test peer=(port=test),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=192.168.0.39-192.168.0.4,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=192.168.0.39-192.168.0.4 peer=(ip=192.168.0.39-192.168.0.4),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=192.168.0.39-invalid,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=192.168.0.39-invalid peer=(ip=192.168.0.39-invalid),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=192.168.0.39-::58c2,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=192.168.0.39-::58c2 peer=(ip=192.168.0.39-::58c2),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=2001:1884:d02e:2759:d30:f166:71c9:288f-192.168.0.39,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=2001:1884:d02e:2759:d30:f166:71c9:288f-192.168.0.39 peer=(ip=2001:1884:d02e:2759:d30:f166:71c9:288f-192.168.0.39),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=80-192.168.0.39,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network ip conditional test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=10.2,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=80-192.168.0.39 peer=(ip=80-192.168.0.39),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=80-65536,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=80-65536 peer=(port=80-65536),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=443-80,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network range test
#=EXRESULT FAIL
#
/usr/bin/foo {
network port=443-80 peer=(port=443-80),
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network subnet test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=invalid/80,
}

View File

@@ -0,0 +1,8 @@
#
#=DESCRIPTION invalid network subnet test
#=EXRESULT FAIL
#
/usr/bin/foo {
network ip=invalid/80 peer=(ip=invalid/80),
}

Some files were not shown because too many files have changed in this diff Show More