Commit graph

496 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Georgia Garcia
64c1eb9cda tests: fix feature test
Fixes: 81f0b84d ("tests: fix feature checking if it's a directory")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-08-01 16:20:20 -03: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
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
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
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
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
fef3eb3693 Merge add userspace support for io_uring mediation
```
io_uring rules have the following format:

io_uring [<access_mode>] [<label>],
access_mode := 'sqpoll'|'override_creds'
label := 'label' '=' <target label>
```

You can use the following kernel tree with the io_uring mediation patch to test this feature https://gitlab.com/georgiag/apparmor-kernel/-/commits/io_uring

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/993
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-06-29 21:38:02 +00:00
John Johansen
d4b0fef10a parser: fix rule flag generation change_mount type rules
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048
made it so rules like

  mount slave /snap/bin/** -> /**,

  mount /snap/bin/** -> /**,

would get passed into change_mount_type rule generation when they
shouldn't have been. This would result in two different errors.

1. If kernel mount flags were present on the rule. The error would
   be caught causing an error to be returned, causing profile compilation
   to fail.

2. If the rule did not contain explicit flags then rule would generate
   change_mount_type permissions based on souly the mount point. And
   the implied set of flags. However this is incorrect as it should
   not generate change_mount permissions for this type of rule. Not
   only does it ignore the source/device type condition but it
   generates permissions that were never intended.

   When used in combination with a deny prefix this overly broad
   rule can result in almost all mount rules being denied, as the
   denial takes priority over the allow mount rules.

Fixes: https://bugs.launchpad.net/apparmor/+bug/2023814
Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1211989
Fixes: 9d3f8c6cc ("parser: fix parsing of source as mount point for propagation type flags")
Fixes: MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1048
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1054

Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit 86d193e183)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-06-21 01:18:14 -07:00
Georgia Garcia
9d3f8c6cc0 parser: fix parsing of source as mount point for propagation type flags
Before 300889c3a, mount rules would compile policy when using source
as mount point for rules that contain propagation type flags, such as
unbindable, runbindable, private, rprivate, slave, rslave, shared, and
rshared. Even though it compiled, the rule generated would not work as
expected.

This commit fixes both issues. It allows the usage of source as mount
point for the specified flags, albeit with a deprecation warning, and
it correctly generates the mount rule.

The policy fails to load when both source and mount point are
specified, keeping the original behavior (reference
parser/tst/simple_tests/mount/bad_opt_10.sd for example).

Fixes: https://bugs.launchpad.net/bugs/1648245
Fixes: https://bugs.launchpad.net/bugs/2023025

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-06-07 20:16:50 -03:00
Georgia Garcia
feb5069f67 tests: add io_uring regression tests
Note that the tests add the dependency of liburing.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-05-03 16:04:29 +02:00
Jon Tourville
9a760def8d Check for newer mount options in regression test
The mount options MS_LAZYTIME and MS_NOSYMFOLLOW were added in
kernels 4.0 and 5.10, respectively. Update the mount test script
and helper to skip testing those options if they are not available.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-03 08:51:28 +00:00
John Johansen
59b4109a8b Merge fix af_unix tests for v8 networking.
The unix network tests are not being run on a v8 network capable kernel. Under v8 there needs to be some adjustments to the tests because unix rules get downgraded to the socket rule ```network unix,``` which does not have the same set of conditionals or fine grained permissions, meaning some tests that would fail under af_unix (like missing permission tests) will pass under v8 network rules.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/893
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-05-01 12:10:10 +00:00
John Johansen
f3d5531516 regression tests: make mount regression tests report skipped options
Don't silently skip options so that we know what is being tested.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 05:50:09 -07:00
Georgia Garcia
608c8a1966 tests: fix profile generation for multiple qualifiers
When the replacement regex for multiple qualifiers matches, the
capture group variables ($1, $2, etc) are overwritten to match the
most recent regex. Since there are no capture groups in the 's/,/ /g'
regex, then $2 was empty, causing an error on policy generation.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-04-25 10:08:21 -03:00
Georgia Garcia
689e0c5ed0 tests: add options to mount tests
This improvement only includes filesystem-independent mount options.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-04-25 10:08:21 -03:00
John Johansen
1fc38dbd2a regression tests: switch from bashism == to posix str comparison =
the == string comparison is a bashism. switch to posix supported =

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 20:34:21 -07:00
John Johansen
f47d5c70a3 fix af_unix tests for v8 networking.
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 20:27:52 -07:00
Georgia Garcia
53d4e341e1 tests: force dbus-daemon to generate an abstract socket
dbus 1.14.4 changed the behavior of unix:tmpdir to be equivalent to
unix:dir, which cases dbus-daemon to generate path based sockets,
instead of the previous abstract sockets. [1]
In this change we force dbus-daemon to generate an abstract socket by
specifying the abstract socket address in the command.

[1] https://gitlab.freedesktop.org/dbus/dbus/-/blob/dbus-1.14/NEWS#L64

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-03-27 16:11:36 -03:00
Georgia Garcia
6a3793eceb tests: add qualifier option to mqueue profile generation
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-01-11 21:46:56 +00:00
Georgia Garcia
a93e1ee3cc tests: fix use of deny qualifier on policy generation for mqueue tests
The mqueue tests were using the previous format which was specific for
capabilities. The qual= prefix should be used instead.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-01-11 21:45:53 +00:00
John Johansen
223036d952 Merge add dbus-broker support on regression tests
dbus-broker requires some modification of the test suite. In summary:

* refactor to support starting and stopping both dbus and dbus-broker.
* Make it so we can run the tests on each, where appropriate
* skip unrequested reply and eavesdrop tests for dbus broker because they are not supported.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/965
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-01-07 00:08:10 +00:00
Georgia Garcia
790b17e1dc tests: add dbus-broker support on regression tests
DBus Broker was enabled for the dbus_message and dbus_service
regression tests.

The dbus_eavesdropping test does not run with dbus-broker because
eavesdropping was deprecated in favor or monitoring, so new tests for
the "BecomeMonitor" method need to be added.

The dbus_unrequested_reply test is also not supported by dbus-broker,
therefore the tests are skipped.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-01-06 20:15:41 +00:00
John Johansen
f0bc1a89a4 Merge regression tests: fix bogon patch characters in Makefile
Commit 8cf3534a5 ("tests regression: fix failure on older versions of
Make") from https://gitlab.com/apparmor/apparmor/-/merge_requests/639
was incorrectly applied, including the `+` prefixes from the proposed
patch. This causes the sysctl syscall() checks to not correctly be
applied and results in a mismatch of expectations in the
syscall_sysctl.sh test script, causing it and the testsuite to fail.

Thus, remove the bogon `+` characters from the Makefile, to make
USE_SYSCTL be set correctly.

Fixes: 8cf3534a5 ("tests regression: fix failure on older versions of Make")
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/963
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Approved-by: Christian Boltz <apparmor@cboltz.de>
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-01-05 00:44:37 +00:00
Georgia Garcia
c42efa510e tests: fix profile generation for dbus test
The test "eavesdrop (confined w/o dbus perms)" was failing for the
wrong reason. While it should fail because it is missing dbus rules, it
was actually failing because it didn't have the required unix rule.

The error message was:
"FAIL: Failed to open connection to "session" message bus: Failed to open socket: Permission denied"

Corresponding audit log:
[28306.743863] audit: type=1400 audit(1671048091.505:297): apparmor="DENIED" operation="create" class="net" profile="/home/georgia/apparmor/tests/regression/apparmor/dbus_eavesdrop" pid=6787 comm="dbus_eavesdrop" family="unix" sock_type="stream" protocol=0 requested_mask="create" denied_mask="create" addr=none

After the change, the error message is:
FAIL: Failed to open connection to "session" message bus: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender="(null)" (inactive) interface="org.freedesktop.DBus" member="Hello" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)

Corresponding audit log:
[28444.248268] audit: type=1107 audit(1671048229.009:300): pid=6826 uid=0 auid=1000 ses=5 subj=unconfined msg='apparmor="DENIED" operation="dbus_method_call"  bus="session" path="/org/freedesktop/DBus" interface="org.freedesktop.DBus" member="Hello" mask="send" name="org.freedesktop.DBus" pid=6854 label="/home/georgia/apparmor/tests/regression/apparmor/dbus_eavesdrop" peer_label="unconfined" exe="/usr/bin/dbus-daemon" sauid=0 hostname=? addr=? terminal=?'

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-01-04 18:26:10 +00:00
Georgia Garcia
8d3aab9795 tests: add write permission to output on dbus test profile
The profile generated by dbus did not include this rule
which caused the following DENIED audit logs:

[26937.013475] audit: type=1400 audit(1671046721.776:246): apparmor="DENIED" operation="getattr" class="file" profile="/home/georgia/apparmor/tests/regression/apparmor/dbus_message" name="/tmp/sdtest.5720-14413-VQMPsH/output.dbus_message" pid=5866 comm="dbus_message" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-01-04 18:26:10 +00:00
Steve Beattie
11bd79e39a
regression tests: fix bogon patch characters in Makefile
Commit 8cf3534a5 ("tests regression: fix failure on older versions of
Make") from https://gitlab.com/apparmor/apparmor/-/merge_requests/639
was incorrectly applied, including the `+` prefixes from the proposed
patch. This causes the sysctl syscall() checks to not correctly be
applied and results in a mismatch of expectations in the
syscall_sysctl.sh test script, causing it and the testsuite to fail.

Thus, remove the bogon `+` characters from the Makefile, to make
USE_SYSCTL be set correctly.

Fixes: 8cf3534a5 ("tests regression: fix failure on older versions of Make")
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2023-01-03 10:03:32 -08:00
Georgia Garcia
47ffef4c39 tests: fix variable type for getopt
getopt returns an int, not a char.
Error caused by this issue could only be observed on non-x86 systems.
Closes LP#2000359

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-01-03 14:08:59 -03:00
John Johansen
b5f558962f Merge ipc message queue rule support
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/858
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-12-05 03:04:48 +00:00
Georgia Garcia
3d422215ba tests: add sysv message queue regression tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-22 19:31:15 +00:00
Georgia Garcia
cd85ca9777 tests: add posix message queue regression tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2022-11-22 19:31:15 +00:00
Georgia Garcia
c6f1981cd8 tests: expand userns tests to use setns
Setns is used to associate to an existing user namespace, so the
kernel security hook for user namespace creation is not called.
The restriction for setns is that it should have the capability
sys_admin.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-22 14:45:54 +00:00
Georgia Garcia
592a0743f0 tests: add userns tests using unshare
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-22 14:28:33 +00:00
Jon Tourville
f6bfd141bd Support rule qualifiers in regression tests
This allows regression tests to generate profiles that use rule qualifiers,
such as allow, deny, and audit. Qualifiers can be specified for a rule by
prepending 'qual=', followed by a comma-separated list of rule qualifiers,
then a ':', then the rule itself.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2022-11-04 09:27:17 +00:00
Georgia Garcia
0727da47b3 tests: add userns regression tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-04 08:29:45 +00:00
Georgia Garcia
ffd74aadb1 tests: extend kernel_features to support check for feature in file
The test kernel_features only checked if the feature file exists, but
there are cases when we need to check if the feature is part of the
file's content. For example, we might want to check if a mode is present
in the feature "mask" file.

This is already supported by libapparmor's aa_features_supports.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2022-11-04 08:29:07 +00:00
John Johansen
571cec5036 Merge Add regression test summary
Print out a summary of the tests that passed and failed at the end of the
regression tests. Merge the tests and alltests make targets since they
only differ in which tests are run.


Signed-off-by: Jon Tourville <jon.tourville@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/942
Approved-by: Steve Beattie <gitlab@nxnw.org>
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2022-11-03 13:20:20 +00:00
Jon Tourville
e30696c484 Add regression test summary
Print out a summary of the tests that passed and failed at the end of the
regression tests. Merge the tests and alltests make targets since they
only differ in which tests are run.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2022-11-03 12:44:21 +00:00
Jon Tourville
f525706407 Add ability to execute tests as different users
This update to the regression test framework allows a test script to
execute a test binary as a different user by passing '-u <username>'
to the settest function.

Signed-off-by: Jon Tourville <jon.tourville@canonical.com>
2022-11-01 15:40:18 +00:00