Commit graph

6672 commits

Author SHA1 Message Date
John Johansen
197d00d21a parser: add support for a generic all rule type
Extend the policy syntax to have a rule that allows specifying all
permissions for all rule types.

  allow all,

This is useful for making blacklist based policy, but can also be
useful when combined with other rule prefixes, eg. to add audit
to all rules.

  audit access all,

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-09-07 01:30:15 -07:00
John Johansen
a9c5388f69
Merge parser: refactor network rules and prepare for fine grained network rules
This lays the ground work for fine grained network mediation. The switch to using the rules class brings the advantages of shared infrastructure and is needed for tracking all the different combinations possible with finer control.

In addition range generation and support for large numbers (needed for ipv6) are added. This patchset does not make policy visible changes to network rules.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1104
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-09-07 07:22:21 +00:00
Georgia Garcia
75ca0e7919 parser: track leading zeros required for ipv6 range regex generator
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:52 -07:00
Georgia Garcia
fb5f59024c parser: add uppercase hex on regex range generator
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:42 -07:00
Georgia Garcia
a71ac76e6d parser: add regex generator for range
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:29 -07:00
Georgia Garcia
2be9c431ca parser: add opt_cond in preparation to finer grained network mediation
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:15 -07:00
Georgia Garcia
05de4b82e7 parser: implement dedup of network rules
Since network rules don't use the "perms" attribute, it is using the
dedup class in which duplicate rules are removed.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:04 -07:00
Georgia Garcia
820f1fb5f2 parser: refactor network to use rule class as its base.
There is one significant difference in the encoding of the network
rules. Before this change, when the parser was encoding a "network,"
rule, it would generate an entry for every family and every
type/protocol. After this patch the parser should generate an entry
for every family, but the type/protocol is changed to .. in the pcre
syntax. There should be no difference in behavior.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:12:51 -07:00
John Johansen
65905b0c55
Merge aa-status: separate error messages from the regular output
using dfprintf for error messages subjects them to the other
output controls and can cause them to be surpressed when they
shouldn't.

Instead use a dedicated error function and add a quiet flag to
allow silencing errors.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1102
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-09-07 06:01:08 +00:00
John Johansen
1945ecbf19 aa-status: separate error messages from the regular output
using dfprintf for error messages subjects them to the other
output controls and can cause them to be surpressed when they
shouldn't.

Instead use a dedicated error function and add a quiet flag to
allow silencing errors.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-28 15:52:44 -07:00
John Johansen
11976c42e3 Merge binutils/aa_status.c: quiet verbose outputs when --json is specified
By default aa-status outputs with --verbose enabled - if --json is also
specified then aa-status would currently output in its first line "apparmor
module is loaded.":

aa-status --json | head -n1
apparmor module is loaded.

And only after this the actual json output would follow. This then results in
failures to parse this JSON output:

aa-status --json | jq .
parse error: Invalid numeric literal at line 1, column 9

This in turn then breaks tools / tests which expect the output of aa-status
--json to be purely json - e.g:
https://salsa.debian.org/apparmor-team/apparmor-profiles-extra/-/blob/debian/unstable/debian/tests/policy-is-loaded#L12

So ensure dprintf() etc do not output when --json is specified to restrict the
output of aa-status to pure JSON.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1097
Approved-by: Seth Arnold <seth.arnold@gmail.com>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:07:17 +00:00
John Johansen
327588f019 Merge parser: fix coverity scan 553075
coverity is reporting an overrun of the profile_mode_table

217     		if (merge_profile_mode(mode, rhs.mode) == MODE_CONFLICT)
>>>     CID 322989:    (OVERRUN)
>>>     Overrunning array "profile_mode_table" of 6 8-byte elements at element index 6 (byte offset 55) using index "this->mode" (which evaluates to 6).

this is because it is being indexed by the profile_mode enum which can
go up to a 6th entry. The code tests for MODE_CONFLICT before using
the table so it shouldn't trigger a bug today, but play it safe for
the future and also get rid of the coverity scan error by adding a
"conflict" entry to the mode_table.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1098
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:05:45 +00:00
John Johansen
84e22b4cca Merge Docs: apparmor.d.pod document io_uring and userns rules
Documentation for io_uring and userns rules is missing from the
apparmor.d man page. Provide some basic documentation for them.

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

Closes #349
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1099
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:05:20 +00:00
John Johansen
248625ae00 Merge apparmor.d.pod: rename SIGNALS to SIGNAL
SIGNAL makes more sense because it's about a single signal.

Besides that, a9494f5523 introduced a (at
that point broken) usage of SIGNAL which becomes valid with this commit.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1100
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:05:04 +00:00
John Johansen
9ab72ffc7c Merge Install systemd unit on fedora/redhat systems
... instead of trying the old rc.apparmor.redhat initscript, which we no
longer ship since 2019519e34.

Also remove a superfluous level of indirection (rhel4 -> redhat).

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

Closes #350
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1101
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-28 22:04:53 +00:00
Christian Boltz
9be09aa909
Install systemd unit on fedora/redhat systems
... instead of trying the old rc.apparmor.redhat initscript, which we no
longer ship since 2019519e34.

Also remove a superfluous level of indirection (rhel4 -> redhat).

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/350
2023-08-28 18:46:20 +02:00
Christian Boltz
2bf35277a0
apparmor.d.pod: rename SIGNALS to SIGNAL
SIGNAL makes more sense because it's about a single signal.

Besides that, a9494f5523 introduced a (at
that point broken) usage of SIGNAL which becomes valid with this commit.
2023-08-28 18:33:03 +02:00
John Johansen
9db134223c Docs: apparmor.d.pod document io_uring and userns rules
Documentation for io_uring and userns rules is missing from the
apparmor.d man page. Provide some basic documentation for them.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/349
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-27 01:06:01 -07:00
John Johansen
ef56e60e06 parser: fix coverity scan 553075
coverity is reporting an overrun of the profile_mode_table

217     		if (merge_profile_mode(mode, rhs.mode) == MODE_CONFLICT)
>>>     CID 322989:    (OVERRUN)
>>>     Overrunning array "profile_mode_table" of 6 8-byte elements at element index 6 (byte offset 55) using index "this->mode" (which evaluates to 6).

this is because it is being indexed by the profile_mode enum which can
go up to a 6th entry. The code tests for MODE_CONFLICT before using
the table so it shouldn't trigger a bug today, but play it safe for
the future and also get rid of the coverity scan error by adding a
"conflict" entry to the mode_table.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-25 23:49:32 -07:00
John Johansen
96965c3da2 Merge Add support for new profile flags
This adds two new profile flags
* `interruptible` which can be used with prompt
* `kill.signal=XXX` which can be used to set the signal used by kill mode or the kill rule prefix

In addition it adds a few cleanups and fixes around profile flag handling

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1096
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-08-26 05:05:42 +00:00
John Johansen
a9494f5523 parser: add kill.signal=XXX flag support
Add a flag that allows setting the signal used to kill the process.
This should not be normally used but can be very useful when
debugging applications, interaction with apparmor.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-25 10:16:51 -07:00
John Johansen
57985480ca parser: Fixup flags merge for disconnected_path
When merging flags with a disconnected_path specified, there is no
check for a conflict and we can just throw away (and leak) one of
the paths.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-25 07:19:01 -07:00
John Johansen
f10467556c parser: move flag init and merge to flagvals class
We have a basic flagvals class it makes sense to move the parser
code into it, to help make management easier going forward.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-25 07:19:01 -07:00
John Johansen
30707be87f parser: add interruptible flag
Allow indicating that prompt upcalls to userspace can be interrupted

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-25 07:18:50 -07:00
Alex Murray
f61fd42061
binutils/aa_status.c: quiet verbose outputs when --json is specified
By default aa-status outputs with --verbose enabled - if --json is also
specified then aa-status would currently output in its first line "apparmor
module is loaded.":

aa-status --json | head -n1
apparmor module is loaded.

And only after this the actual json output would follow. This then results in
failures to parse this JSON output:

aa-status --json | jq .
parse error: Invalid numeric literal at line 1, column 9

This in turn then breaks tools / tests which expect the output of aa-status
--json to be purely json - e.g:
https://salsa.debian.org/apparmor-team/apparmor-profiles-extra/-/blob/debian/unstable/debian/tests/policy-is-loaded#L12

So ensure dprintf() etc do not output when --json is specified to restrict the
output of aa-status to pure JSON.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2023-08-25 09:23:04 +09:30
John Johansen
847ab59e1c Merge collapse_log(): Attach null-* events to correct target profile
ask_exec() and ask_addhat() set
hashlog[aamode][full_profile]['final_name'].

While this was used to get profile and hat split, it was not used as key
for log_dict. This resulted in entries like
log_dict['PERMITTING']['foo//null-/usr/bin/cat']
which are obviously wrong.

Use final_name as log_dict key so that we end up with (assuming child
exec was selected)
log_dict['PERMITTING']['foo///usr/bin/cat']

This fixes a regression introduced in 3.1. Due to other changes in collapse_log() done in master, picking this into 3.1 isn't that easy. I'll submit a separate patch for 3.1.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1091
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-24 01:12:09 +00:00
John Johansen
427b58a4b6 Merge Ignore ´//null-` peers in signal and ptrace events
Ideally we'd update them to the chosen exec target - but until this is
implemented, it doesn't make sense to ask about adding a //null-* peer
to a profile.

I propose this patch for all branches.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1090
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-24 01:11:02 +00:00
John Johansen
aa20721be1 Merge Don't create local/* profile sniplets by default
... and document how to create them if you still want them.

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

Closes #337
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1089
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-23 23:26:54 +00:00
Georgia Garcia
5957aa49f5 Merge fix test specifying path on attach disconnected
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1094
Approved-by: John Johansen <john@jjmx.net>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-08-22 12:49:54 +00:00
Georgia Garcia
e133a9fc68 tests: remove superfluous attach_disconnected flag
Merge request https://gitlab.com/apparmor/apparmor/merge_requests/1084
makes it so attach_disconnected.path implies attach_disconnected, so
remove superfluous flag from tests.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-08-22 09:40:17 -03:00
Georgia Garcia
32307601a0 tests: fix test specifying path on attach disconnected
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-08-21 17:36:48 -03:00
Georgia Garcia
5b139521aa tests: replace individual socket permission to socket and put_old/socket
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-08-21 17:33:33 -03:00
John Johansen
2d7bd40606 Merge tests: fix userns setns opening pipe order
setns tests part of the userns could fail if the parent process opened
the child pipe to write it was done before the child opened the pipe
with read permissions.

From the fifo(7) man page:

A process can open a FIFO in nonblocking mode.  In this case, opening
for read‐only succeeds even if no one has opened on the write side yet
and opening for write‐only fails with ENXIO (no such device or
address) unless the other end has already been opened.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1093
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-21 16:13:28 +00:00
Georgia Garcia
24806f6f61 tests: fix userns setns opening pipe order
setns tests part of the userns could fail if the parent process opened
the child pipe to write it was done before the child opened the pipe
with read permissions.

From the fifo(7) man page:

A process can open a FIFO in nonblocking mode.  In this case, opening
for read‐only succeeds even if no one has opened on the write side yet
and opening for write‐only fails with ENXIO (no such device or
address) unless the other end has already been opened.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-08-21 12:04:51 -03:00
Christian Boltz
fbe68f0078
collapse_log(): use final_name
Now that we have `final_name` as shortcut for
`hashlog[aamode][full_profile]['final_name']`, update the code that used
the long version to make it more readable.
2023-08-20 15:50:20 +02:00
Christian Boltz
74265e8ded
collapse_log(): Attach null-* events to correct target profile
ask_exec() and ask_addhat() set
hashlog[aamode][full_profile]['final_name'].

While this was used to get profile and hat split, it was not used as key
for log_dict. This resulted in entries like
log_dict['PERMITTING']['foo//null-/usr/bin/cat']
which are obviously wrong.

Use final_name as log_dict key so that we end up with (assuming child
exec was selected)
log_dict['PERMITTING']['foo///usr/bin/cat']
2023-08-20 15:49:59 +02:00
Christian Boltz
41df2ca366
Ignore ´//null-` peers in signal and ptrace events
Ideally we'd update them to the chosen exec target - but until this is
implemented, it doesn't make sense to ask about adding a //null-* peer
to a profile.
2023-08-20 11:53:08 +02:00
Christian Boltz
adf19138d5
Don't create local/* profile sniplets by default
... and document how to create them if you still want them.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/337
2023-08-20 11:49:10 +02:00
John Johansen
1758b66c9d Merge Increase timeout in test-logprof.py
On (terribly, but real-world) slow buid hosts, running test-logprof.py
fails with a timeout. Increase the timeout so that even those build
hosts get enough time to finish the aa-logprof tests.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1087
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-17 11:04:14 +00:00
Christian Boltz
dd9b7b358f
Increase timeout in test-logprof.py
On (terribly, but real-world) slow buid hosts, running test-logprof.py
fails with a timeout. Increase the timeout so that even those build
hosts get enough time to finish the aa-logprof tests.
2023-08-15 20:49:08 +02:00
John Johansen
b45c10d4de Merge Fix compability with Python < 3.9
str.removeprefix() was introduced in Python 3.9. Replace it with
backwards-compatible code.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1085
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-15 13:04:06 +00:00
Christian Boltz
c175e414c8
Fix compability with Python < 3.9
str.removeprefix() was introduced in Python 3.9. Replace it with
backwards-compatible code.
2023-08-15 12:40:39 +02:00
John Johansen
5f6e213d23 Prepare for AppArmor 4.0 alpha 2 release
- update version file

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-14 14:36:03 -07:00
John Johansen
d717adfc2f Merge parser: make attach_disconnected.path enable attach_disconnected
Currently you need to use attach_disconnected with
attach_disconnected.path=XXX to be able to attach to a different
location than / whic is ugly and redundant.

Make it so attach_disconnected.path implies attach_disconnected.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1084
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>
2023-08-14 21:28:40 +00:00
John Johansen
4a21bd104c parser: make attach_disconnected.path enable attach_disconnected
Currently you need to use attach_disconnected with
attach_disconnected.path=XXX to be able to attach to a different
location than / whic is ugly and redundant.

Make it so attach_disconnected.path implies attach_disconnected.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-14 13:28:31 -07:00
John Johansen
f9036d57de Merge document that attach_disconnected.path expexts =PATH
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1083
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-14 20:28:26 +00:00
Christian Boltz
c87dd7985f
document that attach_disconnected.path expexts =PATH 2023-08-14 22:22:02 +02:00
John Johansen
8eee4de83e Merge parser: add support for attach_disconnected.path
Add support for specifying the path prefix used when attach disconnected
is specified.

TODO: add regression tests

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/661
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-08-14 14:15:25 +00:00
John Johansen
dbb2a1d0bb tests: regression, add basic regression tests
Add a couple basic attach disconnected regression tests

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-14 01:42:34 -07:00
John Johansen
b46b2662ff parser: add support for attach_disconnected.path
Add support for specifying the path prefix used when attach disconnected
is specified. The kernel supports prepending a different value than
/ when a path is disconnected. Expose through a profile flag.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-08-14 01:42:28 -07:00