Commit graph

105 commits

Author SHA1 Message Date
Steve Beattie
2fec3758ed Subject: [patch] fix apparmor cache tempfile location to use passed arg v2
Merge from trunk revision 2142

This patch fixes problems in the handling of both the final cache
name location and the temporary cache file when an alternate location
is specified.

The first issue is that if the alternate cache directory location was
specified, the alternate directory name would be used as the final
location for the cache file, rather than the alternate directory +
the basename of the profile.

The second issue is that it would generate the temporary file that it
stores the cache file in [basedir]/cache even if an alternate cache
location was specified on the command line. This causes a problem
if [basedir]/cache is on a separate device than the alternate cache
location, because the rename() of the tempfile into the final location
would fail (which the parser would not check the return code of).

This patch fixes the above by incorporating the basename into the cache
file name if the alternate cache location has been specified, bases the
temporary cache file name on the destination cache name (such that they
end up in the same directory), and finally detects if the rename fails
and unlinks the temporary file if that happens (rather than leave it
around). It also has been updated to add a couple of testcases to verify
that writing and reading from an alternate cache location work.

Patch history:
  v1: first draft of patch
  v2: add testcases, convert PERROR() to pwarn() if rename() fails for
      placing cachefile into place.

For 2.8 branch:

Signed-off-by: Steve Beattie <sbeattie@ubuntu.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
2013-07-29 09:52:18 -07:00
Steve Beattie
0a97828f30 Subject: parser tests - fix fine grained timestamp detection in
caching tests

Merge from trunk commit 2083

Original message:
  This patch modifies the parser's caching test to more accurately detect
  whether or not the filesystem has a fine enough timestamp resolution.
  Occasionally even on filesystems like ext3, the two files' creation
  dates would differ when created less than a second apart, which would
  typically cause the 'Cache is used when cache is newer' test to fail
  because the cached file would have the same timestamp as the profile.
  
  The fix creates 10 files 0.1 seconds apart and ensures that all ten
  have distinct timestamps.
  
  (The occasional failure was caught in testing runs like
   https://bugs.launchpad.net/qa-regression-testing/+bug/1087061/ )
  
  Signed-off-by: Steve Beattie <sbeattie@ubuntu.com>
  Acked-by: John Johansen <john.johansen@canonical.com>

Nominated-by: Steve Beattie <sbeattie@ubuntu.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2013-01-03 17:28:44 -08:00
Steve Beattie
6654dfe251 Subject: parser tests - fix test driver for exec() failure
Merge from trunk commit 2076

Original message:
  Subject: two fixes to the parser's simple test driver
  
  This patch fixes two issue with the simple test driver. The first is
  that child exec that actually ran the parser was located inside the
  eval statement. This meant that if the exec failed for some reason
  (like the parser didn't exist), the child wouldn't actually die,
  but would pop out of the eval and continue running through the loop
  of test profiles (while the parent process does the same). This meant
  that if the script ran on the full testsuite with a misconfiguration,
  it would explode creating O(n^2) processes, where n is the number of
  testcase files -- with over 25k testcases, that's a lot. The fis is to
  lift the child exec outside the eval{}, then an exec() failure causes
  the child process to die correctly.
  
  The second fix is that several of the testcases were added with the
  DESCRIPTION field added in lower case (i.e. #=Description blah blah).
  This fix makes the regex that pulls out the description not be
  case-sensitive.
  
  Signed-off-by: Steve Beattie <sbeattie@ubuntu.com>
  Acked-By: John Johansen <john.johansen@canonical.com>

Nominated-by: Steve Beattie <sbeattie@ubuntu.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2013-01-03 17:22:00 -08:00
Steve Beattie
06aa9b0a54 Subject: update caching test message
Merge from just the parser/tst/caching.sh portion of trunk commit 2066.

Original message:
  apparmor: abstract out the directory walking routine
  
  The apparmor_parser has 3 different directory walking routines.
Abstract
  them out and use a single common routine.
  
  Signed-off-by: John Johansen <john.johansen@canonical.com>
  Acked-By: Steve Beattie <sbeattie@ubuntu.com>
 
Nominated-by: Steve Beattie <sbeattie@ubuntu.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2013-01-03 16:20:14 -08:00
Steve Beattie
ecd14e46b9 Add a testcase for the issue fixed in commit 2059.
Signed-off-by: Steve Beattie <sbeattie@ubuntu.com>
Acked-by: John Johansen <john.johansen@canonical.com>
2012-12-10 17:01:24 -08:00
John Johansen
00bf73f7c2 apparmor: add clearing the profile cache when inconsistent
Add the ability to clear out the binary profile cache. This removes the
need to have a separate script to handle the logic of checking and
removing the cache if it is out of date.

The parser already does all the checking to determine cache validity
so it makes sense to allow the parser to clear out inconsistent cache
when it has been instructed to update the cache.

Signed-off-by: John Johnansen <john.johansen@canonical.com>
2012-08-09 00:37:25 -07:00
John Johansen
3356dc4edd Update the parser to support the 'in' keyword for value lists
Bug #959560 Part 1/3 of fix

Signed-off-by: John Johansen <john.johansen@canonical.com>
2012-03-26 06:17:40 -07:00
John Johansen
3c9cdfb841 rework the is_null test to not include deny
The deny information is not used as valid accept state information,
so remove it from the is_null test.  This does not change the dfa
generated but does result in the dumped information changing,
as states that don't have any accept information are no longer
reported as accepting. This is what changes the number of states
reported in the minimize tests.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2012-03-22 07:55:00 -07:00
John Johansen
59c0bb0f46 Fix minimize.sh test to screen out more parser error messages by grepping
closer to the expected -O dfa-states output
2012-03-09 06:48:03 -08:00
John Johansen
fae11e12cf Mark the minimize test as executable 2012-03-09 05:54:54 -08:00
John Johansen
c8e134930f Fix the "Kernel features are written to cache:" test
the cache test is failing because it assumes that kernel features are
stored in a file instead of a directory

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2012-03-09 04:25:03 -08:00
John Johansen
5e361a4a05 Fix dfa minimization to deal with exec conflicts
Minimization was failing because it was too agressive.  It was minimizing
as if there was only 1 accept condition.  This allowed it to remove more
states but at the cost of loosing unique permission sets, they where
being combined into single commulative perms.  This means that audit,
deny, xtrans, ... info on one path would be applied to all other paths
that it was combined with during minimization.

This means that we need to retain the unique accept states, not allowing
them to be combined into a single state.  To do this we put each unique
permission set into its own partition at the start of minimization.

The states within a partition have the  same permissions and can be combined
within the other states in the partition as the loss of unique path
information is will not result in a conflict.

This is similar to what perm hashing used to do but deny information is
still being correctly applied and carried.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2012-03-09 04:20:19 -08:00
John Johansen
cf5f7ef9c2 Fix the x intersection consistency test
The in x intersection consistency test for minimization was failing because
it was screening off the AA_MAY_EXEC permission before passing the exec
information to the consistency test fn.  This resulted in the consistency
test fn not testing the consistency because it treated the permission set
as not having x permissions.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2012-03-09 04:19:24 -08:00
John Johansen
c9e31b7fbd Add mount rules
Add the ability to control mounting and unmounting

The basic form of the rules are.

  [audit] [deny] mount [conds]* [device] [ -> [conds] path],
  [audit] [deny] remount [conds]* [path],
  [audit] [deny] umount [conds]* [path],
  [audit] [deny] pivotroot [oldroot=<value>] <path> -> <profile>

  remount is just a short cut for mount options=remount

  where [conds] can be
    fstype=<expr>
    options=<expr>


  conds follow the extended conditional syntax of allowing either:

  * a single value after the equals, which has the same character range as
    regular IDS (ie most anything but it can't be terminated with a , (comma)
    and if spaces or other characters are needed it can be quoted

    eg.
       options=foo
       options = foo
       options="foo bar"

  * a list of values after the equals, the list of values is enclosed within
    parenthesis () and its has a slightly reduced character set but again
    elements can be quoted.

    the separation between elements is whitespace and commas.

    eg.
      options=(foo bar)
      options=(foo, bar)
      options=(foo , bar)
      options=(foo,bar)


The rules are flexible and follow a similar pattern as network, capability,
etc.

  mount,	# allow all mounts, but not umount or pivotroot

  mount fstype=procfs,  # allow mounting procfs anywhere

  mount options=(bind, ro) /foo -> /bar,  # readonly bind mount

  mount /dev/sda -> /mnt,

  mount /dev/sd** -> /mnt/**,

  mount fstype=overlayfs options=(rw,upperdir=/tmp/upper/,lowerdir=/) overlay -> /mnt/

  umount,

  umount /m*,


Currently variables and regexs are are supported on the device and mount
point. ie.
  mount <devince> -> <mount point>,

Regexes are supported in fstype and options.  The options have a further
caveat that regexs only work if the option is fs specific option.

  eg. options=(upperdir=/tmp/*,lowerdir=/)

regex's will not currently work against the standard options like ro, rw
nosuid


Conditionals (fstype) can only be applied to the device (source) at this
time and will be disregarded in situations where the mount is manipulating
an existing mount (bind, remount).

Options can be specified multiple times
  mount option=rw option=(nosuid,upperdir=/foo),

and will be combined together into a single set of values

The ordering of the standard mount options (rw,ro, ...) does not matter
but the ordering of fs specific options does.

Specifying that the value of a particular option does not matter can be
acheived by providing both the positive and negative forms of and option
  option=(rw,ro) options=(suid,nosuid)

For the fs specific options specifying that a particular value does not
matter is achieve using a regex with alternations.

Improvements to the syntax and order restrictions are planned for the
future.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2012-02-24 04:19:38 -08:00
John Johansen
e087db57b2 Allow the 'file' keyword to be optionally used on file rules.
Add the optional 'file' keyword to the language/grammer.  The main reason
for doing this is to support false token injection.  Which is needed
to move towards the parser being broken out into an api that can be
used to parse individual rule types, separate from parsing the whole file.

Since we are adding the token to the grammar expose it to userspace with
the 'file' keyword.  While not needed it helps bring consistency, as all
the other rule types start with a keyword (capability, network, rlimit, ...).

Also allow the bare keyword to be used to represent allowing all file
operations, just as with network and capability.  Domain transitions are
defaulted to ix.  Thus

  file,

is equivalent to

  /** rwlkmix,

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Kees Cook <kees@ubuntu.com>
2012-02-16 08:06:04 -08:00
John Johansen
dd7427d1eb Remove setting of capabilities from the syntax
The ability to set capabilities from a profile has been removed from the
kernel for several releases.  Remove it from the parser as well.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Kees Cook <kees@ubuntu.com>
2012-02-16 08:04:04 -08:00
John Johansen
4a4ec1c54a Make expressing all capabilities easier
Allow the capability rule to be bare to represent all capabilities similar
to how network, and other rule types work.

  capability,

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Kees Cook <kees@ubuntu.com>
2012-02-16 08:01:47 -08:00
Steve Beattie
d4c4cbe62b It's possible that git doesn't like to create empty directories, so
create the generated_* directories themselves if they don't exist before
running the script to generate them.

Also modify the default invocation of prove to add -f, which reports the
details of failing test cases.
2011-08-09 01:10:19 -07:00
Kees Cook
1644ce31e7 Description: Improve generated test readability and build-time cleanup.
Author: Kees Cook <kees@debian.org>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2011-05-02 13:36:55 -07:00
Steve Beattie
dce1d5d5e6 Bah, fix up screwed up testcase. 2011-03-29 02:46:09 -07:00
Steve Beattie
f8b43d5ba9 The parser's lexer supports variables defined matching the regex
'[[:alpha:]][[:alnum:]_]*' (i.e. a single alpha followed by any number
of alphanumerics or underscores). Unfortunately, the code that expends
variables inside a profile does not match this, it incorrectly matched
'([[:alpha:]]|_)+' (one or more alphas or underscores). This patch
corrects the behavior there as well as synchronizing the expected
variable names in the apparmor.d manpage and apparmor.vim syntax file.

It also adds unit tests and testcases to verify the behavior.

Signed-off-by: Steve Beattie <sbeattie@ubuntu.com>
2011-03-28 10:52:02 -07:00
John Johansen
0b383ad769 Add tests to ensure parser is checking its own time stamp wrt profile cache
Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
2011-03-08 14:52:32 -08:00
Steve Beattie
f471bc4018 Author: Jamie Strandboge <jamie@canonical.com>
Description: the Ubuntu buildds do not have the AppArmor securityfs mounted, so
the cache tests fail. This patch skips these tests if the introspection
directory is not mounted, but runs them if it is. This should allow testing of
local builds while still allowing builds on the official buildds.

Acked-By: Steve Beattie <sbeattie@ubuntu.com> - both Ubuntu and
OpenSUSE were carrying patches that disabled the caching test,
though OpenSUSE's disabled it completely rather than checking. The
parser builds need to complete even when the kernel it's building on
doesn't support AppArmor or all the extensions that the parser needs
at runtime.
2011-02-15 10:41:29 -08:00
Kees Cook
14d8bac7b2 Here's an update to rename another chunk of things that still used
"SubDomain" in some way. This leaves only "subdomain.conf" and the
function names internally.

Additionally, I added a "make check" rule to the utils/Makefile to do a
simple "perl -c" sanity check just for good measure.
2011-01-13 13:58:26 -08:00
Kees Cook
39b5240966 mark parser/tst/simple_tests/xtrans/minimize-x-conflict.sd as "TODO" and hook up parser/tst/Makefile "clean" to parser/Makefile "clean" rule 2010-12-20 13:44:14 -08:00
Kees Cook
b11fd82d96 make gen-xtrans executable 2010-12-20 13:25:54 -08:00
John Johansen
3973387295 Add missing files from my last 11 patches as I forgot to do bzr add before
committing.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-12-20 13:18:36 -08:00
Kees Cook
a6dc414f57 adjust line offset now that $Id$ was removed 2010-12-20 13:06:54 -08:00
Kees Cook
723a20ba7d as ACKed on IRC, drop the unused $Id$ tags everywhere 2010-12-20 12:29:10 -08:00
John Johansen
77be2c450f Add the safe xtransition key word
Currently apparmor provides the unsafe keyword to indicate an xtransition
is not scrubbing its environment variables.  This can be used to be
explicit about which transition are unsafe instead of relying on people
remembering which of px Px is safe or unsafe.

Add the orthogonal keyword safe to allow specifying a transition is
safe.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-12-20 11:58:05 -08:00
John Johansen
4eea3ae073 Make meaning of leading permissions consistent with trailing permissions
x Permissions when specified as a the start of the rule had a differnt
meaning than when they appeared at the tail of a rule.

Specifically px,cx,ux were not treated as unsafe when they appeared at
the start of the rule.
  px /foo,
instead of at the tail of the rule
  /foo px,

the keyword unsafe had to be used to force the rule to cause the x transitio
to be its unsafe variant.

Fix leading permissions so that they are consistent with file rules that
use trailing permissions.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-12-20 11:56:57 -08:00
John Johansen
a29078ac04 Add auto generation of tests to verify leading and trailing perms for xrules
Test the leading permission form of an xrule against its trailing permission
form, to verify that they are generating the same xtransition and thus
don't conflict (assumes xtransition conflict checking is working).
  eg.
    px /foo,
    /foo px,

should generate the same rule and thus not result in any conflicts

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-12-20 11:54:27 -08:00
John Johansen
851b7655c1 Add auto generation of xtransition conflict tests
All the combiniation of xtransition conflics where not well represented in
the regression test suite.  Instead of relying on multiple static test
files, automatically generate all possible conflicts.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-12-20 11:53:52 -08:00
John Johansen
fb61ea7635 Fix xtrans tests
Several of the x-trans tests where failing because of the include file was
bad.  This kept the test from testing what it was supposed as the test
was expected to fail.  Thus hidding a bug :(

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-12-20 11:50:31 -08:00
John Johansen
7c1f5fd932 Merge profile and :namespace:profile parsing into a single rule.
clean up profile parsing by merging profile and :namespace:profile parsing
into a single rule.

This also fixes a bug where the profile	keyword was not allowed to proceed
profiles with a namespace declaration.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2010-12-13 16:26:38 -08:00
Steve Beattie
8740fd517d This patch fixes the parser's lexer to not passthrough other invalid
characters in variable declarations. It also adds testcases
demonstrating the issue.
2010-11-19 02:27:33 -08:00
Steve Beattie
7ef28d9fdc This patch fixes the parser to return an error when variable declaration
statements contain trailing commas, instead of passing them through to
STDOUT. It also adds parser testcases demonstrating the issue.
2010-11-19 01:42:04 -08:00
Steve Beattie
d7fde9d109 Reorders the timstamp check to move it to the beginning of the
script and add an additional sleep before the parser invocation that
generates the cache file for the first time, to avoid failures in the
"Profiles are cached when requested:" test on ext3 and other filesystems
without fine-grained enough timestamps.
2010-09-15 14:28:35 -07:00
Kees Cook
862836548d Fix write_cache to not be a privileged operation so that the caching tests
can be added to the build. Update caching tests to detect non-ns-resolution
filesystems and back off on the timing test.
2010-09-14 12:45:34 -07:00
Steve Beattie
2d2897f426 This patch adds a couple of additional lineno reporting testcases:
* a non-include related syntax error (errors/modefail.sd)
  * multiple successful includes followed by a failed include
    (errors/multi_include.sd)

It also fixes two issues with the parser's line counting:

  * the count began at 0 (demonstrated by the first testcase's error
    being reporting on one line less than it should be), and

  * an extra line increment when includes were detected (demonstrated
    by the second testcase's error being reported at a line beyond the
    correct linenumber.

The existing testcases did not catch these because they were all
based on the first include in the file failing and so the start of
the count from 0 counteracted the extra counted line.
2010-06-25 12:43:48 -07:00
Kees Cook
7cfc7e1133 add correct line number and filename tracking for error conditions (LP: #588014)
Bug: https://launchpad.net/bugs/588014
2010-06-04 18:47:44 -07:00
Steve Beattie
4094043011 Fix up some testcase description fields 2010-03-10 21:38:10 -08:00
John Johansen
04a872f927 Add some new profile flag tests to validate parsing of the new flags
controlling nameresolution.
2010-03-10 17:00:24 -08:00
Steve Beattie
ebe59ca483 Add a simple 'cx' mode testcase. I *think* I'm specifying it correctly. 2010-03-08 22:28:22 -08:00
Kees Cook
4f5686901b include *.dpkg-bak in files to ignore 2010-02-16 12:56:04 -08:00
John Johansen
725328c209 Allow for a location to alias to multiple locations. Ie.
alias / -> /rofs,
alias / -> /rwfs,
2010-02-12 13:51:27 -08:00
Steve Beattie
09ced81ee5 Add debugging reporting for the other capability entry types (audit,
deny).
2010-01-07 15:48:14 -08:00
Kees Cook
b4c355e17e actually add caching tests 2009-11-11 11:07:50 -08:00
Kees Cook
da6c9246f5 clear remaining $Id$ tags, since bzr does not suppor them 2009-11-11 10:44:26 -08:00
John Johansen
9e27a95b8e Enable profile names with regular expressions. This requires a newer
kernel.
2009-07-30 06:09:19 +00:00