Commit graph

1336 commits

Author SHA1 Message Date
Steve Beattie
74df38e284 parser sanity tests: add more mount options tests
Attempt to get clarity on what is valid syntax for mount options and
fstype options.

Note that simple_tests/mount/bad_opt_27.sd is marked TODO, as the
parser accepts it but should not.

Also mark the tests as expecting to fail to raise an exception by the
python utils.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
8f382f5c6b parser: add unix peer addr slash filter equality tests
Test to ensure that slash filtering occurs properly in unix file
peer socket addr paths.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://bugs.launchpad.net/apparmor/+bug/1856738
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
51aedb2118 parser: add mount path slash filtering equality tests
Test to ensure that slash filtering occurs properly in mount path
components.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
80d7e33432 parser: add dbus path slash filtering equality tests
Test to ensure that slash filtering occurs properly in dbus path
components.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
Steve Beattie
9cee676558 parser: add unix addr slash filter equality tests
Test to ensure that slash filtering occurs properly in unix file socket
addr paths.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Bug: https://bugs.launchpad.net/apparmor/+bug/1856738
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:39:16 -07:00
John Johansen
a1978fb1b2 parser: call filter slashes for mount conditionals
The mnt_point and devices conditionals in mount rules are generally
paths and should have slashes filtered after variable expansion.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:14:35 -07:00
John Johansen
35f6d49ec6 parser: call filter slashes for the dbus path conditional
Similar to unix addr rules, the dbus path conditional is more a path
than a profile name and should get its slashes filtered after variable
expansion.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:14:35 -07:00
John Johansen
6af05006d9 parser: Fix expansion of variables in unix rules addr= conditional
The parser is not treating unix addr as a path and filtering slashes
after variable expansion. This can lead to errors where

@{foo}=/a/
unix bind addr=@{foo}/bar,

will always fail because addr is being matched as /a//bar instead of
/a/bar.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/607
Fixes: https://bugs.launchpad.net/apparmor/+bug/1856738
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 04:14:35 -07:00
John Johansen
0a52cf81e3 parser: add support for autobind sockets
af_unix allows for sockets to be bound to a name that is autogenerated.
Currently this type of binding is only supported by a very generic
rule.

  unix (bind) type=dgram,

but this allows both sockets with specified names and anonymous
sockets. Extend unix rule syntax to support specifying just an
auto bind socket by specifying addr=auto

eg.

  unix (bind) addr=auto,

It is important to note that addr=auto only works for the bind
permission as once the socket is bound to an autogenerated address,
the addr with have a valid unique value that can be matched against
with a regular

  addr=@name

expression

Fixes: https://bugs.launchpad.net/apparmor/+bug/1867216
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 03:34:56 -07:00
John Johansen
c9d01a325d parser: don't apply exec mapping computations to the policydb
v8 network permissions extend into the range used by exec mapping
so it is important to not blindly do execmapping on both the
file dfa and policydb dfa any more.

Track what type of dfa and its permissions we are building so
we can properly apply exec mapping only when building the
file dfa.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 03:34:47 -07:00
John Johansen
e92478a9c5 parser: add support for kernel 4.17 v8 networking
Make it so the parser can properly support network socket mediation
in the upstream kernel,

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/521
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-29 03:33:55 -07:00
John Johansen
692f78cf3f init: Add note about snapd policy and early boot to rc.apparmor.functions
Snapd now loads its own policy via its own systemd unit
https://github.com/snapcore/snapd/pull/8467

If A distro is not using snapd systemd unit then dropping snapd policy
from the apparmor unit is a breaking change, distros will either need
to use the snapd systemd unit or revert

0164fd05 init: stop loading snap policy

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-22 12:23:17 -07:00
Jamie Strandboge
0164fd05d6 init: stop loading the snap policy
snapd now loads its snap policy via its own systemd unit, so stop
loading the snap policy in /var/lib/snapd/apparmor/profiles

Fixs: https://launchpad.net/bugs/1871148
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-22 12:09:47 -07:00
John Johansen
d1be977667 parser: add equality test to check that change_hat rule is being inserted
This add a test to ensure that the parser is inserting rules to allow
access to the proc interface for change_hat.

Unfortunately the rule the parser inserts is a bare owner write that
we can't replicate in policy as policy write perm maps to create,
append and write.

So to test equality compare profiles using rules granting access to
the proc attr interface except one uses the append permission and
the other uses write. They will differ in permissions unless the
parser inserts the proc attr write rule for change_hat in which
case the permissions will get merged and we have equivalence.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/626
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-18 03:19:33 -07:00
John Johansen
06d403bdac parser: Fix MR625 to emit proc attr access for all situations
MR625 fixed hats not emitting the rule to access the proc interface
needed for change_hat, but it broke the rule being emitted for the
parent (which used to work).

The proc attr access rule should be emitted for any profile that
is a hat OR any profile that contains hats.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/626
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-17 19:28:23 -07:00
John Johansen
5b850c154f parser: Fix automatic adding of rule for change_hat interface
The parser is supposed to add a rule to profiles if they are a hat
or contain hats granting write access to the kernel interfaces
used to perform the change_hat operation.

Unfortunately the check is broken and currently won't add the
rule to hats (it does add it for the parent).

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/625
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-17 15:02:37 -07:00
John Johansen
69a705707f Merge Pdebug immunix
Convert the two commented-out fprintf() lines in is_merged_x_consistent() to useful debug logging using PDEBUG macro.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/616
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-10 01:06:34 +00:00
Mike Salvatore
ec27d87777 parser: Add a debug msg to reset_parser()
A debug message in reset_parser() gives developers more data about how
the parser is behaving. In addition, it provides much needed context to
the relatively vague debug message in clear_cap_flag().

Another solution might be to pass the profile name into
clear_cap_flag(), however, clear_cap_flag() does not need the profile
name, except potentially for debugging purposes.

Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-09-05 20:07:21 -04:00
Mike Salvatore
5eaf46b4c0 parser: Fix build error when compiling with DEBUG=1
A copy/paste error leads to a build failure due to an undefined variable
"name" in parser_misc.c:clear_cap_flag().

Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-09-05 20:07:15 -04:00
Mike Salvatore
b947ad96f9 parser: convert commented out fprintf() in immunix.h to PDEBUG() 2020-09-05 09:38:53 -04:00
Mike Salvatore
e2237057af parser: Fix formatting in immunix.h:is_merged_x_consistent() 2020-09-04 12:10:35 -04:00
John Johansen
761008f1b6 parser: fix yyerror message to not duplicate file name output
yyerror is outputting the file name twice when not in a profile or
the profilename global is not defined. Drop the second output of
the file name as it just clutters up the error message.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/610
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-09-03 07:19:21 -07:00
John Johansen
fe0d4e8aa3 parser: Fix debug build of flex scanner
yyno_top_state was set as part of getting rid of the need to link against
libfl.

However we actually need to ability when the scanner is built with
debugging. Fix it so the option and libfl linking are conditionally
used based on whether DEBUG is defined.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/609
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-09-02 15:38:12 -07:00
John Johansen
dadc39507b parser: fix --warn and --Werror so they work with --config-file
--config-file is processed early in a separate argument processing
pass. Adjust --warn and --Werror processing so they are done in
both the early and late arg processing pass.

--warn and --Werror must be run in both argument processing passes
so that
1. They can be used with --config-file as long as they are specified
   before --config-file (early pass)
2. They are not overriden by any flags set in the config file, as
   command line options take priority over what is in the config
   file (hence the need for reprocessing in the second pass)

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
3d7cfb29f9 parser: enable printing Werror flag settings
Make it so --Werror=show can display which flags have been set.

In addition update its --help=Werror flag table to display

   ./apparmor_parser --Werror=[Option]

instead of --Warn

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
9c1803d62a parser: cleanup/fix flagtable display for the warn, dump, and Optimize options
This changes the flagtable header from

     warn: --./apparmor_parser [Option]
     -O: --./apparmor_parser [Option]
     dump: --./apparmor_parser [Option]

  to
     ./apparmor_parser: --warn=[Option]
     ./apparmor_parser: -O [Option]
     ./apparmor_parser: --dump=[Option]

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
6e6f99e0b8 parser: add the ability to print what flags are set in option flag tables
Add the ability to show which warnings are enabled by specifying "show"
as an to the --dump, --warn, and --Optimize options

  Eg.
     --warn=show

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
db07b131b5 parser: unify flagtable printing for warn, dump and optimize
warn, dump, and optize share common printing of their option flag
tables, refactor and unify.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
3d54324db0 parser: allow specifying --warn=no-XXX to turn off warnings
Some warning flags are enabled by default, allow a warning to
be disbaled by specifying no- infront of the warning.

  Eg.
    --warn=no-deprecated

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
343024b4a3 parser: Add option --Werror to enable turning warnings into errors
Add basic ability to treat a warning as an error and abort the compile
by specifying the new option --Werror.

  --Werror

will turn all warnings into errors. Where if an warning type is
specified only that type of warning will be turned into an error.

  --Werror=deprecated.

The full list of supported warning types can be found by using

     apparmor_parser --help=warn
   or
     apparmor_parser --help=Werror

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
f5c4927c85 parser: convert remaining pwarn() to flag controlled warns
Make all warnings that go through pwarn() controllable by warning
flags. This adds several new warning control flags, documented in

  --help=warn

Convert --debug-cache to be unified with warning flags. So it can be
set by either
    --debug-cache
  or
    --warn=debug-cache

Also add an "all" option to be able to turn on all warnings.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
d50ada7159 parser: Add warning flag that can toggle a set of developer warnings
Add the flag
  --warn=dev

to be able to toggle several developer warnings with a single flag.

Note: --warn=all is being reserved for a larger patch to warnings
when all warnings are setup with control flags.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
c530c880b1 parser: Add warning flag that can toggle deprecation warnings
Add the flag
  --warn=deprecated

to be able to toggle deprecation warnings

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
0d0686becc parser: Add warning flag for ABI messages
ABI warnings can be to much for a deployed system. Add

  --warn=abi

to control output of abi warnings

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-01 19:42:38 -07:00
John Johansen
398bb20dfd policy: Provide example and base abi to pin pre 3.0 policy
Provide example rules in parser.conf to pin pre 3.0 policy and
appropriate abi files.

abis for vanilla upstream kernels and outoftree network patched
kernels are provided. With both ABIs dropping v8 support from
advertised by the kernel as 2.x policy/userspace did not support it.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/598
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-08-28 12:57:00 -07:00
John Johansen
139fac6062 parser: Add warning to capability_table about the need to update the Makefile
The autogenerated capabilities comparison needs to be updated if the
capability_table structure changes. Add a note by the structure to
make sure the Makefile will get updated if the structure is changed.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/597
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-08-27 01:17:26 -07:00
Steve Beattie
a7fc8bb500
parser/Makefile: fix generated cap comparison against known list
The sed command to manipulate the known cap list (base_cap_names.h) into
a format to match the generated_cap_names.h was buggy because the
trailing '}' would never match anything, leading to failures when built
against 5.8 kernel headers, due to it not replacing the base capabilities
correctly.

Fix this by removing the trailing '}" match and instead match the third
comma-delimited field that matches a capability name, and replace that.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/596
2020-08-26 20:58:14 -07:00
John Johansen
33ff79a9e5
parser/Makefile: use LC_ALL=C when invoking sed
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/596
2020-08-26 20:57:34 -07:00
John Johansen
6cfbb3ff95 Merge parser: replace duplicate warn_once() with common function
The warn_once() function is duplicated in 6 different places. A common, reusable version has been added to parser_common.c.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/590
Acked-by: John Johansen <john.johansen@canonical.com>
2020-08-20 08:54:52 +00:00
John Johansen
a4182119e2 parser: switch arg processing to use constant defines instead of numbers
I screwed up adding the last option, yet again because
EARLY_ARG_CONFIG_FILE was define out of order, and adding the new
option seems to skip a number, ...

Switch to defines to make it easier to update, and keep all these
define numbers together in order.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/579
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-08-20 01:22:03 -07:00
John Johansen
dcc2918665 parser: add an option to allow overriding feature ABI rules
Add an option to allow setting/pinning the feature ABI and overriding
of ABI rules if they exist.

  --override-policy-abi

This option is primarily for profile development and testing without
allowing adjusting feature abis temporarily without modifying the
profile.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/579
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-08-20 01:22:03 -07:00
John Johansen
acb45dc4b0 parser: fix abi rule and pinned feature file interaction
In AppArmor 2 distros could pin the feature file being used by setting
the feature-file option in the config file.

With AppArmor 3 policy is now explicitly tagged with an abi rule.

The problem is the interaction on systems that have a mixture of
AppArmor 2 and AppArmor 3 policy and use feature pinning.

The feature pinning is required to make the apparmor 2 policy behave
as expected but it also overrides the abi rules that are explicitly
set as part of the policy. This means we either have the apparmor 2
pinned policy working as desired or the apparmor 3 policy, but not
both.

To fix this make setting the flag on command line or in config file
lower priority than an abi rule specified in policy. The ability
to override abi rules will be added in a separate patch.

The Priority ordering to determine the policy abi to use is
1. Use abi rules if present
2. if no abi rule use command line option
3. if no abi rule or command line option use config setting
4. if none of the above use the default abi

PR: https://gitlab.com/apparmor/apparmor/-/merge_requests/579
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-08-20 01:22:03 -07:00
Mike Salvatore
52d9529d1b parser: replace duplicate warn_once() with common function
The warn_once() function is duplicated in 6 different places. A common,
reusable version has been added to parser_common.c.

Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com>
2020-08-09 17:56:31 -04:00
John Johansen
c810c755b1 parser: allow backwards mapping of a capability
If a capability is known in policy but not by the kernel, check to see if it has
a backwards mapping to a different capability and use that instead.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
3880ef5b54 parser: Use the kernel and policy abis to detect new capabilities
The kernel and policy abis can be used to detect and support new
capabilities without having to update base_cap_names.h and and
rebuilding the compiler.

This is not perfect however in that the does not provide any backwards
compatibility mappings, so we still need to keep the internal
capability table.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
7b4197f0da parser: convert to dynamically allocated capability list
We need to be able to dynamically add capabilities to the capability
list so switch to using a dynamically allocated table that we can
extend.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
48974e552c parser: add a set of flags to the capability tables
We need a set of flags to track where a capability can from so we know
how to processes it for policy compatibility purposes.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
8a1260db47 parser: move cap code around to consolidate
Just some basic cleanup bringing capability structs and fns together.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
168b141cc2 parse: add backmapping capability information
Some capabilities like perfmon and bpf have been split out from
another capability, likely cap sys_admin. Add this backmapping
infomation so that the parser can take advantage of it to support
policy on older kernels that don't support the new capabilities.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00
John Johansen
fb9c5f9bcf parser: unify capability name handling
There are currently two capability name tables the one that is
autogenerated and an internal hardcoded name table.

Now that the autogenerated table has been converted to a base
static table we can drop the internal static table. This
removes the chance of getting the tables getting out of sync.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-07-07 09:43:48 -07:00