Commit graph

3198 commits

Author SHA1 Message Date
Steve Beattie
98c6087c54 regression tests: fix gcc-5 inline confusion
Parts of the regression tests that use the do_open() inline function
from changehat.h fail to build under gcc-5 like so:

  cc -g -O0 -Wall -Wstrict-prototypes    changeprofile.c  -lapparmor  -o changeprofile
  /tmp/ccT6GE6k.o: In function `main':
  /home/ubuntu/bzr/apparmor/tests/regression/apparmor/changeprofile.c:43: undefined reference to `do_open'
  collect2: error: ld returned 1 exit status
  <builtin>: recipe for target 'changeprofile' failed

This patch converts the do_open function declaration to be static
inline, which apparently keeps gcc-5 from getting confused.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-03-03 11:38:40 -08:00
Steve Beattie
fc3a7f49cf parser: net_find_af_name: do not assume that address families are consecutive,
remove unused net_find_af_val function, and network_families array

Merge fixes from Philip Withnall and Simon McVittie.
2015-03-03 11:33:34 -08:00
Christian Boltz
7262b71d47 move strip_quotes() from aa.py to regex.py
The upcoming function parse_profile_start() (which is a wrapper around
the updated RE_PROFILE_START, and will live in regex.py) needs
strip_profile(), but importing it from aa.py fails with an import loop.
Therefore this patch moves strip_quotes() from aa.py to regex.py and
re-imports it into aa.py.

As a bonus, the patch also adds some tests for strip_quotes() ;-)


Also add TestStripQuotes to the test_suite list because it won't run
otherwise.

Acked-by: Steve Beattie <steve@nxnw.org> for both trunk and 2.9
2015-03-03 20:15:00 +01:00
Christian Boltz
55a2809a5a aa.py: split off parse_profile_start() from parse_profile_data() and add tests
Move the code for parsing the profile start ("/foo {") from aa.py
parse_profile_data() to a separate function parse_profile_start().

Most of the changes are just moving around code, with some small
exceptions:
- instead of handing over profile_data to parse_profile_start() to
  modify it, it sets two variables (pps_set_profile and
  pps_set_hat_external) as part of its return value, which are then
  used in parse_profile_data() to set the flags in profile_data.
- existing_profiles[profile] = file   is executed later, which means
  it used the strip_quotes() version of profile now
- whitespace / tab level changes

The patch also adds some tests for the parse_profile_start() function.



Acked-by: Steve Beattie <steve@nxnw.org>
2015-03-02 21:12:12 +01:00
Christian Boltz
485fde8c50 split flags_bad5.sd parser test into multiple tests
flags_bad5.sd contains tests to ensure the debug flag is no longer
accepted.

However, the file contains multiple expected failures, which means that
it will still fail as long as at least one of them fails. This patch
splits each test into its own file to ensure each of them fails.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-03-02 19:56:07 +01:00
Christian Boltz
49bc4efa1e Add parser tests for empty flags (which result in "syntax error")
Acked-by: Steve Beattie <steve@nxnw.org>
2015-03-02 19:48:30 +01:00
Christian Boltz
c469b92afb Add some tests for aa.py get_profile_flags().
Also adds a check to get_profile_flags() to catch an invalid syntax:
    /foo (  ) {
was accepted by get_profile_flags, while
    /foo () {
failed.

When testing with the parser, both result in a syntax error, therefore
the patch makes sure it also fails in get_profile_flags().


Acked-by: Steve Beattie <steve@nxnw.org>
2015-03-02 19:36:20 +01:00
Tyler Hicks
54841a1986 parser: Fix "PDEBUG" redefined warning
Only present when building with DEBUG=1.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-03-02 09:50:17 -06:00
Tyler Hicks
4bb5fb6003 parser: Fix -Wformat-extra-args warning
Only present when building with DEBUG=1.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-03-02 09:50:14 -06:00
Tyler Hicks
6d1bcdf549 parser: Send PDEBUG() to stderr
PDEBUG() and PERROR() should both go to stderr.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-03-02 09:50:11 -06:00
Tyler Hicks
65b0048aae parser: Fix return value of dirat_for_each()
Seth pointed out that dirat_for_each() didn't correctly handle the
return value from readdir_r(). On error, it directly returns a positive
errno value. This would have resulted in that positive errno value being
returned, with an undefined errno value set, from dirat_for_each().
However, the dirat_for_each() documentation states that -1 is returned,
with errno set, on error.

This patch results in readdir_r()'s return value being handled
appropriately. In addition, it ensures that 0 is always returned on
success.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reported-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-03-02 09:50:07 -06:00
Christian Boltz
cec9b0d09f cleanup smbd profiles
The smbd profile contains /{,var/}run/cups/cups.sock rw, which is
covered by abstractions/cups-client and therefore superfluous.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-02-28 21:35:18 +01:00
Christian Boltz
0166960844 let logparser.py parse_event() change disconnected path events to 'ERROR'
This means that aa-logprof will ignore the event instead of crashing with
    AppArmorException: 'Unexpected rank input: var/run/nscd/passwd'

Note that I made the check as specific as possible to be sure it doesn't
hide other events.

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


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



Also update test-capability.py - it contains a test that needs
    'error_code': 0,
added to avoid a failure.

Patch by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2015-02-28 14:09:45 +01:00
Steve Beattie
d0304227e6 profiles: add geary email client to ubuntu-email abstraction
Merge from Cameron Norman <camerontnorman@gmail.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-02-27 23:24:11 -08:00
Felix Geyer
e2eebe08a8 profiles: allow aspell access to /usr/share/aspell/
From: Felix Geyer <debfx@ubuntu.com>

At least Debian/Ubuntu started shipping some aspell files in
/usr/share/aspell/.
For example:
/usr/share/aspell/iso-8859-1.cmap
/usr/share/aspell/iso-8859-1.cset

The abstraction should allow read access to these files.

Acked-by: Steve Beattie <steve@nxnw.org>
2015-02-27 23:14:03 -08:00
Steve Beattie
a3433dc170 profiles: add support for /etc/pki/ in ssl certs abstraction
These appear to be related to the update-ca-trust tool.

Thanks to Gregor Dschung.
2015-02-27 22:42:06 -08:00
Christian Boltz
4939f7ce14 cleanup aa-disable handling in tools.py
Remove the check if the disable directory exists. If it's really
missing, it will be auto-created by create_symlink(), so we
automagically fix things instead of annoying the user with an
error message ;-)

Acked-by: Steve Beattie <steve@nxnw.org> for both trunk and 2.9.
2015-02-28 00:24:11 +01:00
Philip Withnall
8782872fe2 Remove unused net_find_af_val function, and network_families array
Like net_find_af_name, this assumed that AF_* values were consecutive.

[smcv: split out from a larger patch, added commit message,
removed dead declaration]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-27 16:20:31 +00:00
Philip Withnall
097c520293 net_find_af_name: do not assume that address families are consecutive
The network_families array is automatically built from AF_NAMES, which is
extracted from the defines in <bits/socket.h>. The code assumes that
network_families is indexed by the AF defines. However, since the
defines are sparse, and the gaps in the array are not packed with
zeroes, the array is shorter than expected, and the indexing is wrong.

When this function was written, the network families that were
covered might well have been consecutive, but this is no longer true:
there's a gap between AF_LLC (26) and AF_CAN (29). In addition,
the code that parses <sys/socket.h> does not recognise AF_DECnet (12)
due to the lower-case letters, leading to a gap betwen AF_ROSE (11)
and AF_NETBEUI (13).

This assumption caused a crash in our testing while parsing the rule
"network raw".

[smcv: split out from a larger patch, added commit message]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-27 16:20:31 +00:00
Christian Boltz
c913956554 Fix the minitools (aa-audit, aa-complain, aa-enforce, aa-autodep)
to work with multiple profiles at once.

References: https://bugs.launchpad.net/apparmor/+bug/1378095

Acked-by: Steve Beattie <steve@nxnw.org> for trunk and 2.9.
2015-02-27 14:19:00 +01:00
Steve Beattie
35bbe528d2 parser: fix more gcc 5 compilation problems
Don't pass an ostream reference into another ostream via <<.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-02-26 14:55:13 -08:00
Christian Boltz
608f6493be delete traces of program-chunks directory from apparmor.d(5)
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2015-02-26 18:44:22 +01:00
Cameron Norman
4803eb7fa2 abstractions/ubuntu-email: add geary 2015-02-22 20:23:04 -08:00
Christian Boltz
064697e791 require logfile only for aa-logprof and aa-genprof
Make sure most tools (for example aa-complain) don't error out if
no logfile can be found. (For obvious reasons, aa-logprof and
aa-genprof will still require a logfile ;-)

This is done by moving code from the global area in aa.py to the new
function set_logfile(), which is called by aa-logprof and aa-genprof.

While on it,
- rename apparmor.filename to apparmor.logfile
- move the error handling for user-specified logfile from aa-genprof
  and aa-logprof to aa.py set_logfile()

Note: I'd have prefered to hand over the logfile as parameter to
do_logprof_pass(), but that would break last_audit_entry_time() in
aa-genprof which requires the log filename before do_logprof_pass()
is called.

References: https://bugs.launchpad.net/apparmor/+bug/1423702


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-02-20 21:36:55 +01:00
Seth Arnold
4ec29a7e29 This should fix a gcc 5 build failure (untested) with os << .. << os
This build failure was discovered by doko's archive rebuild:
http://people.ubuntuwire.org/~wgrant/rebuild-ftbfs-test/test-rebuild-20150202-gcc5-vivid.html
2015-02-12 13:20:57 -08:00
John Johansen
a0706d3a46 And the related patch to fix globbing for af_unix abstract names
Abstract af_unix socket names can contain a null character, however the
aare to pcre conversion explicitly disallows null characters because they
are not valid characters for pathnames. Fix this so that they type of
globbing is selectable.

this is a partial fix for

Bug: http://bugs.launchpad.net/bugs/1413410

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-02-12 10:19:16 -08:00
John Johansen
daa07671c7 Currently the parser does escape processing in multiple places, this can result in failures if not handled properly
The lexer front end currently incorrectly processes the \000 \x00 \d00 escape sequence resulting in a null character being embedded in the processed string, this results in the string not being full processed later.

The aare to pcre regex conversion fn also incorrectly strips out the \00, and any other escape sequence it doesn't know about, resulting in incorrect strings being passed to the backend. Fix this by passing through any valid escape sequence that is not handled by the fn.

this is a partial fix for
Bug: http://bugs.launchpad.net/bugs/1413410

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-02-12 10:17:44 -08:00
Tyler Hicks
236ed1cf3a tests: Update code to correctly use the terms context and label
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2015-02-09 18:46:51 -06:00
Tyler Hicks
011777f483 mod_apparmor: Update code to correctly use the terms context and label
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2015-02-09 18:46:49 -06:00
Tyler Hicks
98a71b5120 libapparmor: Update code to correctly use the terms context and label
Adjust the libapparmor function prototypes, variable names, and comments
that incorrectly used the name "con" when referring to the label.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2015-02-09 18:46:46 -06:00
Tyler Hicks
e08f940413 libapparmor: Document the terms context and label in aa_getcon(2)
The correct usage of the terms context and label is not clear in the
aa_getcon(2) man page. The aa_getcon(2) family of functions are also
prototyped incorrectly since the *con parameter represents a label and
not a context.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2015-02-09 18:46:42 -06:00
Christian Boltz
9d471cdd73 Update is_skippable_file() to match all extensions that are listed in
libapparmor _aa_is_blacklisted() - some extensions were missing in the
python code.

Also make the code more readable and add some testcases.

Notes:
- the original code additionally ignored *.swp. I didn't include that -
  *.swp looks like vim swap files which are also dot files
- the python code ignores README files, but the C code doesn't
  (do we need to add README in the C code?)


Acked-by: Kshitij Gupta <kgupta8592@gmail.com> for 2.9 and trunk
Acked-by: Steve Beattie <steve@nxnw.org>
2015-02-04 13:16:29 +01:00
Christian Boltz
68a19c4943 Raise an exception if sub_str_to_mode() is called with invalid mode
string or if a mode_char is not in MODE_HASH.

Also update the testcase for "asdf42" (which raises AppArmorBug now)
and add a test that simulates MODE_HASH and MODE_MAP_SET getting out
of sync (tests the second part of the if condition).


Acked-by: Steve Beattie <steve@nxnw.org>
2015-02-03 12:47:36 +01:00
Christian Boltz
5365e12dc9 Fix aa-unconfined to work with profile names that don't start with / or null
Reported by u on the debian pkg-apparmor-team ML.


Acked-by: John Johansen <john.johansen@canonical.com>
2015-02-02 20:52:07 +01:00
Gregor Dschung
f14150c594 added /etc/pki/trust to the ssl_certs-profile 2015-01-31 16:51:17 +01:00
Christian Boltz
9f1ba65471 rename _clean to pod_clean in Makefiles
Since the Makefile cleanup, the _clean target is only used to delete
manpages etc. generated from *.pod files.

This patch renames the _clean target to pod_clean to make it obvious
what it does.


Acked-by: John Johansen <john.johansen@canonical.com>
2015-01-30 22:15:53 +01:00
Christian Boltz
da8230fe95 remove superfluous/outdated comment about m / ix
For the records: the valid statement from the comment is:
    # m is not implied by ix


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2015-01-30 21:08:17 +01:00
John Johansen
03d7c37650 Currently the parser does escape processing in multiple places, this can result in failures if not handled properly
The lexer front end currently incorrectly processes the \000 \x00 \d00 escape sequence resulting in a null character being embedded in the processed string, this results in the string not being full processed later.

The aare to pcre regex conversion fn also incorrectly strips out the \00, and any other escape sequence it doesn't know about, resulting in incorrect strings being passed to the backend. Fix this by passing through any valid escape sequence that is not handled by the fn.

this is a partial fix for
Bug: http://bugs.launchpad.net/bugs/1413410

Signed-off-by: John Johansen <john.johansen@canonical.com>
2015-01-29 14:54:08 -08:00
Christian Boltz
3e74935279 move the DISTRO variable definition from common/Make.rules to
parser/Makefile (which is the only Makefile that uses the DISTRO
variable)

Acked-by: Steve Beattie <steve@nxnw.org>
2015-01-28 22:44:35 +01:00
Christian Boltz
70efe0cb53 delete superfluous 'dist_clean' target from parser/Makefile
'dist_clean' deletes files that are already deleted by 'clean', which
means it's superfluous.


Acked-by: Steve Beattie <steve@nxnw.org>
2015-01-28 22:40:00 +01:00
Steve Beattie
a157966205 libapparmor: more Makefile cleanups
Get rid of the relics in libapparmor's Makefile.am for generating
tarballs from svn, which is no longer relevant. Also clean generated
manpages during make clean rather than just make maintainer-clean.
2015-01-26 15:39:10 -08:00
Steve Beattie
109c7c625f common: more Make.rules cruft removal
This patch removes a bunch of the per-directory tarball and rpm
generation cruft that is no longer needed now that we've been
distributing a unified tarball in our releases.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2015-01-23 16:01:14 -08:00
Steve Beattie
f19eb31f23 Entire tree: makefile cruft removal
- drop the symlink magic of the common/ directory, and just include
  files directly from there.
- update comments indicating required steps to take when including
  common/Make.rules
- drop make clean steps that refer to no longer generated tarballs,
  specfiles, and symlinks to the common directory/Make.rules.
- don't silence clean steps if VERBOSE is set

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian "Ghostbuster" Boltz <apparmor@cboltz.de>
2015-01-23 15:52:09 -08:00
Christian Boltz
0da2be8432 Add a "common_Make.rules_is_a_bad_target" target to common/Make.rules to
make sure nothing accidently hits the first-best target (well,
first-not-so-good would better describe the rpm target ;-)

Also add a dummy "all:" target to the toplevel Makefile with a short
hint towards README.

(see "[patch] fun with the toplevel Makefile") on the ML for the fun
that lead to this patch)


Acked-by: Steve Beattie <steve@nxnw.org>
2015-01-23 20:40:40 +01:00
Jamie Strandboge
024e7ddf41 Description: Allow writes to /{,var}/run/systemd/journal/dev-log, the systemd
journal socket. On Debian and Ubuntu systems, /dev/log is a symlink to
 /run/systemd/journal/dev-log, so this access is now required in the base
 abstraction to maintain current behavior.
Bug: https://bugs.launchpad.net/apparmor/+bug/1413232

Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2015-01-21 13:30:46 -06:00
Christian Boltz
bb11ad3551 Add some tests for logparser.py based on the log lines from
https://bugs.launchpad.net/apparmor/+bug/1399027

Also move some existing tests from aa_test.py to test-logparser.py and
adds checks for RE_LOG_v2_6_audit and RE_LOG_v2_6_syslog to them.


Acked-by: Steve Beattie <steve@nxnw.org> for trunk and 2.9
2015-01-18 14:55:15 +01:00
Christian Boltz
d30cdf06e4 update logparser.py to support the changed syslog format by adding
(audit:\s+)?   to RE_LOG_v2_6_syslog

References: https://bugs.launchpad.net/apparmor/+bug/1399027


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2015-01-17 11:04:12 +01:00
Christian Boltz
60b05ab1b9 rule class - split out common parts from is_covered()
Split is_covered() in capability.py into
- is_covered_localparts() for rule-specific code
- is_covered() for common code - located in __init__.py

The object type comparison now uses type(self) and a slightly different
error message to make it usable everywhere.

Also rename rule_obj to other_rule which is more self-explaining
(inspired by the parameter name in the is_covered() dummy in __init__.py).


v2:
- remove check_allow_deny and check_audit parameters from
  is_covered_localvars()


Acked-by: Steve Beattie <steve@nxnw.org>
2015-01-16 14:59:49 +01:00
Christian Boltz
7085b53583 let make coverage fail if one of the tests fail
If one of the testcases fail, this goes unnoticed in "make coverage".
This patch changes the Makefile so that test failures let
"make coverage" fail.

You can use   make COVERAGE_IGNORE_FAILURES=true coverage   to build
coverage data even if some tests fail.

Signed-off-by: Steve Beattie <steve@nxnw.org>
(which was most probably meant as an Acked-by)

Also Acked-by: <timeout> ;-)
2015-01-16 14:45:16 +01:00
Steve Beattie
28450b432e utils: fix python install for rule/ subdirectory
For reasons that are unclear, python's setuptools doesn't install
recursively from a directory, meaning that on make install, the new
Rules/Ruleset classes were not being installed. This patch causes
the rule subdirectory to be included.

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

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2015-01-13 13:03:11 -08:00