Commit graph

1201 commits

Author SHA1 Message Date
Christian Boltz
6c42cd9eae
skip_profile: make tests posix-compatible
[ foo -o bar ] isn't supported everywhere, replace it with
[ foo ] || [ bar ]
2019-03-18 19:05:47 +01:00
Christian Boltz
75dc438823 Merge branch 'cboltz-deprecate-kill' into 'master'
drop most of apparmor_kill()

See merge request apparmor/apparmor!351

Acked-by: Eric Chiang <ericchiang@google.com>
2019-03-18 17:49:59 +00:00
Christian Boltz
be02f008c3
remove_profiles(): Fix returning $retval
Extend the subshell so that the actual (possibly non-zero) value of
$retval gets returned. Before, the changed value was lost at "done"
(= leaving the subshell), and the initial $retval=0 was returned.

(found with shellcheck)
2019-03-15 23:12:17 +01:00
Christian Boltz
0e3d6ee43a
drop most of apparmor_kill()
AppArmor can't be built as a kernel module since years, which also means
it's impossible to unload it.
2019-03-15 22:55:51 +01:00
Christian Boltz
6b2765637e
apparmor.d manpage: update list of network domain keywords
- add 'qipcrtr' and 'xdp'
- sort other keywords to the order in apparmor.vim
2019-03-14 21:54:30 +01:00
John Johansen
2c4386a0d1 Merge branch 'xmatch_regex_priority' into 'master'
parser: determine xmatch priority based on smallest DFA match

The length of a xmatch is used to prioritize multiple profiles that
match the same path, with the intent that the more specific match wins.
Currently, the length of a xmatch is computed by the position of the
first regex character.

While trying to work around issues with no_new_privs by combining
profiles, we noticed that the xmatch length computation doesn't work as
expected for multiple regexs. Consider the following two profiles:

    profile all /** { }
    profile bins /{,usr/,usr/local/}bin/** { }

xmatch_len is currently computed as "1" for both profiles, even though
"bins" is clearly more specific.

When determining the length of a regex, compute the smallest possible
match and use that for xmatch priority instead of the position of the
first regex character.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/326
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-03-12 11:23:30 +00:00
Christian Boltz
62abfe38e8
Replace deprecated assertEquals with assertEqual
assertEquals is deprecated since Python 2.7 and 3.2.
2019-02-26 21:27:00 +01:00
John Johansen
14f177e53a parser: update indentation of work_spawn() macro
Update the indetation of work_spawn to correct for the changes made in
cb43e57d27 ("parser: Fix parser failing to handle errors when setting up work")

the indetation was not updated in that patch to make the changes made
easier to review and see in diffs.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-02-22 02:28:43 -08:00
John Johansen
1259319508 parser: Fix parser failing to handle errors when setting up work
The parser is not correctly handling some error conditions when
dealing with work units. Failure to spawn work, access files, etc
should be returned where appropriate, and be able to abort processing
if abort_on_error is set.

In addition some errors are leading to a direct exit without checking
for abort_on_error.

BugLink: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=921866
BugLink: http://bugs.launchpad.net/bugs/1815294

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Eric Chiang <ericchiang@google.com>
2019-02-22 02:28:30 -08:00
Eric Chiang
cc09794fbd parser: determine xmatch priority based on smallest DFA match
The length of a xmatch is used to prioritize multiple profiles that
match the same path, with the intent that the more specific match wins.
Currently, the length of a xmatch is computed by the position of the
first regex character.

While trying to work around issues with no_new_privs by combining
profiles, we noticed that the xmatch length computation doesn't work as
expected for multiple regexs. Consider the following two profiles:

    profile all /** { }
    profile bins /{,usr/,usr/local/}bin/** { }

xmatch_len is currently computed as "1" for both profiles, even though
"bins" is clearly more specific.

When determining the length of a regex, compute the smallest possible
match and use that for xmatch priority instead of the position of the
first regex character.
2019-02-08 13:51:02 -08:00
John Johansen
b97587ec65 Make rc.apparmor.functions suitable for Debian and Ubuntu
Debian and Ubuntu currently don't use rc.apparmor.functions. They have their own code for loading profiles, their own initscript and systemd unit.

As discussed initially on https://bugs.debian.org/870697 and https://salsa.debian.org/apparmor-team/apparmor/merge_requests/6#note_29153, to fix that without introducing regressions on Debian/Ubuntu, we need to upstream a number of changes, which is what this branch is about.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/252
Acked-by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 20:29:20 +00:00
Eric Chiang
2609f356cb parser: fix warnings about unused functions
Signed-off-by: Eric Chiang <ericchiang@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-01-24 02:36:42 -08:00
Eric Chiang
cb8c3377ba *: ensure make apparmor_parser is cached
This change updates parser/Makefile to respect target dependencies and
not rebuild apparmor_parser if nothing's changed. The goal is to allow
cross-compiled tests #17 to run on a target system without the tests
attempting to rebuild the parser.

Two changes were made:

* Generate af_names.h in a script so the script timestamp is compared.
* Use FORCE instead of PHONY for libapparmor_re/libapparmor_re.a

Changes to list_af_names are intended to exactly replicate the old
behavior.

Signed-off-by: Eric Chiang <ericchiang@google.com>
2019-01-22 15:30:51 -08:00
intrigeri
775835db64 Fix is_apparmor_present() regression which breaks the Debian initscript.
Commit 0d5ab43d59 removed support for loading
modules and introduced a caller, in apparmor_start(), that passes no argument to
is_apparmor_present(), which breaks that function when /bin/sh → /bin/dash.

Passing a module name as argument does not make sense since we dropped support
for the long obsolete "subdomain" module, so let's simplify
is_apparmor_present() and adjust its callers accordingly.

Bug-Debian: https://bugs.debian.org/917874
2019-01-01 17:55:48 +00:00
intrigeri
1bd401bb35 Stop looking for apparmor.conf.
As per the discussion that starts at
https://gitlab.com/apparmor/apparmor/merge_requests/252#note_125983293,
apparmor.conf was never documented nor explicitly supported.
It's not really clear what problem it was meant to solve.
2018-12-28 16:34:17 +00:00
intrigeri
93f0c2d9ca Don't call the obsolete configure_owlsm function.
It was removed in commit 94ff870f.
2018-12-28 16:27:58 +00:00
intrigeri
3b997c79b4 Don't try to list files in a non-existent directory.
Thanks to Jamie Strandboge for spotting this during review.
2018-12-27 17:54:11 +00:00
intrigeri
10ba242b89 Make control flow clearer.
Let's add a safety net if we ever add another return code to skip_profile.
2018-12-27 17:46:43 +00:00
Emerson Bernier
b3937d19a4 parser/apparmor.systemd: fix minor issues detected by shellcheck 2018-12-21 19:50:10 +01:00
intrigeri
5865d01449 Remove dead code.
Since 04eb2fe3, __parse_profiles_dir can only return 0 or 1, so $STATUS can only
be 0 or 1, so trying to reset this variable to 0 when its value is 2 can only
cause confusion.
2018-12-16 21:05:06 +00:00
intrigeri
45bc0b8eb7 Merge remote-tracking branch 'origin/master' into prepare-rc.apparmor.functions-for-Debian-and-Ubuntu 2018-12-16 20:36:53 +00:00
Christian Boltz
228b92ce5a
Ignore *.orig and *.rej files when loading profiles
or: get rc.apparmor.functions in sync with the tools and libapparmor.

This was "accidently" reported by Ralph on the opensuse-support
mailinglist.
2018-11-28 22:50:09 +01:00
Christian Boltz
7ba8dc7e2e
Drop APPARMOR_ENABLE_AAEVENTD
This is another trace of aa-eventd which is deprecated since years.
2018-11-12 15:51:15 +01:00
John Johansen
2809060bec parser: limit the number of passes expr tree simplification does
Expr tree simplification makes multiple passes at simplifying the
expression tree trying to use fatoring rules and heuristics to achieve
the minimum tree, so that dfa construction has fewer nodes to deal
with.

Unfortunately expr tree simplification can slow some policy compiles,
dependent on the type of expressions generated, down, and even worse
is currently subject to never terminating on some expressions as the
left and right passes keep undoing each others work.

Limiting the number of passes that expr tree simplification does can
provide most of its benefits (later passes generally have diminishing
returns), reduces the overhead it has on simple policy where it is of
little benefit, and insures that simplifications can not get stuck in
an infinite loop due to the left and right passes ping-ponging on each
others factoring.

Note: This also results in a performance improvement in evince
compiles, and general policy compiles because it achieves a better
balance between time spent on simplifying the tree to remove nodes and
time the dfa build requires to build with extra nodes and then
eliminate with minimization.

$ time apparmor_parser -QT /etc/apparmor.d/usr.bin.evince
real	0m2.744s
user	0m2.714s
sys	0m0.028s

vs.

$ time apparmor_parser -QT /etc/apparmor.d/usr.bin.evince
real	0m2.992s
user	0m2.979s
sys	0m0.012s

and

$ time apparmor_parser -QT /etc/apparmor.d/
real	0m3.568s
user	0m14.529s
sys	0m0.152s

vs.

$ time apparmor_parser -QT /etc/apparmor.d/
real	0m3.741s
user	0m15.400s
sys	0m0.179s

PR: https://gitlab.com/apparmor/apparmor/merge_requests/246
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-11-09 13:01:01 -08:00
Christian Boltz
3a89e9811f
Remove traces of aa-eventd
aa-eventd and its initscripts have been moved to deprecated/ in 2014 and
didn't get any serious updates for several more years, so it's most
probably useless and/or broken nowadays.

This also means we don't need to keep the AA_EV_BIN and AA_EV_PIDFILE
variables in rc.apparmor.functions anymore.
2018-11-09 17:22:17 +01:00
John Johansen
94ff870f78 remove subdomainfs support
It has been over 10 years since transition from subdomainfs to
using securityfs. Lets drop this deprecated code.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/258
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: seth.arnold@canonical.com
2018-11-08 18:23:21 -08:00
John Johansen
0d5ab43d59 rc.apparmor.functions: drop module loading support
The apparmor kernel "module" has not been a loadable module for more
than a decade, it must be built into the kernel and due configuration
requirements it will never go back to being a loadable module.

Remove the long unfunctioning load_module support from the init script.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/257
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: seth.arnold@canonical.com
2018-11-08 18:22:09 -08:00
Eric Chiang
197b5d63fe parser/libapparmor_re: expand comment of firstpos, lastpos, followpos
Elaborate in class comment of firstpos, lastpos, followpos, and nullable
fields beyond just referencing the Dragon book. Also add the section of
the book these are explained in.
2018-11-06 19:08:28 -08:00
Christian Boltz
4b26850e14
error out on superfluous TODOs
If a test is marked as TODO, but matches its EXRESULT, this means the
TODO is superfluous and (probably) a change fixed what the TODO was for.

Instead of more or less ignoring such superfluous TODOs, error out to
make the change visible instantly.
2018-11-06 21:44:40 +01:00
Christian Boltz
a3305b512d
disable abi/ok_10 and abi/ok_12 tests
Both result in "superfluous TODO" (for unknown reason), but fail after
removing the TODO.

Disable the tests until we find out why they have this strange
behaviour, to unblock merging the "error out on superfluous TODO" patch.
2018-11-06 21:33:12 +01:00
Christian Boltz
c98d8570ee Merge branch 'cboltz-fixed-todos' into 'master'
Remove TODO notes from no-longer-failing tests

See merge request apparmor/apparmor!180

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: intrigeri <intrigeri@debian.org>
2018-11-06 17:33:49 +00:00
intrigeri
7416138b43 Merge remote-tracking branch 'origin/merge-requests/251'
apparmor(7): Document various debugging options.

Bug-Debian: https://bugs.debian.org/826218
PR: https://gitlab.com/apparmor/apparmor/merge_requests/251
2018-11-04 12:01:38 +00:00
intrigeri
b95f9bdd3b apparmor(7): Document various debugging options.
Credits go to John Johansen <john@jjmx.net> for most of the information
and the initial phrasing.

Bug-Debian: https://bugs.debian.org/826218
2018-11-04 11:43:04 +00:00
Christian Boltz
29da17310e
replace -1 return codes with 255
Technically "return -1" returns 255, so we should write it that way.

(found by shellcheck)
2018-11-02 17:00:33 +01:00
intrigeri
73e124d4fb rc.apparmor.functions: add is_container_with_internal_policy() function.
Imported from the Debian/Ubuntu packaging. We need this function so that
Debian/Ubuntu can switch to using this shell library instead of their own code.
2018-10-30 16:37:02 +00:00
intrigeri
f58c96699a rc.apparmor.functions: add support for an additional profiles directory, defaulting to /var/lib/snapd/apparmor/profiles.
We need this support so that Debian/Ubuntu can switch to using this shell
library instead of their own code.
2018-10-30 16:36:55 +00:00
intrigeri
13d9512287 rc.apparmor.functions: warn when the profiles directory cannot be found.
We do this for apparmor.conf so let's be consistent.
2018-10-30 15:30:01 +00:00
intrigeri
ff617819aa rc.apparmor.functions: delete disabled profile handling code.
It duplicates the parser's default behaviour.
2018-10-30 15:30:01 +00:00
intrigeri
222943eb3b rc.apparmor.functions: suppress warnings when booting in quiet mode. 2018-10-30 15:30:01 +00:00
intrigeri
04eb2fe345 rc.apparmor.functions: take benefit from the parser's automatic parallelization. 2018-10-30 13:37:05 +00:00
intrigeri
9385d00ea6 rc.apparmor.functions: stop passing -I explicitly to the parser.
A correctly configured/compiled parser adds $PROFILE_DIR to the search
path itself.
2018-10-30 13:13:04 +00:00
intrigeri
7c396bcd3e rc.apparmor.functions: drop force-complain handling code, that now duplicates parser's functionality. 2018-10-30 13:11:43 +00:00
Christian Boltz
3bf11cee3e
Fix syntax error in rc.apparmor.functions
This bug was introduced in
- https://gitlab.com/apparmor/apparmor/merge_requests/230
- commit c974dd0d07 (master)
- commit 9987a7ec9c (2.13 branch)
2018-10-14 18:10:46 +02:00
John Johansen
83df7c4747 parser: ignore feature abi rules
AppArmor 3.0 requires policy to use a feature abi rule for access to
new features. However some policy may start using abi rules even if
they don't have rules that require new features.  This is especially
true for out of tree policy being shipped in other packages.

Add enough support to older releases that the parser will ignore the
abi rule and warn that it is falling back to the apparmor 2.x
technique of using the system abi.

If the profile contains rules that the older parser does not
understand it will fail policy compilation at the unknown rule instead
of the abi rule.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/196
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-10-12 22:14:38 -07:00
John Johansen
4153663c42 parser: fix: ensure that a quotedid actually has both quotes
The handling for quotedid checked for the first quote but failed
to ensure the trailing quote was present.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/196
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-10-12 22:14:38 -07:00
John Johansen
04beee7633 parser: combine INCLUDE cases together and support escape sequences
We can reduce the INCLUDE/INCLUDE_EXISTS code dup by using a
variable for whether the name was enclosed by '<' and using
processid() to handle the whether the id is quoted or not.

In addition using processid allows include names to contain
escaoe sequences like \n and have them handled correctly.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/196
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-10-12 22:14:38 -07:00
John Johansen
eff672b2eb parser: refactor INCLUDE and INCLUDE_EXISTS to share a start condition
We can reduce code duplication by checking the current state to
determine the single parameter difference between include and
include if exists

PR: https://gitlab.com/apparmor/apparmor/merge_requests/196
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2018-10-12 22:14:38 -07:00
John Johansen
c421a29c61 parser: do not output cache warning for stdin if not using cache
Currently if stdin is used the warning
  apparmor_parser: cannot use or update cache, disable, or force-complain via stdin

is always displayed but if caching has been disabled there is no need for
this message.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2018-10-11 22:11:39 -07:00
Cameron Nemo
918e19238a
rc.apparmor.functions: skip XBPS conffile artifacts 2018-10-09 12:39:24 -07:00
John Johansen
17e059a253 parser: fix Makefile hardcoded paths to flex and bison
The hardcoded paths for flex and python can break builds on systems
where those tools are stored in an alternate location. Use which
to lookup where flex and bison are available.

This fixes issue #4

Signed-off-by: John Johansen <john.johansen@canonical.com>
2018-10-05 11:48:11 -07:00