Commit graph

5236 commits

Author SHA1 Message Date
John Johansen
2416faac54 parser: support matching xattr keys but not values
Support profiles that choose to match the presence of an extended
attribute without validating its value. This lets AppArmor target xattrs
with binary data, such as security.ima and security.evm values. For
example, it's now possible to write a profile such as:

        profile signed_binaries /** xattrs=(security.ima) {
                # ...
        }

Both presence and value matches can be used in the same profile. To
match a signed xattr, target both the xattr and the security.ima value:

        profile python_script /** xattrs=(
                security.evm
                security.apparmor="python"
        ) {
                # ...
        }

Updated to work using out of band matching instead of separate data
array.

Signed-off-by: Eric Chiang <ericchiang@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
e5ea3e4a0d parser: Make xattr attachment generation conditional on kernel support
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
9b0a98d00e parser: make sure xattr cond_entry_list is not leaked
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
6b47b8de25 parser: Allow xattr globbing to match the NULL character
xattrs are a byte string that can contain all input characters including
the null character. Allow * ** and ? glob patterns to match the null
character while retaining their apparmor characteristics for '/'.

That is * and ? won't traverse a '/' treating it as a path element.
While ** will match anything.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
2992e6973f parser: convert xmatch to use out of band transitions
xattrs can contain NULL characters in their values which means we can
not user regular NULL transitions to separate values. To fix this
use out of band transition instead.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
53dffc5304 parser/libapparmor_re: add basic documentation about components
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
16b67ddbd6 add ability to use out of band transitions
Currently the NULL character is used as an out of band transition
for string/path elements. This works for them as the NULL character
is not valid for this data. However this does not work for binary
data that can contain a NULL character.

So far we have only dealt with fixed length fields of binary data
making the NULL separator either unnecessary.

However binary data like in the xattr match and mount data field are
variable length and can contain NULL characters. To deal with this
add the ability to specify out of band transitions, that can only
be triggered by code not input data.

The out of band transition can be used to separate variable length
data fields just as the NULL transition has been used to separate
variable length strings.

In the compressed hfa out of band transitions are expressed as a
negative offset from the states base. This leaves us room to expand
the character match range in the future if desired and on average
makes the range between the out of band transition and the input
transitions smaller than would be had if the out of band transition
had been stored after the valid input transitions.

Out of band transitions in the dfa will not break old kernels
that don't know about them, but they won't be able to trigger
the out of band transition match. So they should not be used unless
the kernel indicates that it supports them.

It should be noted that this patch only adds support for a single
out of band transition. If multiple out of band transitions are
required. It is trivial to extend.
- Add a tag indicating support in the kernel
- add a oob max range field to the dfa header so the kernel knows
  what the max range that needs verifying is.
- extend oob generation fns to generate oob based on value instead
  of a fixed -1.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
6062262ccd parser: fix writing dfa flags
Currently the parser is not correctly setting the dfa flag value
and it hasn't been caught because base policy uses a flag value
of 0.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
7c29bfebe3 parser: improve debug output of transhar
Make transchar stream output work with a broader range of values.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
72f93d9aba parser: rename uchar to transchar
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
daa10d3ce1 parser: rework backend to allow for more transitions
As a step in preparing for out of band transitions and double walk
transitions rework the backend from using a char index to a class
with an larger range than char.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-26 21:32:08 -08:00
John Johansen
e958da7678 Nnp unconfined exception tests
Add nnp tests around the unconfined exception.

An unconfined task is allowed changing to a profile under nnp restrictions. However this has implications when the task has stacked confinement.

  profile//&unconfined

  profile//&:ns:unconfined

  ...

will not be caught by the unconfined test. Instead the unconfined exception needs to be tested as part of the subset test. Add tests to ensure we can catch regressions around a stacked unconfined profile.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/424
Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-11-27 05:29:13 +00:00
Christian Boltz
6c85836be5
add zlib1g-dev to .gitlab-ci.yml
This fixes the CI failures introduced with
3db14e8e49 - either conf('BLDLIBRARY') or
$PYTHON_EXTRA_LIBS introduce a dependency on zlib-dev ("-lz").
2019-11-19 22:52:22 +01:00
Christian Boltz
663546c284 Merge branch 'cboltz-abstractions-kerberos' into 'master'
abstractions/kerberosclient: allow reading /etc/krb5.conf.d/

See merge request apparmor/apparmor!425

Acked-by: Steve Beattie <steve@nxnw.org> for 2.10..master
Acked-by: John Johansen <john.johansen@canonical.com> for 2.10..master
2019-11-18 21:35:29 +00:00
Christian Boltz
b017f8f8a9 Merge branch 'cboltz-drop-localinclude' into 'master'
Drop 'localinclude' in parse_profile_data() and ProfileStorage

See merge request apparmor/apparmor!427

Acked-by: John Johansen <john.johansen@canonical.com> for 2.12..master
Acked-by: Steve Beattie <steve@nxnw.org> for 2.12..master
2019-11-18 21:32:24 +00:00
Christian Boltz
3db14e8e49 Merge branch 'fix-autoconf-check-for-python-3.8' into 'master'
Fix a Python 3.8 autoconf check

See merge request apparmor/apparmor!430

Acked-by: Christian Boltz <apparmor@cboltz.de> for master and 2.13
Acked-by: Steve Beattie <steve@nxnw.org> for master and 2.13
2019-11-18 20:16:33 +00:00
John Johansen
095efb821f docs: update apparmor.d language description
Update the language description to provide some over arching
principles, such as the policy is declarative.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
Acked-by: Steve Beattie <steve.beattie@canonical.com>
2019-11-09 14:05:22 -08:00
John Johansen
d6384641c2 added missing functions to slackware init script
There where some functions missing in the Slackware init script which has been added with this commit.

PR: https://gitlab.com/apparmor/apparmor/merge_requests/432
Acked-by: John Johansen <john.johansen@canonical.com>
2019-11-09 11:00:01 +00:00
lmoeller
32105d0816 added missing functions to slackware init script 2019-11-08 13:49:48 +01:00
intrigeri
ccbf1e0bf1 Fix a Python 3.8 autoconf check
Bug-Debian: https://bugs.debian.org/943657

Author: Matthias Klose <doko@debian.org>
2019-10-29 17:53:11 +00:00
Christian Boltz
1567ea6f4c Merge branch 'cboltz-pyflakes-version' into 'master'
README: add PYFLAKES=/usr/bin/pyflakes3 env variable

See merge request apparmor/apparmor!429

Acked-by: John Johansen <john.johansen@canonical.com> for 2.11..master
2019-10-24 21:08:28 +00:00
Christian Boltz
556bb94aa5
README: add PYFLAKES=/usr/bin/pyflakes3 env variable
pyflakes 2.x nowadays complains about
    aa-genprof:60: undefined name 'PermissionError'

We already deprecated py2 support in 2.11 (and obviously nobody tests
with py2 anymore), therefore recommending pyflakes3 makes sense.

Maybe we should also change our Makefiles to use py3 and pyflakes3 by
default, but that will be another (master-only) commit.
2019-10-24 15:36:22 +02:00
Christian Boltz
001ea9e3af
Drop 'localinclude' in parse_profile_data() and ProfileStorage
'localinclude' is/was meant to have 'local/*' includes separate, but
it's write-only and never used, which makes it useless.

Additionally, it causes a crash in the aa-* tools which gets fixed by
removing all the 'localinclude'-related code (what a big word for two
lines ;-)

References: https://bugs.launchpad.net/apparmor/+bug/1848227
2019-10-16 21:30:43 +02:00
Christian Boltz
ee7194a714
Allow /usr/etc/ in abstractions/authentication
openSUSE (and hopefully some other distributions) work on moving shipped
config files from /etc/ to /usr/etc/ so that /etc/ only contains files
written by the admin of each system.

See https://en.opensuse.org/openSUSE:Packaging_UsrEtc for details and
the first moved files.

Updating abstractions/authentication is the first step, and also fixes
bugzilla.opensuse.org/show_bug.cgi?id=1153162
2019-10-07 21:47:25 +02:00
Christian Boltz
5066dc6195 Merge branch 'profile-usr.sbin.winbindd' into 'master'
Update usr.sbin.winbindd profile

Winbind requires access to `/var/cache/samba/msg.lock/*`.

On Arch Linux Winbind's pid is set to `/run/winbindd.pid` ( https://git.archlinux.org/svntogit/packages.git/tree/trunk/winbindd.service?h=packages/samba ).

See merge request apparmor/apparmor!411

Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-10-03 17:53:21 +00:00
Christian Boltz
a2d43e7546 Merge branch 'avoid-blhc-false-positive' into 'master'
Avoid blhc "CPPFLAGS missing" false positive.

See merge request apparmor/apparmor!403

Acked-by: John Johansen <john.johansen@canonical.com>
2019-09-30 21:53:50 +00:00
John Johansen
cb5aeec433 regression tests: add unconfined exception tests to nnp.sh
The unconfined exception needs to be applied even when a stack is
being used. When a stack is in use it prevents the unconfined
test from being used and instead it must be done as part of the
subset test.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-09-29 19:58:02 -04:00
Christian Boltz
dffed83161
abstractions/kerberosclient: allow reading /etc/krb5.conf.d/
Permit the use of /etc/krb5.conf.d configuration snippets

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>

Originally submitted as https://build.opensuse.org/request/show/733763
2019-09-28 17:25:39 +02:00
Christian Boltz
0b94cbe516 Merge branch 'cboltz-drop-deprecated' into 'master'
drop deprecated perl code

* drop repair_obsolete_profiles (updated profiles for abstraction renames pre-2006)
* drop ancient perl aa-* tools and their modules (rewritten to python in 2.9)
* drop rc.aaeventd.{redhat,suse} initscripts (aaeventd was dropped long ago, therefore we don't need to keep its initscripts)

See merge request apparmor/apparmor!423

Acked-by: John Johansen <john.johansen@canonical.com>
2019-09-25 20:32:20 +00:00
Christian Boltz
523f21fb20
drop rc.aaeventd.{redhat,suse} initscripts
aaeventd was dropped long ago, therefore we don't need to keep its
initscripts.
2019-09-23 21:46:16 +02:00
Christian Boltz
12488fcc9a
drop ancient perl aa-* tools and their modules
They were rewritten to python in 2.9.
2019-09-23 21:43:58 +02:00
Christian Boltz
506f51e6fd
drop repair_obsolete_profiles
(updated profiles for abstraction renames pre-2006)
2019-09-23 21:40:27 +02:00
Christian Boltz
98fde52998 Merge branch 'drop-perl' into 'master'
drop deprecated perl code
* aa-repo.pl
* convert-profile.pl

See merge request apparmor/apparmor!416

Acked-by: Christian Boltz <apparmor@cboltz.de>
2019-09-23 19:35:58 +00:00
Christian Boltz
b76567ce10 Merge branch 'cboltz-status-parenthesis' into 'master'
aa-status: handle profile names containing '('

Closes #51

See merge request apparmor/apparmor!415

Acked-by: John Johansen <john.johansen@canonical.com> for 2.10..master
2019-09-23 18:55:22 +00:00
John Johansen
094f9727fa Merge branch 'dont-allow-fontconfig-cache-write' into 'master'
abstractions/fonts: don't allow write of fontconfig cache files

See merge request apparmor/apparmor!420
2019-09-20 09:42:53 +00:00
John Johansen
c9fcc18b9a Fix setfcap Cap mispelling
PR: https://gitlab.com/apparmor/apparmor/merge_requests/421
Acked-by: John Johansen <john.johansen@canonical.com>
2019-09-17 10:01:03 +00:00
Paulo Gomes
2d19d4d159
Fix capability mispelling. 2019-09-17 10:38:09 +01:00
John Johansen
59e799a9ba abstractions/X: allow reading the Xauth file mutter passes to Xwayland.
Applications running under Xwayland in a GNOME+Wayland session need read access to this file since:

a8984a81c2

… that was first included in mutter 3.33.3.

This rule is presumably only needed for GNOME+Wayland sessions, so one could argue that it should live in abstractions/wayland instead, but Jamie argued that it should be in the X abstraction because Xwayland is a X server.

MR: https://gitlab.com/apparmor/apparmor/merge_requests/419
Bug-Debian: https://bugs.debian.org/935058
Acked-by: John Johansen <john.johansen@canonical.com>
2019-09-16 15:08:40 +00:00
Jamie Strandboge
c5968c70d0 abstractions/fonts: don't allow write of fontconfig cache files
879531b36ec3dfc7f9b72475c68c30e4f4b7b6af changed access for
@{HOME}/.{,cache/}fontconfig/** to include 'w'rite. Fontconfig has been
a source of CVEs. Confined applications should absolutely have read
access, but write access could lead to breaking out of the sandbox if a
confined application can write a malformed font cache file since
unconfined applications could then pick them up and be controlled via
the malformed cache. The breakout is dependent on the fontconfig
vulnerability, but this is the sort of thing AppArmor is meant to help
guard against.
2019-09-09 15:52:40 -05:00
intrigeri
c006f79141 abstractions/X: allow reading the Xauth file mutter passes to Xwayland.
Bug-Debian: https://bugs.debian.org/935058

Applications running under Xwayland in a GNOME+Wayland session need read access
to this file since:

  a8984a81c2

… that was first included in mutter 3.33.3.

This rule is presumably only needed for GNOME+Wayland sessions, so one could
argue that it should live in abstractions/wayland instead, but Jamie argued that
it should be in the X abstraction because Xwayland is a X server.
2019-09-08 07:41:36 +00:00
intrigeri
33c5f61c75 Merge branch 'utab' into 'master'
profiles/gnome: Allow access of /run/mount/utab

See merge request apparmor/apparmor!412
2019-09-08 06:58:44 +00:00
intrigeri
9acb17adf0 Merge branch 'cboltz-whitespace' into 'master'
fix whitespace and indentation in several files

See merge request apparmor/apparmor!413
2019-09-08 06:48:27 +00:00
Bryan Quigley
0401235949 Remove a selection of obsolete support.
Requires NPAPI which no major browsers support anymore:
Mozplugger
npviewer / nspluginwrapper

The following have been discontinued
Google Talk (and plugin)
f-spot
conkeror
galeon
Mozilla Prism
rekonq
Adobe Reader for Linux

Other
gnome-codec-install is not in Ubuntu anymore
gstreamer0.10 was replaced by 1.0
2019-08-24 09:50:34 -07:00
John Johansen
a00ac89be8 drop deprecated perl code
With the effort to remove perl, it makes no sense to keep the depracted
perl code around for new releases.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2019-08-21 18:31:34 -07:00
Christian Boltz
41d26b0197
aa-status: handle profile names containing '('
aa-status crashed if a profile name contains an opening parenthesis
because the regex enforces (simplified) '^[^(]* \(.*\)' when reading
/sys/kernel/security/apparmor/profiles

This obviously doesn't match if a profile name contains '(' which is
rare and strange, but still allowed, and the match result "None" then
crashes aa-status.

Adjust the regex to allow all chars instead of all except '(' to handle
these corner cases.

Note that '(enforce)' and '(complain)' still get read correctly because
the regex ends with '\((\w+)\)$' and therefore enforces matching
"something inside parenthesis at the end of the line".

This bug exists since aa-status was rewritten into python, and even
existed in the perl version before. However, in the perl version, the
regex matching was protected with an if so profile names with '(' were
skipped and hidden from the aa-status output.

Fixes: https://gitlab.com/apparmor/apparmor/issues/51
2019-08-16 22:10:36 +02:00
Christian Boltz
e246568819
fix whitespace and indentation in several files 2019-08-12 23:58:04 +02:00
Jörg Sommer
cd3532f792 profiles/gnome: Allow access of /run/mount/utab
When a filesystem is mounted with the option *user*, the file selection
dialogue, e.g. in *Evince*, triggers an access of */run/mount/utab*, which
comes from *libmount* and should be allowed.
2019-08-09 10:11:37 +02:00
nl6720
54dc60ff5b Update usr.sbin.winbindd profile
Winbind requires access to /var/cache/samba/msg.lock/*.
Move msg.lock/ to abstractions/samba.
On Arch Linux Winbind's pid is set to /run/winbindd.pid.

Signed-off-by: nl6720 <nl6720@gmail.com>
2019-08-08 19:37:37 +03:00
Christian Boltz
2e304f82fc Merge branch 'cboltz-logparser-simplify-prefilter' into 'master'
Simplify log prefilter in logparser.py

See merge request apparmor/apparmor!400

Acked-by: John Johansen <john.johansen@canonical.com>
2019-08-05 20:01:59 +00:00
Christian Boltz
095d65f4ae
Simplify log prefilter in logparser.py
As discussed in https://gitlab.com/apparmor/apparmor/merge_requests/395
RE_LOG_ALL should be more broad so that it doesn't accidently
overlook/ignore valid log events.

Instead of adding more and more known log formats to logparser.py,
simplify the regex to do only a basic check.

If we really hand over a line to libapparmor that isn't an AppArmor log
event, worst thing that can happen is that we waste a few milliseconds
for handing over that line to libapparmor, and get AA_RECORD_INVALID as a
result.
2019-08-05 21:42:59 +02:00