Commit graph

6486 commits

Author SHA1 Message Date
Georgia Garcia
6c8331a7d0 libapparmor tests: add io_uring denied logs
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-05-03 16:04:32 +02:00
Georgia Garcia
eb801d8ccf libapparmor: add support for tcontext on logparsing
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-05-03 16:04:32 +02: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
Georgia Garcia
50dd41f920 parser: add io_uring simple tests
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-05-03 16:03:52 +02:00
Georgia Garcia
e5e920d178 parser: add parser 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>

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-05-03 16:03:52 +02:00
Jon Tourville
c46bf8944a Merge 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>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1024
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Jon Tourville <jon.tourville@canonical.com>
2023-05-03 11:40:32 +00: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
09b35f836b Merge Abstractions: better integration
This is the first MR of a possibly very long list of MR in order to upstream stable abstraction & profiles previously tested in https://github.com/roddhjav/apparmor.d

This first MR focuses on integrating abstraction completion from the `*.d` directory in [apparmor.d/abstractions](https://github.com/roddhjav/apparmor.d/tree/main/apparmor.d/abstractions)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/995
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-05-02 12:34:04 +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
c37be61d17 Merge Issue 312: added missing kernel mount options
This patch adds the following mount options: 'nostrictatime',
'lazytime', and 'nolazytime'.

The MS_STRICTATIME mount flag already existed, and 'nostrictatime' was
listed along with 'strictatime' in the comments of parser/mount.cc, so
this patch adds a mapping for 'nostrictatime' to clear MS_STRICTATIME.

Additionally, the Linux kernel includes the 'lazytime' option with
MS_LAZYTIME mapping to (1<<25), so this patch adds MS_LAZYTIME to
parser/mount.h and the corresponding mappings in parser/mount.cc for
'lazytime' and 'nolazytime'.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1005
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-04-27 17:14:29 +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
John Johansen
89bc617d0d parser: fix conflicting mnt flag values message to have a space
The conflicting flags value message was hard to read
  conflicting flag value = lazytimenolazytime

change it to
  conflicting flag values = lazytime, nolazytime

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 04:05:44 -07:00
John Johansen
b51602233d docs apparmor.d: add missing mount options to man page
Add the missing options nostrictatime, lazytime, and nolazytime to the
apparmor.d manpage.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 04:05:44 -07:00
John Johansen
cfb77309d6 parse tests: add parse tests for missing mount options
add simple parsing tests for nostrictatime, lazytime, nolazytime

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 04:05:44 -07:00
Oliver Calder
231c469d86 parser: added nosymfollow mount option
Adds the corresponding `MS_NOSYMFOLLOW` flag to parser/mount.h as well,
defined as (1 << 8) just as in the util-linux and the kernel.

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 03:21:26 -07:00
Oliver Calder
257b3cfbf6 Added MS_LAZYTIME to MS_ALL_FLAGS
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 03:20:34 -07:00
Oliver Calder
bc64b824fa Issue 312: added missing kernel mount options
This patch adds the following mount options: 'nostrictatime',
'lazytime', and 'nolazytime'.

The MS_STRICTATIME mount flag already existed, and 'nostrictatime' was
listed along with 'strictatime' in the comments of parser/mount.cc, so
this patch adds a mapping for 'nostrictatime' to clear MS_STRICTATIME.

Additionally, the Linux kernel includes the 'lazytime' option with
MS_LAZYTIME mapping to (1<<25), so this patch adds MS_LAZYTIME to
parser/mount.h and the corresponding mappings in parser/mount.cc for
'lazytime' and 'nolazytime'.

Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-27 03:20:34 -07:00
John Johansen
cacb812b58 Merge parser: fix chfa quivalence class handling
The chfa equivalence class shouldn't be a reference. Its needs to
actually exist and be part of the class during later method calls.
As a reference it leads to bad references when used later.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1015
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-04-26 06:22:54 +00:00
John Johansen
e6e5e7981f Merge expand mount tests
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1006
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-04-25 13:55:03 +00: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
f8117a384f parser: fix chfa quivalence class handling
The chfa equivalence class shouldn't be a reference. Its needs to
actually exist and be part of the class during later method calls.
As a reference it leads to bad references when used later.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-04-25 05:55:34 -07:00
John Johansen
0e83933fa8 Merge Drop profile_ filename prefix for named profiles
Historically, if you create a `profile foo /bin/foo` with aa-logprof (by
choosing "named exec"), it will be saved as `/etc/apparmor.d/profile_foo`

This patch drops the `profile_` filename prefix so that the filename
will be `/etc/apparmor.d/foo`

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1014
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-04-25 02:29:44 +00:00
John Johansen
30dd1cec42 Merge Fix error when choosing named exec with plane profile names
When a user choooses to execute to a named profile (not: named child),
make sure to get the profile filename in the correct way to avoid a crash.

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

I propose this patch for 2.13..master. (Note: I verified that the bug already exists in 2.13, and that this patch fixes it.)

Closes #314
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1013
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-04-25 02:28:28 +00:00
John Johansen
46c8dbe886 Merge CI: check extra profiles for local/ includes
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1012
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-04-25 02:27:00 +00:00
John Johansen
fa86a7f1d9 Merge abstractions/freedesktop.org: allow custom cursors
... by allowing to read all files below ~/.icons instead of only the
directory listing.

I propose this patch for all branches.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1008
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-04-25 02:24:50 +00:00
John Johansen
be9c0937dc Merge Cleanup parser frontend in preparation for extended permissions
The parser front end is inconsistent about how it handles permissions and rules. This makes extending the permission set and fixing inconsistencies between say file and af_unix rules difficult and prone to failures.

This is a set of work to cleanup the frontend parse handling, and middle semantic checks, dedup, and processing of rules and their permissions. It also is starting to lay the ground work for the parser retaining more information to output better error, and debug messages.

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/802
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-04-25 02:15:53 +00:00
Christian Boltz
d4bcd50c5a
Drop profile_ filename prefix for named profiles
Historically, if you create a `profile foo /bin/foo` with aa-logprof (by
choosing "named exec"), it will be saved as `/etc/apparmor.d/profile_foo`

This patch drops the `profile_` filename prefix so that the filename
will be `/etc/apparmor.d/foo`
2023-04-23 19:27:11 +02:00
Christian Boltz
103be8e14b
Fix error when choosing named exec with plane profile names
When a user choooses to execute to a named profile (not: named child),
make sure to get the profile filename in the correct way to avoid a
crash.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/314
2023-04-23 14:49:35 +02:00
Christian Boltz
5bb867dbc0 Merge Add profile for rpcbind
Noticed that this externally-visible service was not confined, so I put together a profile for it.

Please backport to `apparmor-3.[01]` if it looks good!

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1011
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-04-19 20:15:51 +00:00
Christian Boltz
3ddb1677dd
CI: check extra profiles for local/ includes 2023-04-18 22:43:00 +02:00
Daniel Richard G
408e148109 Add profile for rpcbind 2023-04-18 16:35:34 -04:00
Christian Boltz
954b11fc50
abstractions/freedesktop.org: allow custom cursors
... by allowing to read all files below ~/.icons instead of only the
directory listing.
2023-04-16 16:00:27 +02:00
Christian Boltz
8d9985ac0b Merge abstractions/base: allow reading tzdata ICU zoneinfo DB
This is used by various applications including libreoffice etc so it may as well
be added to the base abstraction along with the existing zoneinfo DB access.

AVC apparmor="DENIED" operation="open" class="file" profile="snap.libreoffice.calc" name="/usr/share/zoneinfo-icu/44/le/zoneinfo64.res" pid=44742 comm="soffice.bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

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

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1007
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2023-04-11 19:21:08 +00:00
Alex Murray
c691b11d6e
abstractions/base: allow reading tzdata ICU zoneinfo DB
This is used by various applications including libreoffice etc so it may as well
be added to the base abstraction along with the existing zoneinfo DB access.

AVC apparmor="DENIED" operation="open" class="file" profile="snap.libreoffice.calc" name="/usr/share/zoneinfo-icu/44/le/zoneinfo64.res" pid=44742 comm="soffice.bin" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

Signed-off-by: Alex Murray <alex.murray@canonical.com>
2023-04-06 11:50:06 +09:30
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
John Johansen
90b3b5e572 Merge Format aa-notify to follow PEP-8
Update (most of the) code and inline comments/docstrings to follow
https://peps.python.org/pep-0008/ so that future maintenance is slightly
easier.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/996
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-04-01 03:20:07 +00:00
John Johansen
7fa20770db Merge tunables/etc: Improve comments which variable to use
The description of @{etc_ro} and @{etc_rw} were not good enough in
explaining which directories they should contain, and when to use which
of the variables in a profile.

I propose this patch for all branches.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1000
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-04-01 03:17:28 +00:00
John Johansen
cf6539b217 Merge Ignore 'x' in mixed file mode log events
Probably thanks to O_MAYEXEC, denials for file access can now contain a
mix of x (exec) and other file permissions.

The actual exec should appear in a separate "exec" log event, therefore
ignore 'x' in file events for now if it's mixed with other permissions.

Note that file events ("open", "link" etc.) that contain denied_mask="x"
without another permission will still cause an error. (So far, this
hasn't been seen in the wild.)

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

Also add the log line from the bugreport and the (for now) expected
result as test_multi testcase.

I propose this patch for all branches.

Closes #303
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1001
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2023-04-01 03:13:23 +00:00
John Johansen
6f65faa164 Merge syslogd: allow reading /dev/kmsg
Fixes: https://gitlab.com/apparmor/apparmor/-/issues/307

I propose this patch for master and 3.x (the profile in 2.13 is very different which makes automatic merging impossible)

Closes #307
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1003
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: John Johansen <john@jjmx.net>
2023-04-01 03:07:00 +00:00
John Johansen
e6e3f44ff9 parser: cleanup: drop unused add_local_entry and associated vars
The code for add_local_entry is actually currently unused and will
have to change anyways by the time it is. Some drop it and the
associated variables.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 02:21:19 -07:00
John Johansen
68421547a1 refactor prefix and x check during parser
Reduce duplicate code and another step towards converting file rules
to rule_t

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 02:21:19 -07:00
John Johansen
9eb23475de parser: refactor rules parser for a common block
Another step towards having a block rule and retaining parsed rule
structure. Setup the parse to use a common block pattern, that when
we are ready will become an actual rule.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 02:21:19 -07:00
John Johansen
dad26e6cd2 parser: add a method for profiles to do rule merging
In preparation for file rules converting to use rule_t add a method
to do rule merging.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 02:21:19 -07:00
John Johansen
8470760e85 parser: add an integer based rule comparison that can be used by merge
Instead of call operator< twice for merge have an integer based
comparison fn.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 02:21:19 -07:00
John Johansen
b061155c9a parser: add flags to rule_t
In preparation for file rules and rule duplication removal add
flags to rule_t with the first flag indicating if the rule is
deleted.

We do this instead of actually deleting the rule so we can hold
on to the rule for debug and printing output in the future.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 02:21:19 -07:00
John Johansen
1acc90e06a parser: add method to test if rules are mergeable/dedupable.
in preparation for file rules switching to rule_t add a method to
indicate whether a particular rule is mergeable/dedupable.

Whether a rule merges or dedups will be up to the rules comparison
and merge methods.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 02:21:19 -07:00
John Johansen
e248014171 parser: carry a rule_t on all rules not just rules that have a class
In preparation for rule comparison and elemination have each rule
carry a type that can be used as the base of comparison. The
rule class is folded into this type.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 02:21:19 -07:00
John Johansen
a2d56c3c74 parser: consolidate rule class handling into aa_class
Instead of having each rule individually handle the class info
introduce a class_rule_t into the hierarchy and consolidate.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2023-03-31 02:21:19 -07:00