Commit graph

3130 commits

Author SHA1 Message Date
Tyler Hicks
7de5ebd18f parser: Fail when a device is present with recursive mount make opts
The parser correctly rejects mount make-* options (make-shared,
make-slave, make-private, make-unbindable) when a device is specified
(the source argument of mount(2)). However, it was not rejecting the
recursive make-* options (make-rshared, make-rslave, make-rprivate,
make-runbindable) when a device was specified.

This patch adds the MS_REC bit, which is used to indicate a recursive
option, to the MS_CMDS macro. Without this change, the recursive options
are treated as normal mount options.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-12-12 08:21:09 -06:00
Tyler Hicks
7140bc27c3 parser: Fail compilation if unknown mount options are found
The parser should not indicate success when mount rules contain
unknown mount options:

  $ echo "/t { mount options=(XXX) -> **, }" | apparmor_parser -qQ
  $ echo $?
  0

This patch modifies the parser so that it prints an error message and
exits with 1:

  $ echo "/t { mount options=(XXX) -> **, }" | apparmor_parser -qQ
    unsupported mount options
  $ echo $?
  1

Bug: https://bugs.launchpad.net/bugs/1401621

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-12-12 08:20:49 -06:00
Tyler Hicks
d336d23e4d parser: Sync mount options parsing and documentation
There are a number of differences between what the apparmor.d(5) man
page lists as valid AppArmor mount rule options and what apparmor_parser
looks for when parsing mount rules. There are also typos in the man page
and parser around mount options. Here's the breakdown of problems and
fixes made in this patch:

 * The apparmor.d(5) man page improperly documented a "nodirsync"
   option.
   - That mount option does not exist and the parser did not honor it.
     Remove the mention from the apparmor.d(5) man page.
 * The loud option was typoed as "load" in both the man page and parser
   - There's no sense in preserving backwards compatibility. "load" is
     simply wrong and should not be honored. The man page and parser are
     updated to only use "loud".
 * The rbind option wasn't listed in the man page.
   - Add rbind to the man page. No change needed for the parser.
 * The documented unbindable, private, slave, and shared options were
   not correctly parsed. The parser expected
   make-{unbindable,private,slave,shared}.
   - The parser is updated to accept both the documented
     {unbindable,private,slave,shared} options and their variants
     prefixed with "make-". The man page will not document the "make-"
     variants.
 * The recursive {runbindable,rprivate,rslave,rshared} options were not
   documented and were only recognized by the parser if they were
   prefixed with "make-".
   - The man page is updated to document the option strings that are not
     prefixed with "make-". The parser still accepts the "make-"
     variants.
 * The man page documented a "rec" option but the parser didn't honor
   it. The MS_REC macro is used by the mount utility to be bitwise OR'ed
   with MS_{UNBINDABLE,PRIVATE,SLAVE,SHARED} to indicate the
   corresponding recursive mount options.
   - This is not an option that should be exposed in the AppArmor policy
     since we already allow have the
     {runbindable,rprivate,rslave,rshared} options.
 * The man page typoed the {no,}relatime options as {no,}relative.
   - The man page is updated to document the correct option strings. The
     parser requires no change.

Bug: https://bugs.launchpad.net/bugs/1401619

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-12-12 08:20:31 -06:00
Steve Beattie
b3523fa920 merge it (and en_GB) translations from launchpad 2014-12-11 15:42:43 -08:00
Steve Beattie
4485d039dc periodic sync up with trunk 2014-12-11 15:40:21 -08:00
Steve Beattie
149cdbc210 utils: improve recursive_print output for RawRules
When using recursive_print for debugging, RawRules objects weren't
reporting detailed information. This patch fixes that, as well as fixing
some indenting issues in the output.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-12-09 10:43:25 -08:00
Christian Boltz
3e222f4b42 delete outdated *.spec{,.in} files
Those *.spec{,.in} files were not updated for years (last change
2006/2007) and don't fit the current "one tarball for everything" model.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-08 22:21:47 +01:00
Christian Boltz
a79caef4c7 extra profiles: Allow useradd to execute nscd
(maybe it tells it to refresh its cache?)

Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-02 20:22:40 +01:00
Christian Boltz
c791881633 extra profiles: update vsftpd profiles
Allow reading /etc/environment, /etc/ftpusers, /@{PROC}/@{pid}/mounts.
Allow rk for /{,var/}run/utmp
(+ some whitespace fixes)

Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-02 20:20:37 +01:00
Christian Boltz
7131f4a7f9 extra profiles: delete duplicated lines in usr.sbin.sendmail
Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-02 20:19:22 +01:00
Christian Boltz
5295ba27d1 extra profiles: allow man to read itsself
Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-02 20:18:30 +01:00
Christian Boltz
826bdc27fd dnsmasq profile needs inet6 raw
Add "network inet6 raw," to the dnsmasq profile as counterpart to
the IPv4 "network inet raw,"

References: https://bugzilla.novell.com/show_bug.cgi?id=907870


Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-02 18:46:26 +01:00
Christian Boltz
dc50135bf6 delete commented line in aamode.py / validate_log_mode()
Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-02 18:45:41 +01:00
Steve Beattie
f05649e518 profiles: update make check-logprof for python tools
The check-logprof target was not updated to use the python tools, when
they were merged in. This patch fixes the issue.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-12-02 08:03:09 -08:00
Christian Boltz
c1ed3481e2 cleanup nscd profile
@{PROC}/@{pid}/maps r,
is part of abstractions/base - so there's no need to include it in the
nscd profile.

Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-01 23:44:13 +01:00
Christian Boltz
d82e9a3bec aamode.py - fix LOG_MODE_RE
LOG_MODE_RE (used in validate_log_mode() in aamode.py) just checked if
the given parameter contains one of the possible matches. This resulted
in "invalid" being a valid log mode (from audit.log requested_mask or
denied_mask) because it contains 'a', which is a valid file mode.

This patch wraps the regex into   ^(...)+$   to make sure the full
string contains only allowed file modes.

The patch also adds some tests for validate_log_mode().


Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-01 22:49:54 +01:00
Christian Boltz
8346ef0f77 delete unused profilemode() from aamode.py
Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-01 20:56:31 +01:00
Christian Boltz
e1da7759dd delete unused map_log_mode() in aamode.py
Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-01 20:55:13 +01:00
Pat Parson
94ebc95eb3 profiles: update usr.bin.passwd profile
Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=770788

Acked-by: Steve Beattie <steve@nxnw.org>
2014-12-01 10:23:45 -08:00
Christian Boltz
93ca0c2ff9 aa.py: change_profile vs. changes_profile
aa.py uses profile_data[profile][hat]['change_profile'] at various
places. However, there are also two places that use 'changes_profile'
(note the additional 's'), which should also be 'change_profile'.

Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-29 13:40:10 +01:00
Steve Beattie
ad17e03b9d utils: wrap ValueError in AppArmorBug w/better reporting
This patch converts a ValueError raised when parsing of a permission
mode fails into an AppArmorBug with better diagnostic information, and
adds a test case to confirm that the exception is raised.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-11-29 00:15:17 -08:00
Christian Boltz
b1c28c7a23 Add some tests for aa.py check_for_apparmor()
Also change check_for_apparmor() to allow easier testing by optionally
specifying alternative locations for /proc/filesystems and /proc/mounts
as parameter.

Note that the code in check_for_apparmor() differs from what the comment
says - valid_path() only does syntax checks, but doesn't check if the
directory exists. I added a comment saying exactly that.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-27 23:20:26 +01:00
Christian Boltz
ff5024d703 Improve performance in aamode.py (saving 10-17% time):
- replace MODE_MAP_RE regex with MODE_MAP_SET set
- change sub_str_to_mode() to use MODE_MAP_SET set instead of MODE_MAP_RE
- change split_log_mode to use split() instead of a regex

Patch by Peter Maloney <peter.maloney@brockmann-consult.de>


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

split_log_mode() change also
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-11-27 19:08:00 +01:00
Christian Boltz
a98426820b improve check_for_apparmor() for better readability and (minor)
performance improvement

Patch by Peter Maloney <peter.maloney@brockmann-consult.de>

Acked-by: Christian Boltz <apparmor@cboltz.de>
(previous patch version (with minor difference) also
 Acked-by: Seth Arnold <seth.arnold@canonical.com>)
2014-11-27 18:34:45 +01:00
Christian Boltz
c7626ec0eb Add tests for sub_str_to_mode() and split_log_mode() in aamode.py.
Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-27 13:54:22 +01:00
Christian Boltz
b6dd8bbb81 Fix the usage of the aa hasher in aa.py handle_children() - for
interpreters, it used
    aa[profile][hat]['path'][interpreter_path]['mode']
instead of
	aa[profile][hat]['allow']['path'][interpreter_path]['mode']

The ['allow'] part was missing.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-27 00:42:06 +01:00
Steve Beattie
8841086c01 utils: abstract out writing prior segments
This patch pulls out all the common processing for writing out
each of the prior segments that need to be written before writing
the current segment into a function called 'write_prior_segments',
reducing a bunch of ugly duplication.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-11-26 14:32:25 -08:00
Steve Beattie
a5d38d3dc9 utils: fix include prior segments indention
The assignment for setting segments['include'] = True was wrong,
it occured inside the 'if not segments['include'] and True in
segments.values():' block, whereas it needed to always get set outside
of that if test.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-11-26 14:28:21 -08:00
Christian Boltz
21b6e70865 fix some performance killer bugs in aa.py
This patch
- fixes a check that used if "aa[profile][hat][incname]:" instead of
  "if aa[profile][hat]['include'].get(incname, False):" ("['include']"
  was missing) which means the performance shortcut was never hit
- avoids auto-created empty and superfluous hashers in
  aa[profile][hat]['allow']['path'] and
  include[incfile][incfile][allow]['path']
- adds the filename to the "Can't find system log" exception

Patch by Peter Maloney <peter.maloney@brockmann-consult.de>


Changes compared to the original patch:
- change back quoting in the exception message to '...'


Acked-By: Christian Boltz <apparmor@cboltz.de>
2014-11-26 20:25:07 +01:00
Tyler Hicks
c7f5f55160 Update the top-level README for the utils rewrite
Modify the build instructions and project requirements to reflect the
utils rewrite from Perl to Python.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-11-18 10:27:56 -06:00
Tyler Hicks
c308e6b24e libapparmor: Make man page generation optional
This patch adds the --enable-man-pages option, defaulting to "yes", to
libapparmor's configure stage so that libapparmor can be built on
systems lacking Perl.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-17 21:20:14 -06:00
Tyler Hicks
806374b5f9 libapparmor: Fix spacing in the configure script usage
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-11-17 21:20:11 -06:00
Tyler Hicks
b57a229c56 libapparmor: Check for podchecker during configure stage
Fail the configure stage if podchecker is not available since man page
generation always happens.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-17 21:19:55 -06:00
Tyler Hicks
3c7621b511 libapparmor: Point to the correct site for downloading Perl
Point to the site for Perl the language and not Perl news.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-11-17 21:19:15 -06:00
Tyler Hicks
742adeeeb7 libapparmor: Don't print perl version in the configure script output
There's no need to date ourselves.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-11-17 21:19:13 -06:00
Tyler Hicks
d27d5f6ba2 libapparmor: Always generate the man pages
The configure script fails if pod2man isn't available since PROG_POD2MAN
is called unconditionally so it is safe to split man page generation out
of the --with-perl configure option.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-11-17 21:19:09 -06:00
Christian Boltz
534148d9aa fix filename for .../nscd/hosts (which was accidently changed to "host" 3 years ago)
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-11-18 00:27:10 +01:00
Steve Beattie
961ab6d6e0 utils: add support for alternate pyflakes versions
Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-11-17 12:32:30 -08:00
Christian Boltz
fc1489863d Allow the usage of /run/nscd/ for runtime files in the nscd profile.
References: https://bugzilla.novell.com/show_bug.cgi?id=904620#c14


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-11-17 20:18:29 +01:00
Kshitij Gupta
a3aee5ce33 The make check for utils was failing due to the raw_input being
present as a function (which it is not in Python3, even though it was
under an if else python version check).

The following patch:
- checks the __builtins__ module for existence of raw_input and sets
it up for Python3

Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-17 18:00:04 +05:30
Christian Boltz
5d148c4ac6 Fix leading whitespace in "(V)iew changes" and cleanup profile writing
The diff displayed by (V)iew changes in aa-logprof lacks leading
whitespace because it bases the whitespace on the indention level of the
closing "}".

Besides that, it uses different values for the indention level for newly
added rule types than for existing rule types. (For example, if a
profile already had a network rule, added network rules will get a
different indention level.) However you won't notice this because
currently it doesn't indent the rules at all ;-)

This patch fixes serialize_profile_from_old_profile() in aa.py so that
it always uses the correct indention level.


Also clean up and simplify how the profile is written in the end (when
matching RE_PROFILE_END) - we already have "write_methods", so we can
just re-use it instead of "manually" calling one write_* function after
the other. Unfortunately dicts don't keep their original order,
therefore I had to introduce "default_write_order".


Finally, add some missing rule types to "segments" to avoid key errors.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-15 12:51:24 +01:00
Christian Boltz
23da51b079 fix audit toggle for capability (when asking in logprof)
When aa-logprof asks for adding capability rules, it also offers the
Audi(t) option. Unfortunately, this option does nothing ;-)

This patch fixes ask_the_question() so that it really ;-) allows to
switch the audit flag on and off. It also initializes the "audit"
variable to make sure the next capability doesn't inherit the audit flag
used for the previous capability.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-15 01:38:29 +01:00
Christian Boltz
be287de823 fix and improve recursive_print()
This patch for recursive_print() in common.py fixes printing dicts with
py3. It also replaced the tabs() lambda function with a plain string,
and the brace() lambda function with a simple formatstring to make the
code easier to understand.

Also add support for nested lists - for the start and end of each list,
print a [ and ]. Without that, you get a long list of items without an
indicator if/when a new parent list starts.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-15 01:08:37 +01:00
Christian Boltz
3364eadafc Add "AppArmorBug" Exception (for things that "should never happen")
Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-14 23:52:38 +01:00
Christian Boltz
365d7036a5 fix "unknown capability: CAP_whatever" in aa-logprof
When aa-logprof asks for a capability, you'll see something like

    WARN: unknown capability: CAP_block_suspend

The reason for the warning and "Severity: unknown" is that severity.db
contains the capability names in uppercase, but ask_the_question() calls
sev_db.rank with the capability in lowercase.

This patch converts the "CAP_$capability" string to uppercase before
doing the lookup.

Acked-by: Steve Beattie <steve@nxnw.org>



Also add a testcase (written by Steve Beattie) to ensure this stays fixed.

Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-11-14 02:27:33 +01:00
Christian Boltz
422680714b utils/Makefile: remove superfluous grep -v from pyflakes call
utils/Makefile contains a grep -v "undefined name _". Some manual
testing shows that pyflakes doesn't print any warning about "_", so
this grep is superfluous.

Removing the grep also means we don't need a tempfile for the pyflakes
output anymore, which simplifies the pyflakes call a lot.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-14 02:21:23 +01:00
Steve Beattie
1a9505a4ef utils: fix pyflakes issues with test-severity
The recent re-work of the severity.db tests were not verified to
pyflakes clean. All but one of pyflakes co are of marginal impact
(assigning to a variable that isn't later referenced); however, one
legitimate issue it detected is that I inadvertently created two test
cases with the same method name, so only one test case would actually
be used.

The following patch fixes the issues.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-11-13 10:58:50 -08:00
Christian Boltz
4dd956461b Import regexes from apparmor.regex one by one (instead of *) to make
pyflakes happy

Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-13 19:17:10 +01:00
Tyler Hicks
4c30cb0e64 tests: Add ptrace tests for LP: #1390592
These regression tests are for an Ubuntu-specific bug. However, they
should benefit the upstream project, as well. Ubuntu took an incomplete
version of a patch, which introduced the bug. The version of that patch
that landed upstream did not contain the bug.

The bug was in policy compilation of certain combinations of rule types,
conditionals, and conditional values. The easiest such combination to
test is a rule such as:

  ptrace peer=ABC,

Buggy parsers will generate binary policy that causes the kernel to deny
a ptrace of a process confined by ABC, despite the presence of the above
rule.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-11-13 10:40:19 -06:00
Christian Boltz
e188f04ce4 Move the profile parsing regexes from aa.py to a new file (regex.py)
and add an "import" line so that they are still available in aa.py.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2014-11-12 00:05:04 +01:00