Commit graph

4414 commits

Author SHA1 Message Date
Steve Beattie
82bd9a390d coverity build: capture separate log files for each coverity invocation
Each coverity command writes its debugging output to
cov-int/build-log.txt, which means that multiple runs of cov-build
overwrite previous logs, resulting in only the last invocation's output
remaining at the end of the build, making debugging why failures to
capture coverity output difficult. Fix this by renaming the build-log to
per-directory log files.

(This would still be an issue even if we had a single build command
for the entire tree, as capturing python and other interpreted
files requires a second invocation of cov-build to scan for those
file types.)

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/145
(cherry picked from commit fed101920b)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-07 02:40:49 -07:00
Christian Boltz
acb40969b5 make message about notify-send package cross-distro compatible
PR: !144
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1100779
(cherry picked from commit 44ee1d5090)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-07 02:29:30 -07:00
Christian Boltz
7473044d41 Fix unsetting filename in get_profile()
When creating a new profile with aa-genprof, get_profile() searches for
an inactive ("extra") profile and, if it finds one, removes the filename
from that profile so that it gets stored in /etc/apparmor.d/ later.

However, it used .pop() to remove the filename, which explodes since
ProfileStorage is a class now.

This patch fixes this (tested manually).

PR: !140
(cherry picked from commit 73b33bdf36)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-07 02:13:47 -07:00
John Johansen
56b8e16698 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
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-08-07 02:13:47 -07:00
Christian Boltz
b3dfe3366a Merge branch 'add-path-to-abstractions-python' into 'master'
Allow /usr/local/lib/python3/dist-packages in abstractions/python

See merge request apparmor/apparmor!160

Acked-by: John Johansen <john.johansen@canonical.com>

Acked-by: Christian Boltz <apparmor@cboltz.de> for 2.10..master

(cherry picked from commit 763a6787d8)

6a10f076 Allow /usr/local/lib/python3/dist-packages in abstractions/python
2018-08-06 18:11:50 +00:00
intrigeri
249b68c92e tunables/share: make variables value more readable by avoiding the use of too many alternations.
Thanks to Christian Boltz for the suggestion and the patch!
2018-07-29 23:42:09 +00:00
intrigeri
749d94297f Rename @{usr_share} → @{system_share_dirs} and @{home_local_share} → @{user_share_dirs}.
Thanks a lot to Simon McVittie for the much better names suggestion.
2018-07-29 23:42:02 +00:00
intrigeri
8a8349d14d freedesktop.org abstraction: refactor (factorize) for consistency.
This change makes the @{home_local_share} rules similar to the
@{usr_share} ones.
2018-07-29 23:41:57 +00:00
intrigeri
7cc2c0dfad freedesktop.org abstraction: simplify by not attempting to guess the exhaustive list of files that can exist in {~/.local/share,/usr/share}/applications/.
As Simon McVittie wrote, "if a specification or library creates extra caches, or
has .desktop files in a subdirectory, or anything like that, then I don't see
why we wouldn't want to allow reading those too".
2018-07-29 23:41:53 +00:00
intrigeri
bb0a9c76e3 kde abstraction: drop redundant rules for icons access.
These rules are already in abstractions/freedesktop.org that's included
by the abstractions/kde.
2018-07-29 23:41:42 +00:00
intrigeri
b86917dc95 freedesktop.org abstraction: treat Flatpak exports the same way as bits shipped by the distro.
As Simon McVittie <smcv@collabora.com> wrote on
https://bugs.debian.org/865206 and on the AppArmor mailing list:

"Anything in /var/lib/flatpak/exports/share or
~/.local/share/flatpak/exports/share is essentially equivalent to
the corresponding path in /usr/{local/,}share, and is something
that has deliberately been "exported" to the rest of the system by a
Flatpak-confined app.

The only reason to prevent reading those directories would be if you do
not want the AppArmor-confined app to be able to enumerate the other
software you have installed on your system, as an anti-fingerprinting
mechanism.".

Bug-Debian: https://bugs.debian.org/865206
2018-07-29 23:41:37 +00:00
intrigeri
9d8b6f4dbd freedesktop.org abstraction: DRY by factorizing duplicated path components with variables.
These alternations will need to grow quite a bit in order to support Flatpak
exports. Let's avoid repeating ourselves too much.
2018-07-29 23:41:28 +00:00
Dimitri John Ledkov
40ba8bf047
Profiles: Patch usr.sbin.useradd to support usr-merge.
(cherry picked from commit e99fa6c605)
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/152
2018-07-27 10:33:47 -07:00
Steve Beattie
e24484c42e
common/Version: update to show 2.13.1 would be next apparmor-2.13 release
Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
2018-07-25 16:11:35 -07:00
Christian Boltz
d9d3cae2aa
adjust abstractions/python for python 3.7
Python 3.7 was released yesterday - and to make the abstraction
future-proof, also cover 3.8 and 3.9 in advance ;-)

(cherry picked from commit 01f41fbff8)

Signed-off-by: Steve Beattie <steve.beattie@canonical.com>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/139/
2018-06-29 11:19:31 -07:00
Christian Boltz
35522677d3 Merge branch 'cboltz-nested-child-error' into 'master'
parse_profile_start(): Error out on nested child profiles

See merge request apparmor/apparmor!136

Acked-by: John Johansen <john.johansen@canonical.com> for 2.10..master

(cherry picked from commit b7a4f37cbb)

8462c39b parse_profile_start(): Error out on nested child profiles
2018-06-21 10:20:20 +00:00
Christian Boltz
90c0d2b3c3
profiles: update samba profiles
- allow smbd to load new shared libraries
- allow winbindd to read and write new kerberos cache location

Based on a patch by "Samuel Cabrero" <scabrero@suse.com>

(cherry picked from commit 23b5f29b80)

References: https://bugzilla.opensuse.org/show_bug.cgi?id=1092099

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/121
2018-05-09 14:02:02 -07:00
Patrick Steinhardt
0361997506
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.

(cherry picked from commit 655d3e7826)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/107
2018-05-09 13:28:47 -07:00
Patrick Steinhardt
14f622bc2b
libapparmor: do not honor $LIBAPPARMOR_DEBUG when secure_getenv is undefined
The `secure_getenv` function is a non-POSIX compliant extension of
glibc. In contrast to the POSIX `getenv`, `secure_getenv` will return
`NULL` for all environment variables when the program is run with
escalated privileges due to an SUID or SGID bit. Some strictly
POSIX-compliant libc libraries, most notably musl libc, do not have this
function and do not wish to implement it. Thus, AppArmor cannot be
compiled on such systems.

In libapparmor, `secure_getenv` is only used to determine whether the
environment variable DEBUG_ENV_VAR has been set to enable debugging. In
case an unprivileged user runs a SUID/SGID executable linked against
libapparmor, we do not want that user to be able to get additional
information via debug output.

The fix here is to produce an error only in case where debug output is
enabled by defining ENABLE_DEBUG_OUTPUT. Otherwise, we simply define
`secure_getenv` to `NULL` to completely disable the debug output.

(cherry picked from commit 778176b9d8)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Acked-by: Steve Beattie <steve@nxnw.org>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/107
2018-05-09 13:27:20 -07:00
Patrick Steinhardt
a0b77b804b
libapparmor: make aa_policy_cache_add_ro_dir function visible
While the parser makes use of the `aa_policy_cache_add_ro_dir` function,
it is not being declared as a global function in the libapparmor.map
file. Due to this, dynamic linking of apparmor_parser with
libapparmor.so is not possible.

[Fixed up to use 2.13.1 symbol section as when the
 `aa_policy_cache_add_ro_dir` was introduced -- @smb]

(cherry picked from commit 1506f2cf0e)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
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/107
2018-05-09 13:24:29 -07:00
Christian Boltz
26a3351552
utis: fix writing alias rules
write_pair() ignored the 'tail' parameter, which resulted in writing
invalid alias rules (without the trailing comma).

Also add an alias to test/cleanprof.* to ensure it doesn't break again.

(cherry picked from commit ae4ab62855)

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/119
2018-05-08 07:50:09 -07:00
Christian Boltz
28586f7309
utils: fix writing "link subset" rules
Writing a "link subset" rule missed a space, which resulted in something
like
  link subset/foo -> /bar,

Also add a test rule to tests/cleanprof.* to ensure this doesn't break
again.

(cherry picked from commit 514535608f)

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/117
2018-05-06 22:32:40 -07:00
Steve Beattie
71d089b4fa
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.

(cherry picked from commit 9f2959482f)

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:16:36 -07:00
John Johansen
9179b5cf17 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>


(cherry picked from commit 67d84c8959)

5b9497a8 is_skippable_dir(): add 'cache.d' to exclude list
2018-04-30 20:56:40 +00:00
Steve Beattie
21ffea57f6
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.

(cherry picked from commit 49ba6af2bf)

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:32:54 -07:00
John Johansen
313e0b4266
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

(cherry picked from commit b08b327922)

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:20:05 -07:00
John Johansen
f2914da00a
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.

(cherry picked from commit c82fcd227d)

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:18:13 -07:00
Christian Boltz
6801c0d0d0
fix permissions of apparmor.systemd helper script
References: https://bugzilla.opensuse.org/show_bug.cgi?id=1090545
(cherry picked from commit f179612abe)

Acked-by: Steve Beattie <steve@nxnw.org>
PR: https://gitlab.com/apparmor/apparmor/merge_requests/106/
2018-04-25 16:14:27 -07:00
Christian Boltz
2becda217b
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)

(cherry picked from commit 62ecc2b574)
Acked-by: Steve Beattie <steve@nxnw.org>

PR: https://gitlab.com/apparmor/apparmor/merge_requests/97
2018-04-25 16:04:09 -07:00
Steve Beattie
8e63137612 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:14:29 -07: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