Commit graph

5794 commits

Author SHA1 Message Date
John Johansen
0dcac24510 Merge aa-logprof: propose 'include' instead of '#include' rules
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/630
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-25 10:12:20 +00:00
John Johansen
1cb8c7885e Merge Remove all conflicting modes when switching profile mode
When switching to complain or enforce mode (for example with aa-complain and aa-enforce), remove conflicting flags like kill and unconfined.

As ground work, change add_or_remove_flag() to allow to add or remove multiple flags. Multiple flags can be given as string (will be split) or as array.

Also add some tests confirming that everything works as expected.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/633
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-25 10:10:24 +00:00
Christian Boltz
de0d4f688e
Remove all conflicting modes when switching profile mode
When switching to complain or enforce mode (for example with aa-complain
and aa-enforce), remove conflicting flags like kill and unconfined.
2020-09-24 23:21:54 +02:00
Christian Boltz
a2d3a382a8
add_or_remove_flag(): allow to add or remove multiple flags
Multiple flags can be given as string (will be split) or as array.

Also add some tests confirming that everything works as expected.
2020-09-24 23:21:54 +02: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
Christian Boltz
7918d8980b
Add change_profile support to aa-logprof
Note that the log doesn't include enough information for EXEC MODE and
EXEC COND, therefore aa-logprof will always propose ALL as EXEC COND
(comm= might give a hint about EXEC COND, but isn't good enough).

With the added support in aa-logprof, remove the changeprofile tests
from the known-failing list in test-libapparmor-test_multi.py.

Also add another test log (from darix) / expected profile to the
libapparmor testsuite.
2020-09-20 17:07:18 +02:00
Christian Boltz
eada7a8d44
aa-logprof: propose 'include' instead of '#include' rules 2020-09-20 14:42:25 +02:00
John Johansen
29ef901289 Merge aa-unconfined: support /proc/$pid/attr/apparmor/current and kill mode
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/629
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-18 11:49:00 +00:00
Christian Boltz
f0c27b57b0
aa-unconfined: add support for 'kill' profile mode
... when reading /proc/$pid/attr/{apparmor/,}current

Also add a comment about _not_ adding support for the 'unconfined'
profile mode, because that would give a quite confusing output.
2020-09-18 13:38:50 +02:00
Christian Boltz
5a31e94394
aa-unconfined: also read /proc/$pid/attr/apparmor/current
This means moving the code that reads the 'current' file into a new
function read_proc_current()Then call that function for both
/proc/$pid/attr/apparmor/current (preferred) and /proc/$pid/attr/current
(fallback).
2020-09-18 13:38:43 +02:00
John Johansen
a680c949af Merge dnsmasq: Permit access to /proc/self/fd/
As of [48755ebf](https://www.openhub.net/p/dnsmasq/commits/1679009518), dnsmasq iterates through directory entries in /proc/self/fd/ to find which file descriptors are open to avoid the potentially costly operation of closing all possible file descriptors.

While the current profile does not make dnsmasq inoperable, this change permits AppArmor users running dnsmasq to avoid falling back on the generic code path.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/628
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-18 11:20:01 +00:00
Christian Boltz
324d745656 Merge branch 'fix-hats' into 'master'
profiles: update profiles for the new proc attr interfaces

See merge request apparmor/apparmor!627

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-09-18 11:17:42 +00:00
John Johansen
9d6db05b52 profiles: update profiles for the new proc attr interfaces
New kernels provide an alternative proc attr interface for apparmor
which is needed for LSM stacking.

Update the remaining profiles that use the old interface to
include access to the new interface.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-18 04:07:24 -07:00
FallenWarrior2k
93a3a30ffd
dnsmasq: Permit access to /proc/self/fd/
As of [48755ebf], dnsmasq iterates through directory entries in
/proc/self/fd/ to find which file descriptors are open to avoid the
potentially costly operation of closing all possible file descriptors.

[48755ebf]: https://www.openhub.net/p/dnsmasq/commits/1679009518
2020-09-18 12:56:13 +02:00
John Johansen
1a7d9d9da0 Merge 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
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-18 10:30:30 +00:00
John Johansen
c05905fff1 Merge Rename postfix.* to postfix-* to match profile names
39ca2adff6 removed the usr.lib.postfix prefix from the filename, but missed to change the remaining dot to a "-" to fully match the profile names.

Note: This affects only master. 2.13 and older still have the `usr.lib.postfix.*` filenames.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/624
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-18 10:22:33 +00: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
3328225bd4 abstractions: update change_profile abstraction for stacking patch
LSM stacking adds new interfaces
   /proc/<pid>/attr/apparmor/*

that should be used in preference of the old interface files in
   /proc/<pid>/attr/*

The library has already been updated to use the new path but the
abstraction for change_profile has not so accessing the new interface
in a confined application fails.

Fix this by making the abstraction cover the old and new interfaces.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/626
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-17 19:28:36 -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
Christian Boltz
405f05aa5d
Rename postfix.* to postfix-* to match profile names
39ca2adff6 removed the usr.lib.postfix
prefix from the filename, but missed to change the remaining dot to a
"-" to fully match the profile names.
2020-09-15 22:39:47 +02:00
John Johansen
d6f332ab03 Merge Fix aa-genprof crash if extra profile exists
serialize_profile() assumes that active_profiles has the /etc/apparmor.d/ filename of a profile initialized.

This patch makes sure this is true even when using an extra profile by initializing it in get_profile().

Ideally serialize_profile() shouldn't always use active_profiles, but that will be part of a bigger change.

Reported by zt1024 including a proposed patch on https://gitlab.com/apparmor/apparmor/-/merge_requests/604 but of course ;-) this patch is better because it selectively does the initialization only in the case that needs it.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/623
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-15 10:07:46 +00:00
Christian Boltz
b3f79f4efb
Fix aa-genprof crash if extra profile exists
serialize_profile() assumes that active_profiles has the
/etc/apparmor.d/ filename of a profile initialized.

This patch makes sure this is true even when using an extra profile by
initializing it in get_profile().

Ideally serialize_profile() shouldn't always use active_profiles, but
that will be part of a bigger change.

Reported by zt1024 including a proposed patch on
https://gitlab.com/apparmor/apparmor/-/merge_requests/604
but of course ;-) this patch is better because it selectively does the
initialization only in the case that needs it.
2020-09-12 20:25:48 +02: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
John Johansen
37d7f8d8d3 Merge 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().

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/608
Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-10 01:01:51 +00:00
John Johansen
6055bbd541 Merge postfix-master: allow access to postlog socket
1/1 - allow access to postlog socket

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/622
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-09 03:34:11 +00:00
Christian Boltz
d55ca8b624
postfix-master: allow access to postlog socket 2020-09-08 21:50:39 +02:00
Christian Boltz
358f7192aa Merge branch 'cboltz-rename-php-fpm-profile' into 'master'
Rename php-fpm profile file to just "php-fpm"

See merge request apparmor/apparmor!620
2020-09-08 19:31:18 +00:00
Christian Boltz
a1e03860d9
Rename php-fpm profile file to just "php-fpm"
Nice profile names should also result in nice filenames, at least for
new profiles.

Also update the local include filename.
2020-09-08 20:41:58 +02:00
Christian Boltz
c3fbc3c801 Merge branch 'pulls/php-fpm-fix-profile-name' into 'master'
php-fpm: fix profile name in php-worker

This is analogous to 9892a032.  It allows php-fpm to manage the worker threads by allowing the threads to receive signals from php-fpm (rather than the nonexistent profile `/usr/sbin/php-fpm*`).

See merge request apparmor/apparmor!619

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-09-06 18:08:33 +00:00
Antonio Russo
8798d44ebe
php-fpm: fix profile name in php-worker
Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
2020-09-06 05:26:45 -06:00
Christian Boltz
4f781eac3f Merge branch 'fix-php-fpm' into 'master'
Revert "php-fpm: allow only one pid file"

Closes #115

See merge request apparmor/apparmor!617

Acked-by: Christian Boltz <apparmor@cboltz.de>
2020-09-06 09:26:41 +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
John Johansen
0dfb2b28bb Revert "php-fpm: allow only one pid file"
This reverts commit 64ae865675.

On Debian (unstable), the PID file is stored with the 7.4 version:

/run/php/php-fpm.sock
/run/php/php7.4-fpm.pid
/run/php/php7.4-fpm.sock

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/115
Reported-by:  Antonio Russo <www.antonioerusso.com>
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/617
Signed-off-by: John Johansen <john.johansen@canonical.com>
2020-09-05 11:50:27 -07:00
Mike Salvatore
b947ad96f9 parser: convert commented out fprintf() in immunix.h to PDEBUG() 2020-09-05 09:38:53 -04:00
John Johansen
9e3aaf34af Merge postfix-common: allow reading icu *.dat
several postfix-\* binaries on openSUSE Tumbleweed need to read /usr/share/icu/\[0-9\]*.\[0-9\]*/\*.dat.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/615
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-05 09:42:53 +00:00
Christian Boltz
39ef7c508f
postfix-common: allow reading icu *.dat
several postfix-* binaries on openSUSE Tumbleweed need to read
/usr/share/icu/[0-9]*.[0-9]*/*.dat.
2020-09-04 23:14:54 +02:00
Mike Salvatore
e2237057af parser: Fix formatting in immunix.h:is_merged_x_consistent() 2020-09-04 12:10:35 -04:00
John Johansen
0dc86bfeb3 profiles: fixup chromium profile
- drop out dated maintenance comment
- cleanup profile name rules, and fix a few broken references
- /usr/lib -> /{usr,}/lib
- lib -> lib{,32,64}

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/611
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-03 11:44:19 -07:00
John Johansen
6e5ad15adf Merge nvidia_modprobe: allow creating /dev/nvidia-modeset
On Debian Sid we get this denial:

```
type=AVC msg=audit(1599065006.981:527): apparmor="DENIED"
operation="mknod" profile="nvidia_modprobe" name="/dev/nvidia-modeset"
pid=12969 comm="nvidia-modprobe" requested_mask="c" denied_mask="c"
fsuid=0 ouid=0
```

Update nvidia_modprobe profile to allow creating device file.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/614
Acked-by: John Johansen <john.johansen@canonical.com>
2020-09-03 18:01:49 +00:00
Vincas Dargis
e6dbe3bfd3 nvidia_modprobe: allow creating /dev/nvidia-modeset
On Debian Sid we get this denial:

```
type=AVC msg=audit(1599065006.981:527): apparmor="DENIED"
operation="mknod" profile="nvidia_modprobe" name="/dev/nvidia-modeset"
pid=12969 comm="nvidia-modprobe" requested_mask="c" denied_mask="c"
fsuid=0 ouid=0
```

Update nvidia_modprobe profile to allow creating device file.
2020-09-03 18:20:33 +03: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
375b75bdc2 Merge Warn flags and -Werror support
Add flags to be able to control parser warnings, and convert warnings into errors.

Flags can be enabled by using `--warn` followed by a single flag. If multiple flags need to be set --warn can be specified multiple times.

Eg.

```
  --warn=deprecated --warn=rule-downgrade
```

Flags can be disabled no prefix the flag name with `no-`

Eg.

```
  --warn=no-config
```

The set of currently enabled flags can be seen by specifying

```
  --warn=show
```

and the set of supported flags can be seen by specifying

```
  --help=warn
```

The default set of warning flags that are enabled are

```
  WARN_CONFIG - config warnings
  WARN_CACHE - cache warnings that were not hidden behind debug-cache
  WARN_JOBS - warnings around job failures
  WARN_UNEXPECTED - warnings about internal consistency checks against what is expected from kernel
  WARN_OVERRIDE - warnings about overriding some option, currently limited to forcing an override on a namespace.
```

Warnings can be converted into errors by specifying `-Werror`. It supports all the same options as \`\`\`--warn\`. A warning must be turned on before the warning can be converted into an error message.

```
   --warn=deprecated --Werror=all
```

Will create error messages for deprecation warnings but not for rule-downgrades. -Werror is disabled by default.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/600
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2020-09-02 02:56:48 +00: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