Commit graph

1347 commits

Author SHA1 Message Date
Tyler Hicks
eb8975e0cc all: Use HTTPS links for apparmor.net
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2018-09-13 16:41:32 +00:00
John Johansen
474be603c4 parser: fix cache write message when stdin is used
Using stdin with --write-cache set results in

  # apparmor_parser --show-cache --write-cache
  Cache: added primary location '/var/cache/apparmor'
  Warnung aus stdin (Zeile 1): Cache: added readonly location '/usr/share/apparmor/cache'
  Warnung aus stdin (Zeile 1): apparmor_parser: cannot use or update cache, disable, or force-complain via stdin
  Cache miss: stdin
  Wrote cache: /var/cache/apparmor/9b2cd0d0.0/(null)

The "Wrote cache:" message is referencing a null value and should not
be displayed.

BugLink: http://bugs.launchpad.net/bugs/1787717
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Timeout
2018-09-11 18:31:06 -07:00
Christian Boltz
d15bdabaef
Remove TODO notes from no-longer-failing tests
simple.pl reported
    TODO passed:   71448, 71459-71460, 71494, 71577

This commit removes the TODO note from the tests that now work as
expected.
2018-08-22 22:24:43 +02:00
John Johansen
657495fa55 parser: add empty config file for parser caching tests
The caching tests will fail if a warning is thrown. Some setups may
not have a parser config file in the default location which results
in the warning
  config file '/etc/apparmor/parser.conf' not found

which causes the tests to fail.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/175
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-21 23:14:52 -07:00
John Johansen
af1818c053 parser: update option parsing so --config-file does not have to be first
Requiring --config-file to be first in the option list is not user
friendly fix the option parsing so that --config-file can be specified
anywhere in the option list.

This also fixes a bug where even when the --config-file option is
first the option parsing fails because the detection logic is broken
for some option cases.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/175
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-21 23:14:52 -07:00
John Johansen
9a8e7e58d2 parser: group parser number of config options together
To help avoid the duplicate option problem in the future sort and group
the config options using numbers at the end of the option table.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/173
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-21 23:14:52 -07:00
John Johansen
3da52f7515 parser: fix collision of --config-file and --compile-features options
Unfortunately both --config-file and --compile-features are using
139 to indicate the feature which breaks one or the other depending
on how the switch state that processes the options is compiled.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/173
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-21 23:14:52 -07:00
John Johansen
2c0d7e608c parser: Add fixes to --config-file option
After the config file patch was committed to 2.13 a couple of
improvements were suggested by intrigeri and cboltz. These have
been done as a separate patch so they can be applied to both
dev and 2.13.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/170
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-17 08:19:39 -07:00
John Johansen
e7949d09fa parser: fix build warning for assigning default cache location
The compiler is spitting out the warning

parser_main.c:1291:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
    char *tmp = "/var/cache/apparmor";

fix this by constifying the cacheloc array.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-15 13:21:37 -07:00
John Johansen
b1967c892a parser: allow specifying the parser config file
The parser config file can affect the parsers behavior during tests.
Allow overriding the default location with the option

  --config-file=

the option must be the first option in the commands argument list.

Also provile a
  --print-config-file

option to display what the parser is using for a config file.

BugLink: http://bugs.launchpad.net/bugs/1277711
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-14 18:31:10 -07:00
intrigeri
3d21cf0e32 Move the cache to /var/cache
Let's not store a bunch of automatically generated binary files in /etc.
AppArmor 3.0 will store the cache in /var/cache and most distros
(openSUSE, Debian, and soon Ubuntu) moved it there already.

Bug-Debian: https://bugs.debian.org/904637
2018-08-02 01:18:04 +00:00
Christian Boltz
c437e9d4a5
add missing 'break' in load_profile()
'case OPTION_OFILE' missed the 'break', which means if did fallthrough
to the default case.

Adding the 'break' means no longer executing another PERROR, and no
longer executing the 'exit(1)' in the default branch.

References: coverity #55994
2018-07-13 15:21:24 +02:00
Christian Boltz
3a9b0fd74a
Adjust cache paths in apparmor.service
The initial apparmor.service assumed the profile cache is in
/var/lib/apparmor/ which was an openSUSE-specific path that was chosen
for historical reasons, but was far from perfect.

In the meantime, the profile cache moved to /var/cache/apparmor/ and the
read-only/packaged version was added in /usr/share/apparmor/cache/

This commit adjusts apparmor.service to use these paths.
2018-06-16 23:14:19 +02:00
Patrick Steinhardt
655d3e7826
parser: provide typedefs for comparison_fn_t and __free_fn_t
The POSIX standard never defines the typedefs `comparison_fn_t` and
`__free_fn_t`, but they are provided by glibc and user in the parsing
code. Provide the typedefs ourselves to fix compiling on musl based
systems.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2018-05-09 13:15:42 -07:00
Rasmus Thomsen
7c86a2acaf
parser: allow using a custom sbin & usr/sbin dir
This is especially handy if your distro doesn't split sbin and bin
and only wants to install into bin (so that the sbin directory doesn't
clash with the sbin -> bin symlink)

[Per feedback, added USR_SBINDIR as a toggle for the install location
 of aa-teardown -- @smb]

Signed-off-by: Rasmus Thomsen <cogitri@exherbo.org>
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/111/
2018-05-08 09:09:24 -07:00
Christian Boltz
f910cb5559
parse_profile_data(): error out on alias inside profile
Defining an alias is only allowed outside of a profile.

Also add a parser test with an alias inside a profile.
2018-05-06 14:27:32 +02:00
Robert Joslyn
dbd6591e2f aa-teardown: Replace /bin/bash with /bin/sh
The script does not require bash, a POSIX shell is sufficient. This
removes bash as a runtime dependency of the parser.
2018-05-05 17:46:19 -07:00
John Johansen
e83fa67edf
parser: fix failures due to -M only setting compile-features
Split the features file into compile features and kernel features
which is needed for policy versioning and the new caching scheme.

A new flag --kernel-features was added to set the kernel features but
unfortunately -M, --features-file was setup to only specify the
compile features, when it used to effectively specify both the
compile and kernel features.

This broke existing uses of -M.

Fix this by having -M specify both the compile and kernel features,
and a new flag --compile-features that can be used to specify the
compile fature set separate from the kernel feature set.

sbeattie> fixed up error message to refer to compile features when
--compile-features argument fails.

Fixes: 9e48a5da5e ("parser: split kernel features from compile features.")
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/104
2018-04-25 22:16:57 -07:00
Steve Beattie
987cc4af3a
parser: fix permissions of apparmor.systemd helper script
Merge branch 'cboltz-fix-apparmor-systemd-perms'

Acked-by: Steve Beattie <steve@nxnw.org>

Bug: https://bugzilla.opensuse.org/show_bug.cgi?id=1090545
PR: https://gitlab.com/apparmor/apparmor/merge_requests/106
2018-04-25 15:41:52 -07:00
John Johansen
48a32b78b1
parser: Add the ability to turn off jobs to ease with debugging
The parser currently uses a fork model to do job processing. For
consistency even when the number of jobs is set to 1 a single
work process is forked. However this makes using gdb more difficult
and can be even worse for other debugging tools.

Make -j 0 disable all job spawning so all processing happens in the
main process.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/105

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2018-04-25 15:26:11 -07:00
Christian Boltz
f179612abe
fix permissions of apparmor.systemd helper script
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1090545
2018-04-23 18:01:52 +02:00
Christian Boltz
62ecc2b574
install aa-teardown to /usr/sbin, not /sbin
Looks like I used a wrong path when upstreaming aa-teardown :-(
(openSUSE always used /usr/sbin/aa-teardown)
2018-04-15 23:28:41 +02:00
John Johansen
aa7dc70de3 translations: sync from launchpad translations
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-04-15 06:54:44 -07:00
John Johansen
481f59a39b parser: Enable cache overlay in the parser
Allow the parser to use cache overlays by extending the --cache-loc
flag to support multiple locations via a comma separated list.

eg.
  --cache-loc=/var/cache/apparmor/,/etc/apparmor.d/cache.d/

The overlayed cache directories are searched in the order
specified. So in the above example /var/cache/apparmor is searched
before /etc/apparmor.d/

Time stamps are ignored in the search, the first match found wins
regardless if there exists a matching cache file with a newer timestamp
in a directory is later in the search.

Cache writes will only occur to the first dir in the list. So
/var/cache/apparmor/ in the above example.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-04-14 15:51:23 -07:00
John Johansen
9e48a5da5e parser: split kernel features from compile features.
The feature set needs to be split, the kernel features set determines
the cache location and controls features down grades to ensure
policy generates a policy that is usable on a given kernel.

The compile featurs set governs the feature set supported by policy
and primarily determines how policy is parsed and compiled.

Taking the intersection of the two feature sets to determine rule
downgrades for a specific kernel is left to a separate patch.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-04-14 15:51:23 -07:00
John Johansen
1328a42d5a libapparmor: Add support for overlaycache directories
Add the support to have the cache be able to search multiple locations
so that the policy cache can be split into multiple locations and
that there can be a local cache that can override preshipped caches.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-04-14 15:51:23 -07:00
John Johansen
2ad924f2b1 libapparmor: prepare to allow a cache to have overlay directory locations
Make the internal cache dir tracking use a fixed array and update
all references to the internal dirfd to index the array.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-04-14 15:51:23 -07:00
John Johansen
419d82c13b libapparmor: handle feature hash collision by falling back to next dir
Adjust the cache directory name from
  <cache_loc>/<feature_id>
to
  <cache_loc>/<feature_id>.<n>

where <n> is 0 for the first cache created for a given feature_id.
If there is a feature_id collision then <n> will be incremented to
the next number.

The .features file within each cache directory is used to disambiguate
which feature_id cache dir belongs to which feature set.

Cache collisions and missing caches cause a slow path that searches
existing cache dirs that fit the cache_name pattern, to ensure the
proper dir is chosen.

TODO: add regression tests
  create cache dir  check it
  copy different feature set to it
  create cache dir again, check it, check that it incremented...

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-04-14 15:51:23 -07:00
Tyler Hicks
1f36505f3e parser, libapparmor: Support multiple policy cache directories
Move the policy cache directory from <cacheloc>/cache/ to
<cacheloc>/cache.d/<features_id>/ where <features_id> is a unique
identifier for a set of aa_features. This allows for multiple AppArmor
policy caches exist on a system. Each policy cache will uniquely
correspond to a specific set of AppArmor kernel features. This means
that a system can reboot into a number of different kernels and the
parser will select the existing policy cache that matches each kernel's
set of AppArmor features.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-14 15:51:23 -07:00
Tyler Hicks
b4a5f44473 parser: Update caching tests to use the --print-cache-dir option
Use the new --print-cache-dir parser option to construct the policy
cache dir when testing the policy caching functionality.

The majority of the required changes involve fully initializing
self.cmd_prefix prior to calling self.get_cache_dir() since that
function requires self.cmd_prefix to be initialized.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-14 15:51:23 -07:00
Tyler Hicks
e9d9395f91 parser: Add option to print the cache directory
The --print-cache-dir option can be used to have the parser print the
value of the cache directory that is specific to the features used (from
the current kernel, the --match-string option, or the --features-file
option). After printing the path, apparmor_parser will exit. This is
helpful because the final component in the path will become
unpredictable because it will be based on arbitrary hash function
output.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-14 15:51:23 -07:00
Christian Boltz
0b18e57cc5 exit(1) in process_arg() if c == 0
(as discussed on https://gitlab.com/apparmor/apparmor/merge_requests/83)
2018-04-13 13:58:55 +00:00
Christian Boltz
b714cf1b0d update Canonical copyright year in header and --help
References: https://bugs.launchpad.net/apparmor/+bug/1437946 "BTW2"
2018-04-13 13:58:55 +00:00
Christian Boltz
b7732a2a30 drop display_usage() calls after printing an error message
This avoids "hiding" the error message with the --help output

References: https://bugs.launchpad.net/apparmor/+bug/1437946
2018-04-13 13:58:55 +00:00
Emerson Bernier
b4fa0cf9f6 Add ".dpkg-remove" to apparmor parser ignored list
References: https://bugs.debian.org/893974
2018-04-02 14:24:44 +00:00
Emerson Bernier
f0876ea92a Add .pacsave/.pacnew to apparmor parser ignored list
Currently there is a list of file extensions which apparmor parser
should ignore which contains rpm and dpkg backup files. The list could
be extended with extensions used by pacman package manager
(Archlinux/Manjaro/Antergos):

.pacsave

.pacnew

https://wiki.archlinux.org/index.php/Pacman/Pacnew_and_Pacsave

References: https://gitlab.com/apparmor/apparmor/issues/3
2018-04-02 14:24:25 +00:00
Emerson Bernier
50ee50f931 Fix typo in apparmor_parser.pod 2018-03-26 19:07:50 +00:00
Christian Boltz
11ae3f6ecd add aa-teardown manpage 2018-03-24 19:28:24 +00:00
Christian Boltz
671ddccf19 Add apparmor.service and aa-teardown
... and the apparmor.systemd wrapper.

Also add a new 'install-systemd' target to the Makefile to install these
systemd-related files on (open)SUSE by default. Other distributions can
follow by adding a dependency on 'install-systemd' on their
'install-$DISTRO' target.

Note that apparmor.service has ExecStop=/bin/true to avoid that running
processes get unconfined if someone accidently types
    systemctl restart apparmor   (instead of using "reload")

Use aa-teardown if you really want to unload all profiles.

The files in this commit are used in openSUSE since a while, and also in
Arch Linux.

BTW: The condition on var-lib.mount is because openSUSE uses
/var/lib/apparmor/cache/ - but with the changed btrfs layout on
openSUSE, maybe I'll change that to /var/cache/apparmor/ which is
a) used by Debian and b) more sane
2018-03-24 19:28:24 +00:00
Christian Boltz
c9bf36dd2e
Drop the old (open)SUSE initscript
Also adjust the install-suse make target to
- make 'rcapparmor' a symlink to 'service'
- no longer create the 'rcsubdomain' symlink

(open)SUSE does this in apparmor.spec since several releases, so this
commit upstreams the changes the spec did after running make install.
2018-03-18 16:31:47 +01:00
intrigeri
967d394ef4 apparmor(7): clarify the effect of reloading a profile.
LP: #1608075

Partly fixes: https://bugs.debian.org/826218
2018-01-29 11:29:35 +00:00
John Johansen
2ea3309942 parser: add support for conditional includes
This is a minimal patch to add conditional includes to the profile
language.

The syntax for conditional includes is similar to regular includes
except with the addition of "if exists" after "include"

  include if exists <foo/bar>
  include if exists "foo/bar"
  include if exists "/foo/bar"
  include if exists foo/bar

Note: The patch is designed to be backportable with minimum
effort. Cleanups and code refactoring are planned for follow up
patches that won't be back ported.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-01-20 00:32:20 -08:00
John Johansen
8d142809f5 parser tests: fix includes to allow white space
includes were not handling WS in path names correctly. Allow WS within
quotes. Eg
  include "foo bar"
  include <"foo bar">

BugLink: http://bugs.launchpad.net/bugs/1738880
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-01-20 00:32:20 -08:00
John Johansen
efd8eedd52 parser tests: add tests for relative path includes
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-01-20 00:32:20 -08:00
Thorsten Kukuk
924983e702
disable write cache if filesystem is read-only
... and don't bail out

Patch by Thorsten Kukuk <kukuk@suse.com>

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1069906
            https://bugzilla.opensuse.org/show_bug.cgi?id=1074429
2018-01-14 21:33:01 +01:00
John Johansen
6344b8ecc3 parser: fix parser so that cache creation failure doesn't cause load failure
This is a minimal patch so that it can be backported to 2.11 and 2.10
which reverts the abort on error failure when the cache can not be
created and write-cache is set.

This is meant as a temporary fix for
https://bugzilla.suse.com/show_bug.cgi?id=1069906
https://bugzilla.opensuse.org/show_bug.cgi?id=1074429

where the cache location is being mounted readonly and the cache
creation failure is causing policy to not be loaded. And the
thrown parser error to cause issues for openQA.

Note: A cache failure warning will be reported after the policy load.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz apparmor@cboltz.de
(cherry picked from commit 42b68b65fe1861609ffe31e05be02a007d11ca1c)
2018-01-05 01:32:47 -08:00
Héctor Orón Martínez
26431478a6 apparmor: support usrmerge
Allow binaries in /bin to run from /usr/bin as well.
For more information on usrmerge, see
https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/

Signed-off-by: Héctor Orón Martínez <hector.oron@collabora.co.uk>
2017-12-09 23:56:58 +01:00
Tyler Hicks
2c04f44a80 binutils, parser, utils: Exit from Makefile shell snippets
Exit rather than returning from shell snippets in Makefiles. It is
reported that returning causes the following error message with bash:

 /bin/sh: line 4: return: can only `return' from a function or sourced script

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reported-by: Christian Boltz <apparmor@cboltz.de>
2017-12-04 23:28:10 +00:00
Tyler Hicks
19c6c3310b all: Use the MAKE variable
https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.html

We should be using the $(MAKE) variable when calling the make command
from Makefiles since we use Makefile recursion.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2017-11-01 23:22:53 +00:00
Steve Beattie
df0f20f32b parser+libapparmor: partially address issues building with musl
adjust macros and header inclusion to make progress on building with the
musl C library.

Acked-by: Steve Beattie <steve@nxnw.org>
2017-10-27 17:12:24 -07:00