Commit graph

2709 commits

Author SHA1 Message Date
Steve Beattie
d318ff6100 Fix up last pyflakes issues with tools 2014-02-13 08:24:02 -08:00
Steve Beattie
15a95e3b36 Fix up some more pyflakes issues with the tools 2014-02-13 08:20:59 -08:00
Steve Beattie
bf655b530f Fix make install to handle new python binaries, as well as informing
setuptools to install the entire apparmor python package.
2014-02-13 00:04:39 -08:00
Steve Beattie
e9db24ac23 Add support for better integration of external apparmor modules (e.g.
appamror-click), see http://www.python.org/dev/peps/pep-0402/ for details.
2014-02-12 23:32:25 -08:00
Steve Beattie
32e0931588 Fix up execute permissions that were lost in the merger for some reason. 2014-02-12 16:59:27 -08:00
Steve Beattie
f989dd0132 Merge in Kshitij Gupta <kgupta8592@gmail.com>'s rewrite of the
logprof/genprof and related utilities in python. Because the branch that
was worked on was not based on the apparmor tree, not all of the history
can be maintained for files that are not newly created or entirely
rewritten in the branch.

(This merge also includes a subsequent commit to the branch
I was merging from which includes my missed bzr add of
utils/apparmor/translations.py)
2014-02-12 15:54:00 -08:00
Steve Beattie
b3b4fd448e Reorganize layout to ease merger into upstream apparmor-utils tree. 2014-02-12 13:27:30 -08:00
Steve Beattie
c1c0eab113 Merge trunk change. 2014-02-12 13:05:03 -08:00
Jamie Strandboge
46f5f51909 add support for python3.2 and python3.4 to the python abstraction
Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-02-12 14:42:39 -06:00
Steve Beattie
975e389f1d Move over the perl apparmor modules (Immunix) as well as some other
perl utilities to the deprecated to directory; a couple of perl
utilities remain, but they are still useful and do not depend on the
Immunix module (just the LibAppArmor perl module).
2014-02-12 10:27:44 -08:00
Steve Beattie
c43d4eaa93 Move perl applications that were reimplemented in python by Kshitij
Gupta to the deprecated directory.
2014-02-12 09:59:23 -08:00
Steve Beattie
d27752350a Simplify the work tools and modules need to do to get the shared
translations. External utilities can still use their own textdomains
if they have strings that are not part of the apparmor-utils catalog.
2014-02-11 16:23:21 -08:00
Steve Beattie
4987e5b158 Clean up a bunch of pep8 warnings, as found by running:
pep8 --ignore=E501,E302

on individual files. This uncovered a bug where the type of an object
was being compared to a type of a list. However, a python string is a
list of characters, and so would cause the test to be true.
2014-02-10 22:20:36 -08:00
Steve Beattie
0525932561 Get rid of the globbing imports, which allows pyflakes to do a better
job. Clean up a bunch of pyflakes complaints. Doing so uncovered
references to apparmor/yasti.py functions in aa.py that hadn't been
imported.
2014-02-10 22:17:21 -08:00
Steve Beattie
35e1936202 Convert to using python's modular translations interface. This allows
the utility python modules to be used inside another tool with another
textdomain binding and still have the translations for that tool and the
stuff internal to the apparmor module convert properly.
2014-02-10 22:15:05 -08:00
Steve Beattie
395c429cb1 Delete empty file 2014-02-10 22:14:54 -08:00
Jamie Strandboge
4b01cb2544 Move os.chdir(old_cwd) to before the aa-exec call it remove the side-effect of
the chdir to $HOME when using Xpra.

Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-02-06 15:15:48 -05:00
Jamie Strandboge
0c5d6f4660 add ubuntu-unity7-* abstractions for Ubuntu desktop users 2014-02-05 23:44:04 -05:00
Tyler Hicks
4b950117f9 parser: Quiet search dir valgrind warning and remove suppression
When passing an include directory on the command line to
apparmor_parser, valgrind emits a warning:

 Invalid read of size 4
    at 0x404DA6: add_search_dir(char const*) (parser_include.c:152)
    by 0x40BB37: process_arg(int, char*) (parser_main.c:457)
    by 0x403D43: main (parser_main.c:590)
  Address 0x572207c is 28 bytes inside a block of size 29 alloc'd
    at 0x4C2A420: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x53E31C9: strdup (strdup.c:42)
    by 0x404D94: add_search_dir(char const*) (parser_include.c:145)
    by 0x40BB37: process_arg(int, char*) (parser_main.c:457)
    by 0x403D43: main (parser_main.c:590)

This patch quiets the warning by removing strlen() calls on the t char
array. Instead, it only calls strlen() on the dir char array. t is a
dupe of dir and strlen(dir) does not trigger the valgrind warning.

Additionally, this patch adds a bit of defensive programming to the
while loop to ensure that index into the t array is never negative.

Finally, the valgrind suppression is removed from valgrind_simple.py.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-02-05 15:17:32 -05:00
Steve Beattie
0d613279ba parser: remove one valgrind suppression from test script
With commit 2364 addressing one of valgrind's false positives, we can
remove the related valgrind suppression entry from the test script.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-02-05 10:58:03 -08:00
Tyler Hicks
2001fb6f81 parser: Quiet valgrind false positive
strlen() assumes that it can read an entire word but when a char array
does not end on a word boundary, it reads past the end of the array.
This results in the following valgrind warning:

 Invalid read of size 4
    at 0x40A162: yylex() (parser_lex.l:277)
    by 0x40FA14: yyparse() (parser_yacc.c:1487)
    by 0x40C5B9: process_profile(int, char const*) (parser_main.c:1003)
    by 0x404074: main (parser_main.c:1340)
  Address 0x578d870 is 16 bytes inside a block of size 18 alloc'd
    at 0x4C2A420: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x53E31C9: strdup (strdup.c:42)
    by 0x40A145: yylex() (parser_lex.l:276)
    by 0x40FA14: yyparse() (parser_yacc.c:1487)
    by 0x40C5B9: process_profile(int, char const*) (parser_main.c:1003)
    by 0x404074: main (parser_main.c:1340)

This patch quiets the warning by not using strlen(). This can be done
because yyleng already contains the length of string.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-02-05 13:39:24 -05:00
John Johansen
5df1ac3610 Move short_options next to long_options to make them easier to keep in sync
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-02-05 09:10:53 -05:00
Steve Beattie
0a8e97098d parser: fix --cache-loc short arg option (-L)
When the --cache-loc option was added in trunk commit 1916, it was
intended that -L would be the short form of the option (based on
documentation and usage changes). However, the commit mistakenly
did not include the short option in the list include in the call
to getopt_long(3). This patch adds it along with the indicator
that it requires an argument (the different cache location) to the
getopt_long() call.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-02-04 14:28:21 -08:00
John Johansen
572fe066da The preprocessing output is broken, in a couple of places
includes come out like

  #include 

  ##included <tunables/home>

which is wrong because #include by itself is broken, and since -p is
supposed to be removing includes, it should not be directly echoed

any keyword in the keyword table is double echoed

  ownerowner /{run,dev}/shm/pulse-shm* rwk


Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-02-02 19:23:10 -10:00
Christian Boltz
19038d063b /usr/lib/dovecot/auth reads the mysql config files, which is not covered by
abstractions/mysql.

This binary/profile seems to be the only one that needs to do this, so 
add it to this profile (instead of abstractions/mysql) to avoid superfluous
permissions for other programs with abstractions/mysql

Acked-by: John Johansen <john.johansen@canonical.com>
2014-02-02 15:16:25 +01:00
Christian Boltz
a38ce71813 update usr.bin.dovecot profile
after testing the dovecot profiles on a new server, I noticed 
/usr/sbin/dovecot needs some more permissions:
- mysql access
- execution permissions for /usr/lib/dovecot/dict and lmtp
- write access to some postfix sockets, used to
  - provide SMTP Auth via dovecot
  - deliver mails to dovecot via LMTP 
- and read access to /proc/filesystems

Acked-by: John Johansen <john.johansen@canonical.com>
2014-02-02 15:13:51 +01:00
Christian Boltz
8b802b3fe6 update logprof.conf for UsrMove
logprof.conf contains a list of binaries in the [qualifiers] section 
that should for example never have their own profile.

Since some distributions moved lots of files from /bin/ to /usr/bin/ 
("UsrMove"), this list is outdated.

The patch adds copies of all /bin/ (and /sbin/) lines with /usr 
prepended.

Acked-by: John Johansen <john.johansen@canonical.com>
2014-02-02 15:12:32 +01:00
Kshitij Gupta
1126e1f8d7 Fixed the sample --trace feature. Opinions on using it? and should it be implemented in every tool separately? 2014-02-01 07:04:08 +05:30
Kshitij Gupta
21d1c4572d 2014-02-01 06:32:20 +05:30
Kshitij Gupta
c82fda86b6 Some bugfixes for UIYesNo to deny invalid keys, fix autodep when creating new profiles 2014-02-01 06:14:05 +05:30
Christian Boltz
bdaf2592e8 apparmor.vim says "attach_disconnect" is correct, but the parser only
likes "attach_disconnected".

Acked-By: Jamie Strandboge <jamie@canonical.com>
2014-01-29 23:16:36 +01:00
Christian Boltz
0fa4676d30 [3/3] dovecot profiles: update usr.sbin.dovecot profile for dovecot 2.x
The usr.sbin.dovecot profile needs several updates for dovecot 2.x, 
including
- capability dac_override and kill
- Px for various binaries in /usr/lib/dovecot/

The patch also adds a nice copyright header (I hope I got the bzr log 
right ;-)


Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-26 22:48:02 +01:00
Christian Boltz
df94a355fc [2/3] dovecot profiles: add profiles for new dovecot 2.x binaries
dovecot 2.x comes with several new binaries in /usr/lib/dovecot. 
This patch adds profiles for

/usr/lib/dovecot/anvil 
/usr/lib/dovecot/auth 
/usr/lib/dovecot/config 
/usr/lib/dovecot/dict 
/usr/lib/dovecot/dovecot-lda 
/usr/lib/dovecot/lmtp 
/usr/lib/dovecot/log 
/usr/lib/dovecot/managesieve 
/usr/lib/dovecot/ssl-params

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


Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-26 22:46:51 +01:00
Christian Boltz
86ed060f25 [1/3] dovecot profiles: introduce tunables/dovecot
Introduces tunables/dovecot (with @{DOVECOT_MAILSTORE}) and replace 
the mail storage location in various dovecot-related profiles with 
this variable.

Also add nice copyright headers (I hope I got the bzr log right ;-)


Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-26 22:43:42 +01:00
Felix Geyer
6733da5fcd nameservice abstraction: read permission to avahi socket
From: Felix Geyer <debfx@ubuntu.com>

AppArmor requires read and write permission to connect to
unix domain sockets but the nameservice abstraction only
grants write access to the avahi socket.
As a result mdns name resolution fails.

Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-26 12:16:54 -08:00
Steve Beattie
cb679f3206 add keyword 'other' vim syntax support, plus language parsing tests
Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 11:17:23 -08:00
Steve Beattie
9bb81e1ed3 parser: add rttime rlimit support
This patch adds support for the rttime rlimit (aka RLIMIT_RTTIME),
available since the 2.6.25 kernel, according to the getrlimit(2)
man page; see that man page for more details on this rlimit.
An acceptance test is also added, as well as an update to the
apparmor.vim input template.

While reviewing to see what made sense in apparmor.vim for the rttime
rlimit, I discovered that RLIMIT_RTTIME's units are microseconds, not
seconds like RLIMIT_CPU (according to the setrlimit(2) manpage). This
necessitated not sharing the case switch with RLIMIT_CPU. I didn't add
a keyword for microseconds, but I did for milliseconds. I also don't
accept any unit larger than minutes, as it didn't seem appropriate
(and even minutes felt... gratuitous). I would appreciate feedback
on what keywords would be useful here.

Patch History:
  v1: initial submission
  v2: - add apparmor.vim support for rttime keyword
      - adjust RLIMIT_TIME value assignment due to its units being
	microseconds, not seconds, and add milliseconds keyword.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 11:06:31 -08:00
Steve Beattie
f65368068f regression tests: minor dbus compilation cleanups
This patch replaces explicitly named output targets with the make
variable $@ as well as an instance where dbus_common.h was being added
to the compile command line due to the use of $^ rather than $<.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 11:03:22 -08:00
Steve Beattie
1fd3b5ed5a parser: close file handle left opened
Close file handle left opened if parser.cfg is found and read from.
Found by cppcheck.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 10:59:30 -08:00
Steve Beattie
fb3baeaf23 parser: fix memory leak on calloc() failure
Fix leaked memory if calloc() fails. Found by cppcheck.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 10:58:06 -08:00
Steve Beattie
8237c6fb28 parser: simplify handling of default matching patterns
Seth Arnold noticed an ugly string.clear(); convert_entry(string,
NULL) pattern occurred frequently following the conversion to using
std::string. This patch replaces that by using a static pointer to
a constant string matching pattern, and also converts other uses of
that pattern. It also adds a function wrapper that will clear the
passed buffer before calling convert_entry().

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 10:47:42 -08:00
Steve Beattie
d4c8971b65 parser: pull forward free() calls
As noted by Seth Arnold, in expand_by_alternations() if our set
variable has at least one value, then we're going to rewrite the entry,
so rather than sprinkle the free()s near where the reallocation occurs,
use one free() once we're guaranteed to need to do so.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 10:45:48 -08:00
Steve Beattie
78fe398a2f parser: replace reverse iterator
As suggested by Seth Arnold, we can use string::find_last_not_of()
instead of using C++'s hideous reverse iterators.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 10:30:08 -08:00
Steve Beattie
39564bbdf5 parser: remove unneeded e_buffer_overflow
As noted by Seth Arnold, e_buffer_overflow is no longer set in
convert_aaregex_to_pcre(), so remove it and the sole check for it.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 10:27:58 -08:00
Steve Beattie
6e701f798f parser: remove static sized buffer in process_dbus_entry()
This patch converts a stack allocated buffer into an std::ostringstream
object. The stringstream interface for specifying the equivalent of
a printf %02x conversion is a bit of an awkward construction, however.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 10:25:47 -08:00
Steve Beattie
5f18a7c237 parser: remove unneeded vars/allocations in regex unit tests
Based on feedback from Seth Arnold, the convert_aaregex_to_pcre()'s
first argument is const char *, and thus the unit test macros don't need
to pass a copy of the input string to it, as it's guaranteed to be
unmodified by the function.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 10:21:30 -08:00
Steve Beattie
fdd89f1da5 parser: eliminate bison warning
This patch eliminates the bison warning about "%name-prefix =" being
deprecated.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-24 10:19:59 -08:00
Steve Beattie
52b3458972 mod_apparmor: include errno in log messages for failures
This patch includes the errno in the log messages generated by two
different failed aa_change_hat() calls and the failure to open
/dev/urandom to get the random token, to further ease failure
diagnosis.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-23 14:50:07 -08:00
Steve Beattie
016e1f1b19 mod_apparmor: eliminate unnecessary back out aa_change_hat() calls
This patch removes unnecessary back out aa_change_hat() calls that occur
if the prior call to aa_change_hat() call failed. It used to be case
that an aa_change_hat() call that failed would result in the task being
placed in a profile with no permissions except the ability to
aa_change_hat() back out, but this behavior has been removed from
apparmor for many, many years now.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-23 14:44:24 -08:00
Steve Beattie
6fd2f36bd8 mod_apparmor: add logging for AAHatName/AADefaultHatName policy misconfig
This patch adds code that checks the resulting hat that apache gets
placed into, and verifies that if the apache configuration specified
that an AAHatName or AADefaultHatName should have been the resulting
hat. If it wasn't, emit a warning message to the apache log, as this
likely indicates a mismatch between the apache configuration and its
apparmor policy (i.e. why define AAHatName if you aren't going to
create the corresponding hat in the apparmor policy?)

Note for AADefaultHatName, a message is not logged if a defined
AAHatName would also apply or if there is a hat defined for the uri,
as each of those come first in the order of attempted hats.

Also note that the way the hat name is manually calculated will break
for nested profiles and stacking. It should be fine for all current
deployments as we don't allow nesting beyond the first subprofile level
in policy yet. And stacking will likely only be used between namespaces
where aa_getcon() will not report parent namespace info. However, when
libapparmor adds functionality to query the hatname, the code that
computes it here should be replaced by a call to that library function.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2014-01-23 14:42:00 -08:00