Commit graph

6807 commits

Author SHA1 Message Date
Daniel Richard G
018efdeb9d firefox: fix app name and DBus access 2023-07-25 20:04:26 -04:00
John Johansen
17a521ff50 Merge ask_exec: Stop checking for CMD_nx (named exec)
... because it gets translated to CMD_px or CMD_cx earlier in the
function.

Also add a safety check for unknown answers.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1072
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-07-19 21:17:35 +00:00
John Johansen
853b138537 Merge libapparmor: fix dynamic linkage
It appears that lto1 does not support -dynamic, and that ld no longer
documents -dynamic. Which results in the following build failure
when usine lto1 for link time optimizations

```
[   45s] libtool: link: gcc -shared  -fPIC -DPIC  .libs/grammar.o .libs/libaalogparse.o .libs/kernel.o .libs/scanner.o .libs/private.o .libs/features.o .libs/kernel_interface.o .libs/policy_cache.o .libs/PMurHash.o    -flto-partition=none -O2 -fstack-protector-strong -flto=auto -dynamic -Wl,--version-script=../src/libapparmor.map -flto=auto   -pthread -Wl,-soname -Wl,libapparmor.so.1 -o .libs/libapparmor.so.1.17.0
[   45s] lto1: warning: unrecognized gcc debugging option: y
[   45s] lto1: warning: unrecognized gcc debugging option: n
[   45s] lto1: warning: unrecognized gcc debugging option: m
[   45s] lto1: warning: unrecognized gcc debugging option: i
[   45s] lto1: warning: unrecognized gcc debugging option: c
```

Switch to -Bdynamic which is documented.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1071
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>
2023-07-19 21:16:36 +00:00
John Johansen
d6673f95d2 Merge tests: fix feature checking if it's a directory
The test to check if the kernel supports a feature covers two cases:
1. The file/directory indicates a feature is supported.
2. The feature is supported if it's in the contents of the file.

When the intended check is for case 1, and the file does not exist,
then the code checks if it's case 2, but since it was not supposed to
be, we end up grepping a directory, causing an error message. Fix this
by checking if we're grepping a file.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1074
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-07-19 21:16:23 +00:00
John Johansen
b2274a7f5d Merge Revert "policy: pin policy to 4.0 abi for dev"
This reverts commit 460c3d5b59.

The 4.0 ABI was pinned for the development cycle but it can cause
in-tree uses of parser/parser.conf to fail if it cannot find the 4.0
file in /etc/apparmor.d/abi/.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1073
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-07-19 21:14:45 +00:00
Georgia Garcia
81f0b84da5 tests: fix feature checking if it's a directory
The test to check if the kernel supports a feature covers two cases:
1. The file/directory indicates a feature is supported.
2. The feature is supported if it's in the contents of the file.

When the intended check is for case 1, and the file does not exist,
then the code checks if it's case 2, but since it was not supposed to
be, we end up grepping a directory, causing an error message. Fix this
by checking if we're grepping a file.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-07-19 17:46:13 -03:00
Georgia Garcia
10529a6db7 Revert "policy: pin policy to 4.0 abi for dev"
This reverts commit 460c3d5b59.

The 4.0 ABI was pinned for the development cycle but it can cause
in-tree uses of parser/parser.conf to fail if it cannot find the 4.0
file in /etc/apparmor.d/abi/.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-07-19 17:37:24 -03:00
Christian Boltz
f1ab009a09
ask_exec: Stop checking for CMD_nx (named exec)
... because it gets translated to CMD_px or CMD_cx earlier in the
function.

Also add a safety check for unknown answers.
2023-07-19 21:41:43 +02:00
John Johansen
94082cc5e4 libapparmor: fix dynamic linkage
It appears that lto1 does not support -dynamic, and that ld no longer
documents -dynamic. Which results in the following build failure
when usine lto1 for link time optimizations

[   45s] libtool: link: gcc -shared  -fPIC -DPIC  .libs/grammar.o .libs/libaalogparse.o .libs/kernel.o .libs/scanner.o .libs/private.o .libs/features.o .libs/kernel_interface.o .libs/policy_cache.o .libs/PMurHash.o    -flto-partition=none -O2 -fstack-protector-strong -flto=auto -dynamic -Wl,--version-script=../src/libapparmor.map -flto=auto   -pthread -Wl,-soname -Wl,libapparmor.so.1 -o .libs/libapparmor.so.1.17.0
[   45s] lto1: warning: unrecognized gcc debugging option: y
[   45s] lto1: warning: unrecognized gcc debugging option: n
[   45s] lto1: warning: unrecognized gcc debugging option: m
[   45s] lto1: warning: unrecognized gcc debugging option: i
[   45s] lto1: warning: unrecognized gcc debugging option: c

Switch to -Bdynamic which is documented.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-17 21:04:11 -07:00
Steve Beattie
b6bd4f5421
parser: improve errors.py test coverage, convert to unittest.main
Merge the following commits:

- [12cf66ff0] parser/errors.py: check error message + error code for non-existent profiles
- [87896b949] parser/errors.py: convert to unittest.main()

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1070
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Approved-by: John Johansen <john@jjmx.net>
2023-07-13 13:43:40 -05:00
Steve Beattie
87896b9496
parser/errors.py: convert to unittest.main()
Do this to simplify test identification, and also support the different
invocation mechanisms of unittest, like running individual tests.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1070
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Approved-by: John Johansen <john@jjmx.net>
2023-07-13 13:40:42 -05:00
Steve Beattie
12cf66ff0b
parser/errors.py: check error message + error code for non-existent profiles
Add tests for passing the parser a file that doesn't exist, a symlink
to a file that doesn't exist, and a directory that contains that
latter.  Also include tests for different levels of -j passed as an
argument. These tests are based on the fixing commit 1259319508
("parser: Fix parser failing to handle errors when setting up work")

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1070
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Approved-by: John Johansen <john@jjmx.net>
2023-07-13 13:38:52 -05:00
Georgia Garcia
a271b2474c Prepare for AppArmor 4.0 alpha release
- update version file
- update library version

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-07-11 13:23:38 -03:00
Georgia Garcia
3cd2baccdd Merge parser: rework perms rule merging
Instead of pushing the cmp logic for rule merging into each rule
class make it the default behavior for the perms_rule_t parent class.
Also save off the original perms for the merged rule.

For classes that don't want perms merging add an alternate
dedup_perms_rule_t clase.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1069
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-07-11 12:10:23 +00:00
John Johansen
5e8567c9e9 parser: rework perms rule merging
Instead of pushing the cmp logic for rule merging into each rule
class make it the default behavior for the perms_rule_t parent class.
Also save off the original perms for the merged rule.

For classes that don't want perms merging add an alternate
dedup_perms_rule_t clase.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-10 20:04:53 -07:00
John Johansen
74b101faa8 Merge parser: improve dfa generation
speedup and reduce memory usage of dfa generation

A variety of changes to improve dfa generation
- By switching to Nodevec instead of Node sets we can reduce memory usage slightly and reduce code
- By using charsets for chars we reduce code and increase chances of node merging/reduction which reduces memory usage slightly
- By merging charsets we reduce the number of nodes

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1066
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-07-11 02:26:10 +00:00
John Johansen
1dfd26aea7 Merge parser: add permission merging
By changing the compare function from each rule to use class_rule_t,
instead of perms_rule_t, we temporarily ignore if permissions are
different. If every rule attribute is the same, then the permissions
can be merged. This is done at the perms_rule_t's level.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1068
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-07-11 02:18:45 +00:00
John Johansen
806b097d9a Merge tests: only compile and run io_uring tests if liburing-dev is installed
Compiling of io_uring tests fail if liburing-dev is not installed.
Also, the tests were not running as part of the test suite.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1067
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-07-10 21:05:21 +00:00
Georgia Garcia
cdb5e501d6 parser: add permission merging
By changing the compare function from each rule to use class_rule_t,
instead of perms_rule_t, we temporarily ignore if permissions are
different. If every rule attribute is the same, then the permissions
can be merged. This is done at the perms_rule_t's level.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-07-10 18:01:32 -03:00
John Johansen
1279f85e4a Merge parser: Improve rule merging/dedup
Currently File rules are the only rules that have rule dedup/merging performed. Extend support for rule merging to all other rule types.

This can result in a small performance regression when rules can not be merged/deduped but can result in a large performance increase when lots of rules can be eliminated.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1065
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-07-10 19:13:25 +00:00
Georgia Garcia
3b832dd313 Merge tests/regression/apparmor/capabilities.sh: fail iopl/ioperm with lockdown
In MR #1063 the tests/regression/apparmor/syscall.sh script was updated to
account for kernel lockdown, but the capabilities.sh script also exercises these
system calls so this also needs to be updated as well.

Also required to fix issue #226.

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

Closes #226
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1064
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-07-10 13:09:48 +00:00
John Johansen
501e87a3f2 parser: Cleanup parser control flags, so they display as expected to user
Instead of having multiple tables, since we have room post split
of optimization and dump flags just move all the optimization and
dump flags into a common table.

We can if needed switch the flag entry size to a long in the future.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-08 19:58:59 -07:00
John Johansen
1754b4da69 parser: add flags to control rule merging
Add the ability to control whether rule merging is done.

TODO: in the furture cleanup display of flags split accross two tables

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-08 01:06:50 -07:00
John Johansen
e84e481263 parser: cleanup and rework optimization and dump flag handling
In preparation for more flags (not all of the backend dfa based),
rework the optimization and dump flag handling which has been exclusively
around the dfa up to this point.

- split dfa control and dump flags into separate fields. This gives more
  room for new flags in the existing DFA set
- rename DFA_DUMP, and DFA_CONTROL to CONTROL_DFA and DUMP_DFA as
  this will provide more uniform naming for none dfa flags
- group dump and control flags into a structure so they can be passed
  together.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:47:41 -07:00
John Johansen
c5f2fcbb95 parser: add rule merging for dbus rules
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:47:36 -07:00
John Johansen
5e713276ca parser: add rule merging for af_unix rules
this is reuired because af_rule merging does not take into account
the potential af_unix addresses and could incorrectly merge af_unix
rules.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:46:54 -07:00
John Johansen
00553a6dd5 parser: add rule mergeing for af_rules
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:46:19 -07:00
John Johansen
08a0970d1f parser: add io_uring rule merging
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:45:38 -07:00
John Johansen
ca976bf5cb parser: add rule merging for mqueue rules
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:41:10 -07:00
John Johansen
0f660828e1 parser: add rule merging for ptrace rules
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:40:20 -07:00
John Johansen
fd20c226e0 parser: add rule merging for userns rules
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:39:50 -07:00
John Johansen
53b99a82f6 parser: add rule merging for signals
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:39:33 -07:00
John Johansen
3ede2c46cf parser: add rule dedup of mount rules
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:38:47 -07:00
John Johansen
7d9958890f parser: finish basic infrastructure for rule merging
Currently only file rules get merged. Finish adding basic support
for rule merging and make the default the behavior to dedup
merge rules that are exact matches.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-07 17:35:37 -07:00
Georgia Garcia
88baa28799 common: fix newline on Makefile rules
The required extra newline was removed unintentionally in 0b719e4f8.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-07-05 11:08:32 -03:00
Georgia Garcia
502b83a2a6 tests: only compile and run io_uring tests if liburing-dev is installed
Compiling of io_uring tests fail if liburing-dev is not installed.
Also, the tests were not running as part of the test suite.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-07-05 11:08:28 -03:00
John Johansen
dbca8ebb89 parser: Improve the rule skip test.
Rules can be marked as being deleted/merged, and should be skipped on
further processing.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-05 04:40:27 -07:00
Alex Murray
eafae0dd03
tests/regression/apparmor/capabilities.sh: fail iopl/ioperm with lockdown
In MR #1063 the tests/regression/apparmor/syscall.sh script was updated to
account for kernel lockdown, but the capabilities.sh script also exercises these
system calls so this also needs to be updated as well.

Also required to fix issue #226.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2023-07-05 13:25:25 +09:30
John Johansen
f6b179010e Merge parser: add support for exposing a debug flag to policy
Allowing access to a debug flag can greatly improve policy debugging.
This is different than the debug mode of old, that was removed. It only
will trigger additional messages to the kernel ring buffer, not
the audit log, and it does not change mediation.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1060
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-07-04 06:58:16 +00:00
John Johansen
5dda593345 Merge policy: update to use 4.0 abi
Begin preparing policy for the 4.0 release. This may result in new
denials. This is expected and needed to make sure policy is ready
for the 4.0 release.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1061
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: John Johansen <john@jjmx.net>
2023-07-04 06:57:52 +00:00
John Johansen
7393aaac21 Merge tests/regression/apparmor/syscall.sh: fail iopl/ioperm with lockdown
When kernel lockdown is enabled the ioperm and iopl tests will fail regardless
since lockdown prevents these syscalls before AppArmor has a chance to mediate
them. So workaround this by detecting when lockdown is enabled and expect the
tests to fail in that case.

Fixes issue #226.

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

Closes #226
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1063
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-07-04 06:52:33 +00:00
Alex Murray
6ca4992107
tests/regression/apparmor/syscall.sh: fail iopl/ioperm with lockdown
When kernel lockdown is enabled the ioperm and iopl tests will fail regardless
since lockdown prevents these syscalls before AppArmor has a chance to mediate
them. So workaround this by detecting when lockdown is enabled and expect the
tests to fail in that case.

Fixes issue #226.

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2023-07-04 15:45:45 +09:30
John Johansen
24f834b128 parser: allow character sets to be used as exact match permissions
character sets are just a way of enumerating to exact match rules
more succinctly, so loosen the exact match check to allow them.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-03 00:53:26 -07:00
John Johansen
9e9ca7e55d Drop code that is now unused because of the conversion to NodeVec
Drop NodeCache and hashedNodes as they are no longer used.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-03 00:53:26 -07:00
John Johansen
61c20a0ae8 convert anodes to using NodeVecs instead of NodeSets
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-03 00:53:26 -07:00
John Johansen
53d00b4d2b rename hashedNodeVec to NodeVec
Shorten the name length by dropping the leading "hashed".

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-03 00:49:56 -07:00
Daniel Richard G
3f6ebfd218 firefox: updates from usage monitoring 2023-07-03 00:49:56 -07:00
John Johansen
367babf9cb parser: add support for exposing a debug flag to policy
Allowing access to a debug flag can greatly improve policy debugging.
This is different than the debug mode of old, that was removed. It only
will trigger additional messages to the kernel ring buffer, not
the audit log, and it does not change mediation.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-07-02 03:02:02 -07:00
John Johansen
460c3d5b59 policy: pin policy to 4.0 abi for dev
TO BE REVERTED: this is a dev patch to help make sure policy is getting
updated.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-30 23:43:40 -07:00
John Johansen
f1b4da2f64 policy: update to use 4.0 abi
Begin preparing policy for the 4.0 release. This may result in new
denials. This is expected and needed to make sure policy is ready
for the 4.0 release.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-30 23:36:12 -07:00