Commit graph

4405 commits

Author SHA1 Message Date
Christian Boltz
3ee6058050
rewrite write_alias()
Instead of calling write_pair() (which is quite complex because it needs
to handle multiple rule types), write the alias rules directly in
write_alias().

This comes with minor code duplication, but makes the code much more
readable (3 instead of 7 %s)
2018-05-06 20:07:28 +02:00
Steve Beattie
eca16ae6cf
aa-teardown: Replace /bin/bash with /bin/sh
Merge branch 'remove-unnecessary-bash' from Robert Joslyn

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/115
2018-05-05 23:25:54 -07: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
Steve Beattie
9f2959482f
libapparmor: do not purge PMurHash.h on maintainerclean
Commit 63b7cb0660 (libapparmor: convert
multicache from using djb2 hashing to murmur3 hash) mistakenly added
PmurHash.h to the list of files generated by the build process and thus
should be removed when the 'maintainerclean' make target is invoked.
This fixes the issue by removing PmurHash.h from the list of generated
files.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/112
2018-05-03 14:09:17 -07:00
Steve Beattie
e87a662efc
swap regression test: fix swap permissions warning
When running the swap regression tests, the swapon command would issue
a warning about insecure permissions on the swapfile being used as
part of the test:

  mkswap: /tmp/sdtest.9698-822-2BL034/swapfile: insecure permissions 0644, 0600 suggested.

Fix this by setting the permissions after the swapfile is created.

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/108
2018-04-30 13:48:13 -07:00
Steve Beattie
49ba6af2bf
mount regression test: convert mount test to use MS_NODEV
The mount regression test passes MS_MANDLOCK to the mount(2) syscall in
the test program. When the kernel is configured without
CONFIG_MANDATORY_FILE_LOCKING set, attempting to mount a filesystem with
this option always fails with EPERM. To fix, convert the test program to
use the MS_NODEV option instead.

Bug: https://bugs.launchpad.net/apparmor/+bug/1765025
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/109
2018-04-30 13:25:44 -07:00
Jamie Strandboge
7bd3029f25 Merge branch 'update-fonts' into 'master'
Update fonts for Debian and openSUSE

See merge request apparmor/apparmor!96
2018-04-30 10:03:22 +00:00
John Johansen
67d84c8959 Merge branch 'cboltz-utils-exclude-cache-d' into 'master'
is_skippable_dir(): add 'cache.d' to exclude list

See merge request apparmor/apparmor!110

Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-30 05:07:07 +00:00
Christian Boltz
5b9497a8c6
is_skippable_dir(): add 'cache.d' to exclude list
This excludes the /etc/apparmor.d/cache.d/ directory from aa-logprof
parsing because parsing the binary cache, well, takes a while :-/

Reported on the opensuse-factory mailinglist by Frank Krüger and
confirmed by others.
2018-04-30 00:57:52 +02: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
John Johansen
b08b327922
libapparmor: fix failure to create missing cache dir
The refactor unfortunately changed dirfd to fd on one mkdirat, but
fd is always invalid at this point resulting in the parser reporting

Failed setting up policy cache (../profiles/cache/): Bad file descriptor

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/103
2018-04-25 20:09:05 -07:00
John Johansen
c82fcd227d
libapparmor: Fix build failure when enable-debug-output=yes
The code refactoring didn't update some debug messages. Update to
keep the debug messages and add a few extra while we are at it.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/103
2018-04-25 20:08:44 -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
Steve Beattie
06d9a8eff0 libapparmor: fix reallocarray FTBFS w/older glibc
The recently added overlay cache directory support added to libapparmor
makes use of reallocarray(3) to resize memory allocations; however,
reallocarray() was only included in glibc 2.26. This commit adds a
configure check for reallocarray() and if it's not available, provides
it as a wrapper around realloc(3).

PR: https://gitlab.com/apparmor/apparmor/merge_requests/100
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-18 21:08:03 -07:00
Christian Boltz
3009b22aec Merge branch 'qt5' into 'master'
Add qt5 abstraction

See merge request apparmor/apparmor!99

Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-04-18 22:18:30 +00:00
Vincas Dargis
b902d2505d Update fonts for Debian and openSUSE
* Allow to read conf-avail dir itself.
* Add various openSUSE-specific font config directories.
2018-04-18 19:16:29 +03:00
Vincas Dargis
6a85ffe00e Add qt5 abstraction
Create abtractions/qt5 with common rules needed for Qt5-based
applications.
2018-04-18 19:12:28 +03:00
John Johansen
ae20ee6036 Merge branch 'cboltz-teardown-path' into 'master'
install aa-teardown to /usr/sbin, not /sbin

See merge request apparmor/apparmor!97

Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-15 21:36:57 +00: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
f97782b100 Prepare for AppArmor 2.13 release
- update Version file
- update library versioning

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-04-15 06:54:44 -07: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
3f1ed05da6 libapparmor: fix library version to 2.13
The versioning previous patches was inconsistent because the multicache
patch have been in development for a while and the target version has
changed.

Cleanup libapparmor .map file to use the 2.13 release version

Signed-off-by: John Johansen <john.johansen@canonical.com>
Christian Boltz <apparmor@cboltz.de>
2018-04-14 15:51:23 -07:00
John Johansen
971908b730 libapparmor: docs: fixup version numbers and small mistakes/typos
There are several small mistakes/typos in the previous patches. Just
fix them all here.

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
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
4814763c97 libapparmor: add a workaround for procfs returning a bad stat.st_size value
For some longer pathname fstat is returning a bad size resulting in
the path being truncated. Fix this by detecting a potential truncation
and re-doing the readlink.

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
be94d7b27f libapparmor: add the ability to add readonly layers to the policy cache.
This adds the fn aa_policy_cache_add_ro_dir() to the library allowing
for readonly layers to be added to the policy cache. It does not
make those additional layers functional. Which requires the ability
to create and search an overlay of directories.

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
bf662b5594 libapparmor: refactor init_cache_features() to call cache_check_features()
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
110b96bd3d libapparmor: move create_cache() and init_cache_features()
Prepare to refactore init_cache_features() with cache_check_features()

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
10a4b3b9fb libapparmor: merge policy_cache features and kernel_features
A policy cache is for a specific set of kernel features so there is no
need to keep these separate.

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
John Johansen
26b6dc1306 libapparmor: error out if there is a cache directory collision
It is possible that a given feature set will hash to the same cache
directory as a different feature set. This will be a problem if binary
caches are required, eg. early boot with systemd doing the cache load.

Detect cache collisions and fail. This is a precursor to handling
collision resolution and should not be committed without the follow
up patch to properly handle collisions.

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
63b7cb0660 libapparmor: convert multicache from using djb2 hashing to murmur3 hash
Murmur3 hash is a better hash that djb2 and has a lower chance of
hash collisions, so switch over to using it.

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
30e0eacebc libapparmor: update multicache patches for aa_*_unref() preserving errno
Carry the changes made in
libapparmor: Preserve errno across aa_*_unref() functions

into the multicache patcheset

Signed-off-by: John Johansen <john.johansen@canonical.com>
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
8d9c904174 libapparmor: aa_features function that returns a features identifier
Add and export aa_features_id() which can be used to get a unique
identifier for an aa_features object. Internally, this is a djb2 hash of
the features string. The hash function used and even the makeup of the
features ID can be easily changed in the future since external consumers
must use this function to fetch the features ID.

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
4c7924ec31 libapparmor: Generate a features hash for new aa_features objects
Store a hash value that can be used to represent the aa_features
object. This will be useful when storing multiple AppArmor policy cache
directories, each based on a kernel feature set.

The hash algorithm used is currently djb2. It was simple to add for
testing purposes, but may eventually need to be changed to something
that is resilient against collisions since there is no handling of
features file hash collisions.

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
Tyler Hicks
b950c76d66 libapparmor: aa_policy_cache function to preview cache dir path
Add and export aa_policy_cache_dir_path_preview() which allows the
parser to know exactly where the policy cache binaries, for the
specified aa_policy_cache and aa_features objects, would be stored. This
function may be useful to preview the policy cache dir without having
sufficient permissions or desires to create a policy cache dir.

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
95912e41bf libapparmor: aa_policy_cache function to get cache dir path
Add and export aa_policy_cache_dir_path() which allows the parser to
know exactly where the policy cache binaries, for the current
aa_policy_cache and aa_features objects, will be stored. The parser
previously assumed that it was <cacheloc>/cache/ but it will soon be
<cacheloc>/cache.d/<features_id>/.

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
64c196a487
Merge branch 'Talkless/apparmor-nvidia-update'
See https://gitlab.com/apparmor/apparmor/merge_requests/92

Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-14 23:38:29 +02:00
Christian Boltz
df0a2335f2 Merge branch 'cboltz-fix-flags-regression' into 'master'
fix regression in {get,set}_profile_flags()

See merge request apparmor/apparmor!94

Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-14 21:27:03 +00:00
Christian Boltz
f472b6bb34 fix regression in {get,set}_profile_flags()
Since the latest change, calling {get,set}_profile_flags() with the
profile name failed when attachment was specified ("profile foo /bar").

Catched by the unittests.

Also fix a whitespace issue.
2018-04-14 21:26:34 +00:00
Christian Boltz
059adcdf76 Merge branch 'cboltz-mlmmj-digesters' into 'master'
mlmmj-send-profile: allow reading digesters.d/*

See merge request apparmor/apparmor!93

Acked-by: John Johansen <john.johansen@canonical.com>
2018-04-14 21:26:05 +00:00
Christian Boltz
a7ffae4396 mlmmj-send-profile: allow reading digesters.d/*
Reported by Per Jessen by mail
2018-04-14 21:25:09 +00:00