Commit graph

1447 commits

Author SHA1 Message Date
John Johansen
40b7019d72 Merge Fix wording of some warnings
pwarn() prints "Warning" itsself, therefore it doesn't make sense to include/repeat that word in the actual warning text.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/650
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-11 11:34:29 +00:00
John Johansen
21060e802a parser: Fix warning message when complain mode is forced
when a profile is being forced to complain a variation of the
following message is displayed

  Warning from /etc/apparmor.d/usr.sbin.sssd (/etc/apparmor.d/usr.sbin.sssd line 54): Warning failed to create cache: usr.sbin.sssd

This is incorrect in that the parser doesn't even try to create the
cache, it just can't cache force complain profiles.

Output a warning message for this case that is correct.

Fixes: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1899218
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/649
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-10-11 03:34:37 -07:00
Christian Boltz
01f5954b5c
Fix wording of some warnings
pwarn() prints "Warning" itsself, therefore it doesn't make sense to
include/repeat that word in the actual warning text.
2020-10-11 12:22:23 +02:00
John Johansen
ec19ff9f72 parser: fix parser.conf commenting on pinning an abi
The comments describing the example rules to pin the abi are wrong.
The comments of the two example rules are swapped resulting in confusion.

While we are at it. Add a reference to the wiki doc on abi, and
how to disable abi warnings without pinning.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/648
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2020-10-09 13:25:49 -07:00
John Johansen
05acf374b1 Merge aa_status: Fix build issue with musl
add limits.h

aa_status.c:269:22: error: 'PATH_MAX' undeclared (first use in this function); did you mean 'AF_MAX'? | 269 | real_exe = calloc(PATH_MAX + 1, sizeof(char));

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/647
Signed-off-by: Armin Kuster [akuster808@gmail.com](mailto:akuster808@gmail.com)
Acked-by: John Johansen <john.johansen@canonical.com>
2020-10-08 06:31:02 +00:00
Armin Kuster
0dbcbee700 parser/Makefile: dont force host cpp to detect reallocarray
In cross build environments, using the hosts cpp gives incorrect
detection of reallocarray. Change cpp to a variable.

fixes:
parser_misc.c: In function 'int capable_add_cap(const char*, int, unsigned int, capability_flags)':
| parser_misc.c:297:37: error: 'reallocarray' was not declared in this scope
|   297 |   tmp = (struct capability_table *) reallocarray(cap_table, sizeof(struct capability_table), cap_table_size+1);

Signed-off-by: Armin Kuster <akuster808@gmail.com>
2020-10-07 20:55:52 -07:00
Christian Boltz
3f752fac5f
Ensure empty stderr if no errors are expected
... instead of not checking stderr if it's expected to be empty.
2020-10-04 19:51:54 +02:00
Christian Boltz
37552669d4
Test for full parser error messages, not parts
By using assertIn, we test if a given message is contained in the parser
error message. This can (and actually does) hide errors if the error
message changes outside the checked part.

Change the test to assertEqual to test the full error message, and add
'\n' to all expected error messages to make them still match.

Depending on the kernel version and patches, there can be an additional
message
    Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)
which will be ignored by the check.
2020-10-04 19:51:54 +02:00
John Johansen
709fd0e930 parser: Fix parser FTBS due to reallocarray
Older glibcs and alternate libcs don't have reallocarray()

So define it if not defined by libc.

Fixes: #3 of https://gitlab.com/apparmor/apparmor/-/issues/109
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/639
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:33:12 -07:00
John Johansen
bee9f94eab parser: fix bison error message output when built against bison 3.6+
bison change the default text past to yerror in bison 3.6, this
breaks make check as some tests are comparing against the error
output

======================================================================
FAIL: test_modefail (__main__.AAErrorTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jj/apparmor.git/parser/tst/testlib.py", line 50, in new_unittest_func
    return unittest_func(self)
  File "./errors.py", line 58, in test_modefail
    self._run_test(
  File "./errors.py", line 40, in _run_test
    self.assertIn(message, outerr, report)
AssertionError: 'AppArmor parser error for errors/modefail.sd in profile errors/modefail.sd at line 6: syntax error, unexpected TOK_ID, expecting TOK_MODE' not found in 'AppArmor parser error for errors/modefail.sd in profile errors/modefail.sd at line 6: syntax error\n' :
Command: ../apparmor_parser --config-file=./parser.conf -S -I errors errors/modefail.sd
Exit value:1
STDERR
AppArmor parser error for errors/modefail.sd in profile errors/modefail.sd at line 6: syntax error

To fix this we need to add

define parse.error=verbose

to bison. Unfortunately define parse.error was only added in bison 3.0
and and older versions of bison will break if that is defined in
parser_yacc.y

Instead test for the version of bison available and set define parse.error
as a build flag if supported by the version of bison being called.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/640
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:17:09 -07:00
John Johansen
882380ad3d parser: enable variable expansion for mount type= and options=
Currently mount options type= and options= do not expand variables
but they should. Fix it.

Note: this does not treat either as paths because their use is
too device dependent for it to be safe to filter slashes.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/638
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-10-01 02:11:37 -07:00
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