Commit graph

345 commits

Author SHA1 Message Date
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
John Johansen
1179c1a42c Improve partitioning performance slightly by inserting new partitions
imediately after the current partition being considered, instead of
at the back of the parition list.  This does two things, it makes it
more likely the data is in cache, and it also in general results in
more partitions being created in a single pass.
2010-01-31 23:12:33 -08:00
John Johansen
80c7ee74a2 Speedup transition table compression. This is a basic improvement and
not an algorithmic improvement.  It does the same basic algorithm of
test until it can insert the data, but instead of only tracking the
first free entry (and recomputing it each pass).  It tracks all
free entries reducing the number of comparisons done and the table
grows in size.

This may actually result in a small loss on small tables, but is a win
for larger tables.
2010-01-27 17:20:13 -08:00
John Johansen
f9906a9584 Update hash calculation
Update the hash calculation to guarentee that states with a different
number of transition entries will be placed in seperate partitions.

This will allow for a better character transition based state comparison.
2010-01-20 05:10:38 -08:00
John Johansen
91dd7527d9 Dfa minimization and unreachable state removal
Add basic Hopcroft based dfa minimization.  It currently does a simple
straight state comparison that can be quadratic in time to split partitions.
This is offset however by using hashing to setup the initial partitions so
that the number of states within a partition are relative few.

The hashing of states for initial partition setup is linear in time.  This
means the closer the initial partition set is to the final set, the closer
the algorithm is to completing in a linear time.  The hashing works as
follows:  For each state we know the number of transitions that are not
the default transition.  For each of of these we hash the set of letters
it can transition on using a simple djb2 hash algorithm.  This creates
a unique hash based on the number of transitions and the input it can
transition on.  If a state does not have the same hash we know it can not
the same as another because it either has a different number of transitions
or or transitions on a different set.

To further distiguish states, the number of transitions of each transitions
target state are added into the hash.  This serves to further distiguish
states as a transition to a state with a different number of transitions
can not possibly be reduced to an equivalent state.

A further distinction of states is made for accepting states in that
we know each state with a unique set of accept permissions must be in
its own partition to ensure the unique accept permissions are in the
final dfa.

The unreachable state removal is a basic walk of the dfa from the start
state marking all states that are reached.  It then sweeps any state not
reached away.  This does not do dead state removal where a non accepting
state gets into a loop that will never result in an accepting state.
2010-01-20 03:32:34 -08:00
Jamie Strandboge
d98c8ae8b5 add commented, but blank tunables/alias
profiles/apparmor.d/tunables/global: include tunables/alias
parser/apparmor.d.pod: add alias rules and home.d. clean up
 HOMEDIRS
2010-01-11 14:19:35 -06:00
Steve Beattie
b8b2b48949 Add long optimization option along with case-insensitive help options 2010-01-08 14:33:35 -08:00
John Johansen
636ee4a11a Update option parsing for help to add in Short flag form and Optimize
help.
2010-01-08 14:04:56 -08:00
John Johansen
fe08d62e91 Abort if bad option is passed to optimize option parsing 2010-01-08 12:48:10 -08:00
John Johansen
d87145ad23 Update trans table reporting to include some statistics 2010-01-08 05:29:25 -08:00
John Johansen
dce395e7ad Add basic controls for dfa optimization 2010-01-08 04:30:56 -08:00
John Johansen
926b0c72e8 Update the output of transtable creation 2010-01-08 03:18:59 -08:00