Commit graph

1746 commits

Author SHA1 Message Date
Georgia Garcia
63676459c4 parser: encode create permission separately from the others
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 10:33:33 -03:00
Georgia Garcia
9ed04cb01e parser: introduce network label attribute
We want to be able to determine label in the future and build the
policy dfa based on its presence or not.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 10:33:33 -03:00
Georgia Garcia
2a885872a3 parser: ip size encoding should be an enum, not the ip size
According to the protocol expected by the kernel, the field
representing the ip size should be an enum instead of the actual ip
size. This is more future-proof.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 10:33:33 -03:00
Georgia Garcia
989501428e parser: initial steps into encoding protocol properly
Before the inet patches, protocol was not handled, so the information
was ignored. This patch introduces the ability to start mediating
protocol.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 10:33:33 -03:00
Christian Boltz
d1d39d176e Merge parser(Makefile): don't ship /var in downstream packages
Should help with building /var free images downstream.

See below: https://gitlab.com/apparmor/apparmor/-/merge_requests/1167#note_1798547092

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1167
Approved-by: Christian Boltz <apparmor@cboltz.de>
Merged-by: Christian Boltz <apparmor@cboltz.de>
2024-03-08 12:53:32 +00:00
Max Gautier
2d654477f2
parser(Makefile): dont install /var/lib/apparmor
This directory is not used anymore.
This help downstream build of /var free images.

Links: https://0pointer.net/blog/fitting-everything-together.html
2024-03-08 10:18:16 +01: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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Christian Boltz
c87dd7985f
document that attach_disconnected.path expexts =PATH 2023-08-14 22:22:02 +02: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