Commit graph

3045 commits

Author SHA1 Message Date
Christian Boltz
31a57bdfa9 update the aa-mergeprof manpage to match the new commandline syntax
introduced with the aa-mergeprof patch collection.

Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-16 20:26:45 +02:00
Christian Boltz
4f4eded593 aa-mergeprof: don't ask for includes that are already there
Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-16 20:22:52 +02:00
Christian Boltz
4f9183b23e aa-mergeprof cmdline changes, disable 3-way-merge for now
This is the rebased version of the patch by
Kshitij Gupta <kgupta8592@gmail.com>


(mostly) original patch description:

Changes to facilitate 2-way merge (maybe also 3-way) of multiple
profiles as discussed on IRC

This patch
- moves reset method to reset_aa function
- modifies message displayed to user
- allows processing of multiple files in 2-way merge
- disables 3-way merge till new syntax has been decided

The changes reflect the approach of providing arbitrary number of
files using wildcards or explicitly.

The changes map the profiles in the given files to their respective
files in the local directory specified using -d. Then the merges take
place profile-wise.


Acked-by: Steve Beattie <steve@nxnw.org>.
2014-10-16 20:06:45 +02:00
Christian Boltz
3cb61c5dae highlight comments in alias and link rules with correct color
(in blue, instead of the color used for the rule itsself)

Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-14 21:36:41 +02:00
Christian Boltz
c613d8a884 fix "list index out of range" when allowing inet rules
When adding inet rules in aa-logprof, it crashes with
    IndexError: list index out of range

The reason is that it doesn't display the options if only the raw rule
is available (aka "no abstraction").

This patch checks if options[] is set and otherwise sets selection to
the raw rule.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-14 21:28:32 +02:00
Christian Boltz
d11055aa0c Fix "Invalid mode found: /usr/lib64/firefox/firefox.sh"
After several hours of debugging on IRC and flooding paste.opensuse.org ;-)
I finally found the reason - reading(!) from log_dict with a wrong 
key caused the creation of that strange mode in log_dict.keys().

While finding that bug was very hard, the fix is easy - just replace 
"profile" with "aamode". (That probably makes one char per hour of 
debugging...)

To improve that ratio, also add a warning to common.py so that this 
interesting[tm] behaviour of hasher() is at least documented.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-14 12:54:39 +02:00
Christian Boltz
7e84f4efe9 If a filename mentioned in audit.log contains an @, aa-logprof crashes with
...
  File "/home/cb/apparmor/HEAD-CLEAN/utils/apparmor/severity.py", line 147, in handle_variable_rank
      variable = regex_variable.search(resource).groups()[0]
	  AttributeError: 'NoneType' object has no attribute 'groups'

handle_variable_rank() checked with   if '@' in resource:
and if it finds it, expects it can match a variable, which means   @{.....}
If a filename contains a   @   this fails.

The patch fixes the if condition so that it does a regex match.

It also adds two testcases for filenames containing @ to make sure they
don't cause a crash and result in the exptected severity rank.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-14 12:50:20 +02:00
Christian Boltz
9a960a22a9 prevent adding multiple quotes in file rules
aa-cleanprof (and others?) duplicate quotes in file rules.

If a profile contains
      "/bin/foo bar" mrix,
and I run aa-cleanprof on it several times, I end up with
   """"""/bin/foo bar"""""" mrix,

This patch calls strip_quotes on the pathname.
(If needed, the quotes are re-added when writing the profile - tested 
with aa-cleanprof.)

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


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2014-10-11 23:30:46 +02:00
Christian Boltz
7ef2ae9b05 Prevent encoding errors when reading a file
This patch changes open_file_read() and open_file_write() to use 
errors='surrogateescape' (with fallback to 'replace' for py2).

This avoids a crash when reading a logfile with special characters that 
are not utf8-encoded (for example a latin1 "ö"), and also avoids crashes 
at several other places we don't know yet ;-)

The patch also changes open_file_read() and open_file_write() to wrapper
functions, and moves the "real" code to the new open_file_anymode() 
function.

Also, I removed the try/except - it's superfluous because it throws the 
exception without any modifications.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2014-10-10 20:35:32 +02:00
Steve Beattie
a4685bebf3 Update version in preparation for apparmor 2.9.beta5 release. 2014-10-09 15:14:26 -07:00
Jamie Strandboge
e08c45a65f Description: also allow /var/mail in user-mail
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1192965

Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-09 15:48:37 -05:00
Jamie Strandboge
d9cc289022 ubuntu-browsers.d/java: update to allow /run/user/*/icedteaplugin-*
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1293439

Acked-By: Jamie Strandboge <jamie@canonical.com>
2014-10-09 14:56:34 -05:00
Steve Beattie
ada96afd84 mod_apparmor: revert apache 2.4 api fix from commit 2555
This patch reverts commit 2131 which added support for the newer apache
2.4 ap_hook_check_access_ex() api, based on a report from Christian that
it broke apache's simple authentication.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-10-09 12:52:31 -07:00
Steve Beattie
29f1b9ec7f tests: warn about xpass/xfail marked tests
With the two recent unix socket test patches to mark dgram tests as
failing but expected to pass, I realized that there's no indication
in the output that there are current expected failures (except for
the single corefile test expected failure)[0]. This patch attempts to
remedy that by emitting the x-type plus the test description for each
test that is marked as such. I've set it to always emit these results.

[0] The test infrastructure does give an alert if there is a test that
    has been marked xpass or xfail but has started behaving correctly.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-10-09 12:30:34 -07:00
Steve Beattie
5fee046bfe tests: mark failing dgram tests in unix_socket_unnamed.sh as xpass
It's not been tracked down in
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1373172 why
this is happening, but the current unnamed unix socket dgram tests
are failing when only the server is confined, and the peer label is
given as only the confining profile (the stream and seqpacket dgram
tests/permissions don't seem to trigger this revalidation rejection).

Until this bug is diagnosed and addressed, mark these tests as failing
but expected to pass (i.e. 'xpass').

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-10-09 12:27:51 -07:00
Steve Beattie
dcb39f494c tests: mark failing dgram tests in unix_socket_pathname.sh as xpass
With the addition of the unix socket mediation and
corresponding tests, there are currently two tests that fail
in unix_socket_pathname.sh. These have been recorded as bugs
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1373174 and
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1373176 but John
has not had time to investigate if these are legitimate bugs. The
following patch marks the tests as expecting to pass but currently
failing.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-10-08 22:32:01 -07:00
John Johansen
c2b8a72317 disable downgrade and not enforced rule messages by default
Currently the apparmor parser warns about rules that are not enforced or
downgraded. This is a problem for distros that are not carrying the out of
tree kernel patches, as most profile loads result in warnings.

Change the behavior to not output a message unless a warn flag is passed.
This patch adds 2 different warn flags
  --warn rule-downgraded    	 # warn if a rule is downgraded
  --warn rule-not-enforced	   # warn if a rule is not enforced at all

If the warnings are desired by default the flags can be set in the
parser.conf file.

v2 of patch
- update man page
- add --warn to usage statement
- make --quiet clear warn flags

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-08 13:20:20 -07:00
Jamie Strandboge
dc9474fe5a Description: update base abstraction read access to
/proc/sys/kernel/cap_last_cap. This is needed to determine the highest valid
 capability of the running kernel. Reference:
 https://lkml.org/lkml/2011/10/15/42
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1378977

Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-10-08 15:18:34 -05:00
Kshitij Gupta
b34e81e606 utils: Allow Perl utils to store and write back unsupported rules
This patch:
- allows the unsupported rules to be stored when parsing profiles
- writes all the unsupported rules back to profile

Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-10-09 01:42:33 +05:30
Kshitij Gupta
8bc6a176f6 Fix: fix aa-genprof to use new PromptQuestion class
The following patch:
- ensures aa-genprof also uses class based prompt

Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-10-09 01:37:18 +05:30
Jamie Strandboge
de9fcf1def Description: update freedesktop.org for new location of mimeapps.list
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/1377140

Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-10-08 14:32:11 -05:00
Steve Beattie
1e437a3cd8 utils: fix missed conversion in move to more class based approach
Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
2014-10-08 11:05:01 -07:00
Steve Beattie
22af3ba507 utils: fix typo in apparmor/aa.py
Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-10-08 10:41:31 -07:00
Christian Boltz
e70f8f2f78 remove duplicated "dbus" from "unsupported rule types" regex
(introduced in my previous patch)

Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-10-08 18:46:09 +02:00
Christian Boltz
f1c86e2486 Convert RE_PROFILE_BARE_FILE_ENTRY and the code using it to named
match groups. 

Also split out RE_OWNER that matches the "owner" keyword.

To make the code easier to understand, I dropped the existing audit
variable and instead directly query the "new" audit variable while 
filling path_rule['audit'].


Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-08 12:31:56 +02:00
Christian Boltz
3b5bede154 AppArmor.pm: add basic support for signal, unix, ptrace and dbus rules
YaST still uses AppArmor.pm, and now errors out when starting the 
profile editor because it doesn't know about signal, unix, ptrace and 
dbus rules.

This patch adds basic support for those rules to AppArmor.pm by adding 
them to the "ignore those rules" regex.

Note: Rules covered by this regex are lost when writing the profile
therefore the patch adds a comment to at least make this a "known bug".

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


Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-07 22:27:58 +02:00
John Johansen
44d2e9dacf fix: auditing of capabilities
BugLink: http://bugs.launchpad.net/bugs/1378091

The audit flags are not being set correctly by the parser so that

  audit capability XXX,

will not result in an audit message being logged when the capability
is used.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-07 12:50:23 -07:00
Kshitij Gupta
52cd4835e2 Refractor prompts in utils.
The following patch:
- creates a class for prompt questions moving away from Perl hash hack
for the purpose.
- moves some functions to the methods for that class
- fix options being incorrectly passed to questionPrompt in aa-mergeprof

Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-10-07 18:36:01 +05:30
Jamie Strandboge
6c5efcc5ea Update gnome abstraction to allow unix connections to dbus-vfs-daemon abstract
socket. Note, DBus mediation is still in effect so rules still need to be added
for accessing the DBus API (LP: #1375067)


Acked-By: Jamie Strandboge <jamie@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-10-06 14:06:23 -05:00
Christian Boltz
d00f01d0a8 ntpd on openSUSE Factory needs another location for the pid file.
References: https://bugzilla.novell.com/show_bug.cgi?id=899746


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-10-06 19:57:46 +02:00
Christian Boltz
ed1e2f3321 fix utils/test/runtests-py*.sh exitcode
utils/test/runtests-py*.sh always exits with $? = 1 even if there is no 
error. This is caused by the last executed command, test -n

This patch changes it to test -z so that we'll get $? = 0 if all tests 
succeed.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-10-03 11:48:21 +02:00
Steve Beattie
a44b6ce0a2 C tools: rename __unused macro to unused
Bug: https://bugzilla.novell.com/show_bug.cgi?id=895495

We define the __unused macro as a shortcut for __attribute__((unused))
to quiet compiler warnings for functions where an argument is unused,
for whatever reason. However, on 64 bit architectures, older glibc's
bits/stat.h header defines an array variable with the name __unused
that collides with our macro and causes the parser to fail to build,
because the resulting macro expansion generates invalid C code.

This commit fixes the issue by removing the __unused macro where it's
not needed (mod_apparmor) and renaming it to 'unused' elsewhere. It also
in some instances reorders the arguments so that the unused macro
appears last consistently.

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
2014-10-02 12:58:54 -07:00
Steve Beattie
ce70c84f5c X abstraction: adjust for LightDM xauthority location
Bug: https://bugs.launchpad.net/bugs/1339727

LightDM keeps moving the location where it stores xauthority files for
users, when configured to store them in a system directory (e.g. with

  [LightDM]
  user-authority-in-system-dir=true

set in a lightdm configuration file).

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: Christian Boltz <apparmor@cboltz.de>
2014-10-02 11:06:05 -07:00
John Johansen
655b1534e7 Parser: fix error when using regex profile names in IPC rules
BugLink: http://bugs.launchpad.net/bugs/1373085

The parser fails to accept certain characters, even when escaped
or quoted as part of the profile or label name in ipc rules. This
is due to the lexer not accepting those characters as part of the
input pattern.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-01 15:54:30 -07:00
Christian Boltz
95994ed64a convert RE_PROFILE_CAP in aa.py and the code using it to named match groups
(capability is one of the easiest rule types, so it's good as a start.)

The patch also adds basic support for rules containing more than one 
capability, like
    capability chown dac_override,
Note that this is just a pass-through mode (instead of complaining about 
an invalid line). aa-logprof will happily add another "capability chown" 
if it hits a log entry for it. (But: we never got a bugreport about not 
supporting multi-capability lines, so I guess they are rarely used ;-)

I also added a parse_audit_allow() function to handle the audit and 
allow/deny keywords. They are used in most rule types, which means we 
can get rid of some duplicated code with this function.


Finally, update utils/test/test-regex_matches.py - RE_PROFILE_CAP now 
has 5 instead of 4 match groups because of the added multi-capability 
support.

While on it, I also improved the error message in setup_regex_tests()
to also show the rule that causes a problem.


Acked-by: Steve Beattie <steve@nxnw.org>
2014-10-01 21:45:22 +02:00
Tyler Hicks
bcb1cd750e tests: getopt is not required for bound AF_UNIX pathname sockets
Bug: https://bugs.launchpad.net/bugs/1375516

The unix_socket test program calls getsockopt() after calling bind().
Because AppArmor continues to use traditional file rules for sockets
bound to a filesystem path, it does not mediate some socket operations
after the socket has been bound to the filesystem path. The getopt
permission is one of those socket operations.

To account for this lack of mediation, the getopt permission should be
removed from the server permissions list.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-30 19:00:32 -05:00
Tyler Hicks
7bf0c15ef8 tests: Add unnamed socket tests
Tests abstract UNIX domain sockets with various combinations of implied
permissions, explicit permissions, and conditionals. It also tests with
bad permissions and conditionals.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-30 12:00:10 -05:00
Tyler Hicks
85db44b586 tests: Add negative tests for missing individual AF_UNIX pathname perms
Iterate through the individual client and server AF_UNIX pathname
permissions and remove them, one-by-one, to verify that the test fails.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-30 11:34:42 -05:00
Tyler Hicks
84b6f98007 tests: Separate client and server AF_UNIX pathname permissions
The client and server programs require a different set of AF_UNIX
permissions. This patch makes it so that the unix rules are constructed
differently depending on the program under test.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-30 11:34:32 -05:00
Tyler Hicks
0262f44eb7 tests: Add abstract socket tests
Tests abstract UNIX domain sockets with various combinations of implied
permissions, explicit permissions, and conditionals. It also tests with
bad permissions and conditionals.

The new file unix_socket.inc includes a generic set of tests that can be
reused by another test script in order to test unnamed AF_UNIX socket
mediation. The do_test() function is conditionalized in a way that it
can test confined servers and confined clients depending on the
arguments passed in.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-29 18:49:13 -05:00
Tyler Hicks
2b22c70e74 tests: Break up unix_socket getopt and setopt operations
The unix_socket operations for testing getopt and setopt permissions
were occurring back to back. This patch breaks them up into "pre-bind"
and "post-bind" operations. The setopt operation now occurs pre-bind
while the getopt operation happens post-bind. This allows for the test
policy to test setopt without an addr= conditional and to test getopt
with an addr= conditional.

Additionally, the wrapper functions that call setsockopt()/getsockopt()
are moved into a new file that both unix_socket.c and
unix_socket_client.c can reuse.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-29 18:48:27 -05:00
Tyler Hicks
3368c9bc40 tests: Test the getattr permission in unix_socket_client
The client will now do a getsockname() on its socket in order to test
the AppArmor 'getattr' unix rule permission.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-29 18:47:53 -05:00
Tyler Hicks
48a755d471 tests: Test the shutdown permission in unix_socket
The server will now do a shutdown() on its socket in order to test the
AppArmor 'shutdown' unix rule permission.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-29 18:47:42 -05:00
Tyler Hicks
12b09ecd9e tests: Don't call connect() for connectionless sockets
Use the sendto()/recvfrom() functions when dealing with dgram sockets in
unix_socket_client.

This allows us to test different interfaces besides the typical
write()/read() and will allow for a smaller permissions set for
unix_socket_client.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-29 18:47:36 -05:00
Tyler Hicks
f31b44ff2d tests: Don't use autobinding in unix_socket_client
The unix_socket_client test program was using an abstract socket, which
was set up using the autobind feature, when testing any socket address
types.

To more accurately test a specific address type, this patch changes the
client code to use whatever address type that the server is using. The
string ".client" will be added to the end of the server's address.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-09-29 18:47:14 -05:00
Christian Boltz
deaa692aa2 test if aa-enforce removes force-complain symlinks
Two weeks ago, I fixed various tests in minitools_test.py which also 
included disabling the test if aa-complain deletes the force-complain 
symlink because nothing (especially aa-complain) creates those symlinks.

Seth didn't like the removal of that test too much. Therefore this patch
"manually" creates the force-complain symlink and tests that it's removed
by aa-enforce.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-09-26 22:03:14 +02:00
Seth Arnold
ce2abf01d5 Simon Deziel 2014-09-25 abstractions/freedesktop.org: Allow reading /usr/share/applications/defaults.list
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-09-25 17:47:18 -07:00
Simon Deziel
1d867ae7ba abstractions/freedesktop.org: Allow reading /usr/share/applications/defaults.list
This is required at least by Pidgin's profile and it seems harmless
to allow looking at its content.
2014-09-25 19:45:11 -04:00
Christian Boltz
3d902d57fc dovecot profile improvements:
- usr.lib.dovecot.auth needs /{var/,}run/dovecot/auth-token-secret.dat{,.tmp} rw,
- usr.lib.dovecot.imap requests block_suspend, which I propose to deny as usual

Acked-by: Seth Arnold <seth.arnold@canonical.com>
2014-09-26 00:37:14 +02:00
Jamie Strandboge
1842767cf3 add /usr/bin/gnome-gmail to ubuntu-email (LP: #1169881) 2014-09-24 15:26:38 -05:00