Commit graph

1106 commits

Author SHA1 Message Date
John Johansen
520dd4fab0 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>
(cherry picked from commit 2ea3309942)
2018-01-20 00:44:56 -08:00
John Johansen
84391104f4 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>
(cherry picked from commit 8d142809f5)
2018-01-20 00:44:42 -08:00
John Johansen
f7f3d4e6f2 parser tests: add tests for relative path includes
Signed-off-by: John Johansen <john.johansen@canonical.com>
(cherry picked from commit efd8eedd52)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-01-20 00:44:07 -08:00
Thorsten Kukuk
e3d4200453 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

(cherry picked from commit 924983e702)
Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-01-16 11:34:22 -08:00
John Johansen
6f31a83c5a 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:14:57 -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
intrigeri
12fc3f0d4d Raise the self-test timeout to 4 minutes for really slow machines.
Original author: Kees Cook <kees@debian.org>

Fixes https://bugs.debian.org/699774.
2017-10-23 15:28:48 +02:00
Steve Beattie
b926125618 Translations: merge updates from launchpad
Updates to the following translations:

  * binutils - add and update an entry to de.po
  * utils
    - de.po: add several entries
    - en_GB.po: add many entries
    - es.po: add non-existing(?) entry
    - id.po: add many entries
    - sv.po: update and add correct a number of entries

All other changes are the usual nonsense of launchpad updating
timestamps and export information.
2017-10-09 14:23:37 -07:00
John Johansen
112af14dd5 Remove the use of dbus from comments and policy from unix tests
Note one use of dbus is left because it is represnative of a unix
socket name used for communication with dbus

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2017-10-09 13:18:08 -07:00
Steve Beattie
f2831c875e merge from apparmor trunk 2017-10-05 16:52:55 -07:00
Patrick Steinhardt
ca42518c1d parser: include <limits.h> for PATH_MAX macro
The macro `PATH_MAX` macro is typically defined in the <limits.h>
header by the system's libc implementation. While we do not
include it right now, glibc indirectly includes it via other
headers already and thus compilation of the file succeeds. For
other libc implementations this may not be the case, which would
then lead to a compilation error. This is the case for musl libc.

Explicitly include <limits.h> to fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2017-09-27 11:38:35 +02:00
Patrick Steinhardt
41c1e30e9b parser: fix compilation with missing RLIMIT macros
The define `RLIMIT_OFILE` is a historic macro originating from
the BSDs, which is nowadays an alias for `RLIMIT_NOFILE`. On some
implementations, it has thus been dropped in favor of the new
define, but we still assume it will always be defined in our
rlimit keywords table. Wrap it in an `ifdef` to fix compilation
on systems where it does not exist.

For the second macro `RLIMIT_RTTIME`, we do check for its
existence in our keywords table, but then forgot to do so in the
YACC rules. Wrap it into an `ifdef`, as well.

Both patches serve the goal to fix compilation on musl libc.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2017-09-27 11:31:10 +02:00
John Johansen
4eece9d5ee with unix rules we output a downgraded rule compatible with network rules
so that policy will work on kernels that support network socket controls
but not the extended af_unix rules

however this is currently broken if the socket type is left unspecified
(initialized to -1), resulting in denials for kernels that don't support
the extended af_unix rules.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: timeout
2017-09-07 02:26:15 -07:00
Christian Boltz
347715da30 Add network 'smc' keyword in NetworkRule and apparmor.d manpage
'smc' seems to be new in kernel 4.12.


Note that the 2.10 apparmor.d manpage also misses the 'kcm' keyword, so
the patch also adds it there.


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk, 2.11 and 2.10.
2017-08-30 11:06:19 +02:00
Jamie Strandboge
27654be0b5 Update parser/policy_cache.c to consistently use defines in
valid_cached_file_version()

Signed-Off-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2017-08-29 08:58:34 -05:00
Tyler Hicks
8901b3e835 parser: Preserve unknown profiles when restarting apparmor init/job/unit
CVE-2017-6507

https://launchpad.net/bugs/1668892

The common AppArmor 'restart' code used by some init scripts, upstart
jobs, and/or systemd units contained functionality that is no longer
appropriate to retain. Any profiles not found /etc/apparmor.d/ were
assumed to be obsolete and were unloaded. That behavior became
problematic now that there's a growing number of projects that maintain
their own internal set of AppArmor profiles outside of /etc/apparmor.d/.
It resulted in the AppArmor 'restart' code leaving some important
processes running unconfined. A couple examples are profiles managed by
LXD and Docker.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2017-03-24 05:06:07 +00:00
Seth Arnold
1285d81547 parser: Fix delete after new[] -- patch from Oleg Strikov <oleg.strikov@gmail.com> 2017-03-21 12:09:59 -07:00
Kees Cook
f5384469b5 pass LDFLAGS fully into build
Acked-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
2017-01-19 23:04:34 +00:00
Steve Beattie
106396289a build: make documentation at tarball creation time, not during build
The latex based techdoc in the parser/ tree adds a number of build
dependencies for downstreams to create it; it also is the primary
element to make the builds unrepeatable. Creating the techdoc and other
documentation when generating a tarball for distribution avoids all
that.

* Makefile: build documentation as part of the tarball creation. Skip
  the libraries/libapparmor directory as it needs to have configure run
  before the manpages can be made.
* changehat/mod_apparmor/Makefile, changehat/mod_apparmor/Makefile,
  utils/Makefile, profiles/Makefile: create separate docs target,
  some of them dummies.
* parser/Makefile: pull the techdoc out of the default build target, add
  an extra_docs target to create it.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2016-12-10 10:25:31 -08:00
Christian Boltz
d8de3a1e20 Fix 'alias' rule description in apparmor.d manpage
The apparmor.d description about alias rules was broken in multiple
ways. The manpage
- didn't include the   alias   keyword
- listed alias rules in the "COMMA RULES" section - while that's correct
  for the comma requirement, it's also wrong because COMMA RULES is
  meant to be inside a profile
- didn't list alias rules in the PREAMBLE section

This patch fixes this.

It also moves the definition of VARIABLE, VARIABLE ASSIGNMENT (both
unchanged) and ALIAS RULE next to PREAMBLE.


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10
2016-11-16 20:38:54 +01:00
intrigeri
095e9eea82 Fix typo: s/resonable/reasonable/. 2016-10-15 11:33:50 -05:00
Christian Boltz
e0134514e2 add network 'kcm' keyword to apparmor.d manpage
I already did this in the python code a month ago, and now realized that
we should also update the apparmor.d manpage ;-)


Acked-by: Seth Arnold <seth.arnold@canonical.com> for trunk and 2.10.
2016-10-14 20:32:48 +02:00
John Johansen
40e193e623 Fix: make sure overlapping safe and unsafe exec rules conflict
BugLink: https://launchpad.net/bugs/1588069

Currently

  change_profile /** -> A,
  change_profile unsafe /** -> A,

do not conflict because the safe rules only set the change_profile
permission where the unsafe set unsafe exec. To fix this we have the
safe version set exec bits as well with out setting unsafe exec.
This allows the exec conflict logic to detect any conflicts.

This is safe to do even for older kernels as the exec bits off of the
2nd term encoding in the change_onexec rules are unused.

Test files
  tst/simple_tests/change_profile/onx_no_conflict_safe1.sd
  tst/simple_tests/change_profile/onx_no_conflict_safe2.sd
by Christian Boltz <apparmor@cboltz.de>

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2016-06-02 22:24:22 -07:00
Christian Boltz
c3bcdc32fb Document aliases for dbus send and receive in apparmor.d
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2016-06-01 22:55:14 +02:00
Launchpad Translations on behalf of apparmor-dev
79f41156e8 Launchpad automatic translations update. 2016-06-01 05:15:41 +00:00
Tyler Hicks
fe14a337ef parser: Clean up exec mode parsing
The opt_unsafe token was being used to represent 'safe' and 'unsafe' so
it is renamed to opt_exec_mode. Create helpfully named macros to compare
opt_exec_mode's value against instead of hard-coded '0', '1', and '2'
values.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2016-05-31 15:38:36 -05:00
Tyler Hicks
138a9bf9ef parser: Document change_profile exec modes in apparmor.d man page
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2016-05-31 15:38:36 -05:00
Tyler Hicks
b5d7154100 parser: Add tests for rules with change_profile exec modes
Simple tests that validate the parser's ability to handle change_profile
rules containing an exec mode.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2016-05-31 15:38:36 -05:00
John Johansen
0fe6e1955a parser: combine SUB_ID and SUB_ID_WS to reduce code duplication
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2016-05-31 15:38:36 -05:00
Tyler Hicks
0c4c975509 parser: Allow change_profile rules to accept an exec mode modifier
https://launchpad.net/bugs/1584069

This patch allows policy authors to specify how exec transitions should
be handled with respect to setting AT_SECURE in the new process'
auxiliary vector and, ultimately, having libc scrub (or not scrub) the
environment.

An exec mode of 'safe' means that the environment will be scrubbed and
this is the default in kernels that support AppArmor profile stacking.
An exec mode of 'unsafe' means that the environment will not be scrubbed
and this is the default and only supported change_profile exec mode in
kernels that do not support AppArmor profile stacking.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2016-05-31 15:32:08 -05:00
Tyler Hicks
0801b3a72f parser: Simplify change_profile grammar rules
Make future modifications to the change_profile grammar rules easier by
simplifying things. First, the change_profile rule handling is collapsed
into a single grammar rule. The inputs to the grammar rule are given
helpful variable names to make it harder to mix up which variable we're
dealing with. Finally, the two separate calls to new_entry() are unified
into a single call.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2016-05-28 11:58:41 -05:00
Steve Beattie
4d5a4675d8 translations: fix up msgfmt warnings
This commit touches up the .po files that generate warnings
when msgfmt processes them to create .mo files, at least with gettext
0.19.7-2ubuntu3 in Ubuntu 16.04 LTS. Example warning types cleaned up
include:

  ce.po:7: warning: header field 'Last-Translator' still has the initial default value
  ce.po:7: warning: header field 'Language' missing in header
  de.po:6: warning: header field 'Language-Team' still has the initial default value

This commit also fixes up po files where the Report-Msgid-Bugs-To:
field had not been updated, setting it with the email address
'AppArmor list <apparmor@lists.ubuntu.com>'

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2016-05-24 13:08:06 -07:00
Steve Beattie
ad65a4467e merge translations update from launchpad 2016-05-23 15:30:36 -07:00
Christian Boltz
bdf5a2facc Document empty quotes ("") as empty value of a variable
Acked-by: Seth Arnold <seth.arnold@canonical.com> for all branches where this makes sense :)
2016-05-22 14:51:19 +02:00
Launchpad Translations on behalf of apparmor-dev
47aa6baad3 Launchpad automatic translations update. 2016-04-29 05:14:00 +00:00
John Johansen
22738991ac Fix: parser: incorrect output of child profile names
BugLink: http://bugs.launchpad.net/bugs/1551950

The apparmor_parser is incorrectly outputting the names of child profiles
and hats, by adding a : between the parent and the child profile name

  Eg.
    /usr/sbin/httpd{,2}-prefork
    /usr/sbin/httpd{,2}-prefork://DEFAULT_URI
    /usr/sbin/httpd{,2}-prefork://HANDLING_UNTRUSTED_INPUT

  instead of what it should be
    /usr/sbin/httpd{,2}-prefork
    /usr/sbin/httpd{,2}-prefork//DEFAULT_URI
    /usr/sbin/httpd{,2}-prefork//HANDLING_UNTRUSTED_INPUT

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-04-18 13:26:53 -07:00
John Johansen
26b3bc5799 Enable dynamically scaling max jobs if new resources are brought online
BugLink: http://bugs.launchpad.net/bugs/1566490

This patch enables to parser to scale the max jobs if new resources are
being brought online by the scheduler.

It only enables the scaling check if there is a difference between the
maximum number of cpus (CONF) and the number of online (ONLN) cpus.

Instead of checking for more resources regardless, of whether the online
cpu count is increasing it limits its checking to a maximum of
MAX CPUS + 1 - ONLN cpus times. With each check coming after fork spawns a
new work unit, giving the scheduler a chance to bring new cpus online
before the next check.  The +1 ensures the checks will be done at least
once after the scheduling task sleeps waiting for its children giving
the scheduler an extra chance to bring cpus online.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-04-11 16:22:12 -07:00
Tyler Hicks
e815226675 parser: Fix dependency in Makefile
parser 'make install' failed if 'make' wasn't run before. This patch
adds the missing dependency 'install-indep: indep'.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2016-04-06 12:23:48 -05:00
Launchpad Translations on behalf of apparmor-dev
d0871bf2a8 Launchpad automatic translations update. 2016-03-30 05:13:33 +00:00
Tyler Hicks
f82344d7ff parser: Allow debugedit to work on apparmor_parser
https://launchpad.net/bugs/1561939

The debugedit program is unable to cope with the extra slash in the
LIBAPPARMOR_SRC variable.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Suggested-by: Christian Svensson <blue@cmd.nu>
2016-03-25 10:28:52 -05:00
Steve Beattie
4dcfa7db35 parser: eliminate redundant/dead code
The debugging code for profile entries contains a check to ensure that
it's not NULL, but the list iterator macro already ensures that the
iteration will stop if the item is NULL, making the check redundant.

Coverity CID #55983

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2016-03-19 01:52:45 -07:00
Steve Beattie
e69891c222 man page touchups
This makes some of the references to functions in the aa_query_label(2)
manpage more consistent and fixes a couple of grammar issues. It also
tries to make the qualifying statements in apparmor.d(5) more distinct,
and also fixes some typos there as well.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2016-03-19 01:48:11 -07:00
Tyler Hicks
a23dd56e03 parser: Update features.all file for new kernel features
The audit_read capability, mpls address family, and profile stacking are
all new features advertised by the latest AppArmor kernel features file.

Without this change, the parser tests will fail because parsing profiles
that utilize stacking results in an error when the features file
indicates that stacking is not supported by the kernel.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2016-03-19 03:03:18 -05:00
Tyler Hicks
1a7663e89a parser: Check kernel stacking support when handling stacked transitions
Check if the current kernel supports stacking. If not, ensure that named
transitions (exec, change_profile, etc.) do not attempt to stack their
targets.

Also, set up the change_profile vector according to whether or not the
kernel supports stacking. Earlier kernels expect the policy namespace to
be in its own NUL-terminated vector element rather than passing the
entire label (namespace and profile name) as a single string to the
kernel.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2016-03-18 17:28:51 -05:00
Tyler Hicks
00fb4e94ab parser: Support stacking in exec and change_profile rules
Allow for a leading '&' character to be present in the named transition
target strings to indicate that the transition should stack the current
profile with the specified profile.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2016-03-18 17:28:51 -05:00
Tyler Hicks
a83d03a6a7 parser: Stop splitting the namespace from the named transition targets
The parser was splitting up the namespace and profile name from named
transition targets only to rejoin it later when creating the binary
policy. This complicated the changes needed to support the stacking
identifier '&' in named transition targets.

To keep the stacking support simple, this patch keeps the entire named
transition target string intact from initial profile parsing to writing
out the binary.

All of these changes are straightforward except the hunk that removes
the namespace string addition to the vector in the process_dfa_entry()
function. After speaking with John, kernels with stacking have support
for consuming the namespace with the profile name.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2016-03-18 17:28:51 -05:00
Tyler Hicks
a49c988c03 parser: Create a label parsing function that doesn't exit or malloc
This patch separates the label parsing functionality from the program
termination and memory allocation duties of parse_label(). This will
ultimately help in creating simple helper functions that simply need to
check if a label contains a namespace.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2016-03-18 17:28:51 -05:00