Commit graph

606 commits

Author SHA1 Message Date
Kees Cook
feb70284bc Effectively revert revno 1471, and fix the misdetected error condition
so that caching will work again without needing kernel_load.
2010-09-14 12:38:38 -07:00
Kees Cook
3a1fbb49f4 fix up typo and add extern for update_mru_tstamp 2010-09-14 12:37:59 -07:00
John Johansen
02e86864da This patch changes how cache validation is done, by moving it post
parsing, and precompilation of policy.  This allows finding the most
recent text time stamp during parsing and this is then compared to
the cache file time stamp.

While this is slightly slower than the cache file check that only
validated against the profile file it fixes the bug where abstraction
updates do not cause the cache file to become invalid.
2010-09-14 12:22:02 -07:00
John Johansen
8762c1dcfb The upstream 2.6.36 version of apparmor doesn't support network rules.
Add a flag to the parser controlling the output of network rules,
and warn per profile when network rules are not going to be enforced.
2010-08-26 10:37:46 -07:00
John Johansen
1f1a303457 The upstream 2.6.36 version of apparmor is missing the match file,
so the parser doesn't set matching options correctly.

Set minimal defaults with that will allow the parser to load policy,
on 2.6.36 kernels.
2010-08-26 10:36:45 -07:00
John Johansen
d72422b369 When doing debugging/building dfa graphs, generally I use -QT however
this results in

Unable to open output file - Success

to be output to standard error.

This occurs because despite specifying kernel_load = 0, the kernel load
parts are still being done, and failing.
2010-08-17 08:03:07 -07:00
John Johansen
291066dcbd On certain graphs the dfa graph dump output can become messed up as it isn't properly handling non-printing characters in the case of single character
output.  Drop the cast to signed character which messes up the output.
2010-08-17 08:02:27 -07:00
John Johansen
6259edac38 Update and expand comments on regex tree normalization 2010-08-04 10:23:22 -07:00
John Johansen
f0220611aa Epsnodes carry no information beyond the node type. Convert to using
a single static node, which will reduce allocations and peak memory
use slightly.
2010-08-04 09:53:46 -07:00
John Johansen
5c8051994b Make -q quiet can not update cache warnings 2010-08-04 09:52:54 -07:00
John Johansen
b5c780d2a1 Remove pcre and update tests where necessary 2010-07-31 16:00:52 -07:00
Kees Cook
624aee531a Fix many compile-time warnings.
Start replacing RPM with lsb-release.
Drop old references to CVE.
Remove unused code.
2010-07-26 09:22:45 -07:00
John Johansen
4be07c3265 This adds a basic debug dump for the conversion of each rule in a profile to its expression
tree.  It is limited in that it doesn't currently handle the permissions of a rule.

conversion output presents an aare -> prce conversion followed by 1 or more expression
tree rules, governed by what the rule does.
eg.
  aare: /**   ->   /[^/\x00][^\x00]*
  rule: /[^/\x00][^\x00]*  ->  /[^\0000/]([^\0000])*

eg.
echo "/foo { /** rwlkmix, } " | ./apparmor_parser -QT -D rule-exprs -D expr-tree

aare: /foo   ->   /foo
aare: /**   ->   /[^/\x00][^\x00]*
rule: /[^/\x00][^\x00]*  ->  /[^\0000/]([^\0000])*

rule: /[^/\x00][^\x00]*\x00/[^/].*  ->  /[^\0000/]([^\0000])*\0000/[^/](.)*


DFA: Expression Tree
(/[^\0000/]([^\0000])*(((((((((((((<513>|<2>)|<4>)|<8>)|<16>)|<32>)|<64>)|<8404992>)|<32768>)|<65536>)|<131072>)|<262144>)|<524288>)|<1048576>)|/[^\0000/]([^\0000])*\0000/[^/](.)*((<16>|<32>)|<262144>))


This simple example shows many things
1. The profile name under goes pcre conversion.  But since no regular expressions where found
   it doesn't generate any expr rules
2. /** is converted into the pcre expression /[^\0000/]([^\0000])*
3. The pcre expression /[^\0000/]([^\0000])* is converted into two rules that are then
   converted into expression trees.

   The reason for this can not be seen by the output as this is actually triggered by
   permissions separation for the rule.  In this case the link permission is separated
   into what is shown as the second rule: statement.
4. DFA: Expression Tree dump shows how these rules are combined together

You will notice that the rule conversion statement is fairly redundant currently as it just
show pcre to expression tree pcre.  This will change when direct aare parsing occurs,
but currently serves to verify the pcre conversion step.


It is not the prettiest patch, as its touching some ugly code that is schedule to be cleaned
up/replaced. eg. convert_aaregex_to_pcre is going to replaced with native parse conversion
from an aare straight to the expression tree, and dfaflag passing will become part of the
rule set.
2010-07-23 13:29:35 +02:00
John Johansen
837f47c921 This is the user space fix for launchpad.net/busgs/599450
It changes the table resizing so that there is always sufficient
high entries in the table, preventing bounds violations from
occurring.

Previously the resize allocation was always based on the character
set range for a state, which could be more or less than actually
required, and packing would waste some space when over allocation
was done.

As a result this patch in general results in slightly smaller
transition tables even though it enforcing the minimum required
padding to avoid bounds violations.
2010-07-23 04:30:31 +02:00
John Johansen
bfb96638f6 This is a preparatory patch for the fix to launchpad.net/bugs/599450.
It combines the two separate table resize code segments into a single
functionally equivalent segment.  It does not fix the bug.
2010-07-23 04:29:54 +02:00
John Johansen
6453a41a28 Add extra transition table labeling to help with interpretation of the
dump output.
2010-07-23 04:29:29 +02:00
John Johansen
af3476afb9 The templatization of deref_less_than is unnecessary and complicates the code
replace it with its none templatized version.
2010-07-10 17:53:04 -07:00
John Johansen
4f8e01ff36 expression tree node labeling is used during debugging dumps. Currently the node labels
are computed and stored in a map, that is not cleaned up.  This means that the labeling
is retained across different dfas.

Move the labeling into expr node as this takes less memory than using a map and will
also separates node labeling so its per dfa instead of global.  In addition this means
the labeling is cleanedup/freed when the expr tree is freed without any extra work.
2010-07-10 17:52:13 -07:00
John Johansen
d0dcab10f1 Make the transition table dump easier to understand by labeling each entry with its
index.
2010-07-10 17:49:32 -07:00
John Johansen
1004f039ec When creating the dfa the sets firstpos, lastpos, and followpos are computed for
each expression tree node and then used as input to create the dfa states.

Currently they are not being freed until the nodes are destroyed, but the information
is no longer needed once the dfa has been created.  Cleaning them up early reduces
peak memory usage.
2010-07-10 17:47:25 -07:00
John Johansen
da6df9fdc5 The apparmor parser applies the disabled and complain mode directories even when just
dumping the preprocessor output to stdout.

Add a flag to test whether to skip forcing the mode and use it with -p (dump preprocessed
profile).
2010-07-10 17:46:06 -07:00
John Johansen
a30ecbfe3c Add the -o flag to allow specifying the output file instead of loading
to the kernel.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2010-06-26 13:14:56 -07:00
John Johansen
49530d5fe5 This patch adds back in the -p flag, allowing the dumping of a
flattened profile to stdout.

It currently does not do anymore than flattening the include
files.  The expansions of variables etc can be added later.
2010-06-26 13:13:52 -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
6737031eb9 hrm, since I added code, I need to update the copyright details. 2010-06-04 18:57:01 -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
John Johansen
b0a9f46bb7 Update parser man page to include dump and optimize flags 2010-04-03 16:24:06 -07:00
John Johansen
d295e3b444 Update several flags to not preclude there using with writing the cache,
they will however still skip reading the cache.
2010-04-03 15:41:40 -07:00
Steve Beattie
4e039d07f3 - Break out make targets so that distributors that don't want full docs
can pick targets they want. Patch from Arkadiusz Miskiewicz <arekm at
  maven.pl>.

- Comment out debug dump of generate af_names.h
2010-03-16 15:18:55 -07:00
John Johansen
9efd526f6f Fix memory leak during dfa minimization.
Dfa minimization wasn't deleting the states it eliminated during the
minimization process, and hence leaking memory.
2010-03-13 02:23:23 -08:00
Steve Beattie
4ab92b62f5 Fix debug options so they don't go through the dfa engine, significantly
speeding up the time to emit debugging information.
2010-03-12 15:26:32 -08:00
Steve Beattie
bd1b72ad42 *whimper* last portiong of the strict-aliasing fix. 2010-03-12 15:20:22 -08:00
Steve Beattie
bccd45a22e Bah, managed to forget part of the last commit. The other half of fixing
the strict-aliasing bit, the portion that I don't like.
2010-03-12 15:16:06 -08:00
Steve Beattie
3b9b2158c1 Fix strict aliasing issue that triggered a bug in the parser_symtab unit
tests. I don't like the solution because it exposes a data structure
definition outside of the only file that should know it's layout.

Also, fixed the Makefile to fail the build when one of the unit test
programs fails. :-(
2010-03-12 14:41:58 -08:00
Steve Beattie
21875a520d Fix leaking file descriptors on included files. 2010-03-12 01:50:26 -08: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
69d59f80ed Don't (un)load flattened hats on removal, as the kernel pulls them out
automatically (and the parser emits an error due to this).
2010-03-09 01:38:12 -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
Steve Beattie
fc669861fe Yuck, fix up bogus type conversions. Also fix up some PDEBUG statements,
to make debugging why things are going wrong in specific examples
easier.
2010-03-08 21:49:16 -08:00
Steve Beattie
61c61f9aab Add some unit tests for processunquoted() -- sadly it handles octals
fairly wrong. Need to fix, but not tonight. Le sigh
2010-03-08 20:38:54 -08:00
John Johansen
5709d94710 Add the ability to control how path mediation is done at the profile level 2010-02-17 12:21:52 -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
John Johansen
ee00b0cea2 Update aliases so that they apply properly to profile names.
Instead of updating the profile name, allow a profile to have multiple
alternate names.  Aliases are now added as alternate names and matched
through the xmatch dfa.
2010-02-12 13:49:58 -08:00
John Johansen
eafddd3cea Fix alias to keep old rule and add new one instead of updating old rule.
Alias was broken because it when an alias was made the old path was completely
removed and there was no way to specify it.  Update it so aliases just add
an new duplicate rule instead.
2010-02-12 13:46:55 -08:00
John Johansen
94b2a345f2 Fix -S flag so the profile can be dumped to stdout again
The changes to the loader permission logic broke the -S flag, so update
the test so that we can dump out the profile again.
2010-02-12 13:44:00 -08:00
John Johansen
8dd795dec1 Rework the partitioning to take advantage of Partitions now being a list 2010-01-31 23:21:00 -08:00
John Johansen
8bcfa1a32f Move partitions from using sets to lists as this is a better match
for what is being done.
2010-01-31 23:19:54 -08:00
John Johansen
e984b6ff74 Seperate Partition definition for States. This is a small step to cleaning
up the code
2010-01-31 23:18:14 -08:00