Commit graph

54 commits

Author SHA1 Message Date
Steve Beattie
030d97e3f1 Merge from r1430: fix for LP: #599450
Changes the table resizing so that there is always sufficient high
entries in the table, preventing bounds violations from occurring.

Nominated-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2010-07-24 16:16:14 +02:00
Steve Beattie
0eb5d7c050 Merge from r1429: combine the two separate table resize code segments
into a single functionally equivalent segment.

Nominated-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2010-07-24 16:09:25 +02:00
Steve Beattie
1ad455c6da Merge r1385: Fix memory leak during dfa minimization.
Nominated-by: Steve Beattie <sbeattie@ubuntu.com>
Acked-By: Marc Deslauriers <marc.deslauriers@canonical.com>
2010-07-13 16:36:47 -07:00
Steve Beattie
ac1a585bbe Merge from trunk rev 1424: Move expression tree node labeling into expr
node themselves to reduce memory usage and make node labeling per dfa
rather than global.

Nominated-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2010-07-12 15:53:51 -07:00
Steve Beattie
8187d02864 Merge in rev 1422 from trunk: Cleaning up the sets firstpos, lastpos,
and followpos early reduces peak memory usage.

Nominated-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
2010-07-12 15:28:26 -07: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
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
John Johansen
4f044e753c Add basic dfa stats and debug dumps for
equivelence classes
expr tree (add stats, update parser switch)
dfa
transition table
2010-01-08 02:17:45 -08:00
John Johansen
17a67d7227 Update parser to allow for multiple debug dump options via -D or --dump.
This will allow turning on and off various debug dumps as needed.
Multiple dump options can be specified as needed by using multiple
options.
  eg. apparmor_parser -D variables
      apparmor_parser -D dfa-tree -D dfa-simple-tree


The help option has also been updated to take an optional argument
to display help about give parameters, currently only dump is supported.

  eg.  apparmor_parser -h       # standard help
       apparmor_parser -h=dump  # dump info about --dump options

Also Enable the dfa expression tree dumps
2010-01-07 16:21:02 -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
aced280818 Make cache warning respect the quiet flag 2009-08-20 23:48:32 +00:00
John Johansen
397ead10af add aare_reset_matchflags() to reset match flags
Signed-Off-By: Kees Cook <kees.cook@canonical.com>
2009-07-24 07:33:09 +00:00
John Johansen
5148942b90 Fix a missing case in the pcre-expression parsing "\\"
Change the globbing conversion to include [^\x00].  This reduces cases of
artifical overlap between globbing rules, and link rules.  Link rules
are encoded to use a \0 char to seperate the 2 match parts of the rule.

Before this fix a glob * or ** could match against the \0 seperator
resulting the generation of dfa states for that overlap.  This of course
can never happen as \0 is not a valid path name character.

In one example stress policy when adding the rule
  owner /** rwl,
this change made the difference between having a dfa with 55152 states
and one with 30019
2008-12-04 10:44:02 +00:00
John Johansen
037d7b5a57 Clean up the tree simplification code, and make the following improvements
- disable charter, charset merging.  This can actually hamper optimization
  in some cases and needs special cases added to the factoring code.

  The charset code is merged off into its own routines that can be
  reenabled at a later time.

- fix a couple bugs in tree simplifications that would cause earlier
  exit before the tree had even reached a local minima

  I particular the t != c portion of the simplify_tree, would cause
  the loop to exit early if it didn't change but other modifications
  had been made.

- remove the extra epsnode that was getting added to the created tree

- optimize the forward factor alt loop so that it will find all left
  factor matches down the alt subtree without having to loop and recompare
  against nodes that were already checked

These changes result in small improvements in most cases, but in some
policies the changes result in very large wins.  The early bailout of
optimizations was causing 2.5* as many dfa states in one particular
stress test policy.
2008-12-03 03:47:31 +00:00
John Johansen
b017899f12 Fix a bug in tree normalization, where it could get stuck in an infinite loop
when doing Epsnode move, when cating or alting two epsnodes.
2008-11-20 16:19:51 +00:00
John Johansen
0491e8d707 Add char node, and char node set merging. This does not have a substantive
impact on performance but makes tree debugging nicer.
2008-11-20 13:23:13 +00:00
John Johansen
c0533b390b Reintroduce calling back into tree simplification when any modifications have
been made but only from the top level.  This allows us to get the
optimizations that were missed, while not causing the massive recursive call
explosion we had before.
2008-11-20 13:21:23 +00:00
John Johansen
1855fde331 Reduce the use of simplify recursion, repeating the recursion of single
changes is a waste especially as we get to larger subtrees.

Unfortunately this also means that a fair bit of optimization is lost.
2008-11-20 13:18:30 +00:00
John Johansen
91eb71e9fa Improve tree normalization
- reduce the amount it is called, and the amount of recursion it does
- fix a bug that would prevent trees from being fully normalized
2008-11-19 16:54:26 +00:00
John Johansen
5b97455878 Improve dfa generation.
Apply tree factoring and simplification techniques to reduce the number of
states used in computing the dfa.  This can have an exponential impact
on both space and time for dfa generation.
2008-11-07 13:00:05 +00:00
John Johansen
6b6c57887c Reverting previous commit. 2008-11-07 01:31:19 +00:00
John Johansen
1b0dd32cca fix race condition between boot.apparmor and boot.cleanup bnc#426149 2008-11-07 01:19:55 +00:00
John Johansen
b2f4863231 Fix to stop leaking the dfa ruleset. On large policies containing lots of
hats this will result in a marked improvement on memory usage.
2008-06-08 08:56:37 +00:00
John Johansen
db34aac811 Basis for named transitions 2008-04-16 04:44:21 +00:00
John Johansen
4dd0e8ead8 allow for ptrace rules 2008-04-09 09:04:08 +00:00
John Johansen
c460dcc52f update change_hats rules to generate rules for all hats 2008-04-06 18:52:47 +00:00
John Johansen
a3c0753b89 Add Audit control to AppArmor through, the use of audit and deny
key words.  Deny is also used to subtract permissions from the
profiles permission set.

the audit key word can be prepended to any file, network, or capability
rule, to force a selective audit when that rule is matched.  Audit
permissions accumulate just like standard permissions.

  eg.
  audit /bin/foo rw,

  will force an audit message when the file /bin/foo is opened for
  read or write.

  audit /etc/shadow w,
  /etc/shadow r,
  will force an audit message when /etc/shadow is opened for writing.
  The audit message is per permission bit so only opening the file
  for read access will not, force an audit message.

  audit can also be used in block form instead of prepending audit
  to every rule.

  audit {
    /bin/foo rw,
    /etc/shadow w,
  }
  /etc/shadow r,	# don't audit r access to /etc/shadow


the deny key word can be prepended to file, network and capability
rules, to result in a denial of permissions when matching that rule.
The deny rule specifically does 3 things
- it gives AppArmor the ability to remember what has been denied
  so that the tools don't prompt for what has been denied in
  previous profiling sessions.
- it subtracts globally from the allowed permissions.  Deny permissions
  accumulate in the the deny set just as allow permissions accumulate
  then, the deny set is subtracted from the allow set.
- it quiets known rejects.  The default audit behavior of deny rules
  is to quiet known rejects so that audit logs are not flooded
  with already known rejects.  To have known rejects logged prepend
  the audit keyword to the deny rule.  Deny rules do not have a
  block form.

eg.
  deny /foo/bar rw,
  audit deny /etc/shadow w,

  audit {
     deny owner /blah w,
     deny other /foo w,
     deny /etc/shadow w,
  }
2008-03-13 17:39:03 +00:00
John Johansen
d2eeef8291 extend the flags in preparation for audit control 2008-03-13 16:46:53 +00:00
John Johansen
814773b2e1 Update the parse to emit a 0 to seperate pairs in the dfa.
This was always the intended behavior and fixes a bug where
the dfa will match change profile rules using // seperator.
2008-03-13 16:46:19 +00:00
John Johansen
ace86e6d01 fix overlapping x modifiers perm computation 2007-12-20 12:56:50 +00:00
John Johansen
97dbaa02cb change from U:G:O syntax to owner syntax and remove group permission 2007-11-29 18:06:53 +00:00
John Johansen
638535d650 exec modes per U:G:O 2007-11-16 09:35:57 +00:00
John Johansen
ec639bc82c user:group:any permissions 2007-11-16 09:35:31 +00:00
John Johansen
230b04231c add pix transition mode 2007-11-16 09:27:34 +00:00
Steve Beattie
9df76dbcda Patch by jjohansen@suse.de
Acked-By: Steve Beattie <sbeattie@suse.de>

Add mediation/keywords for locks.
2007-07-27 20:38:43 +00:00
Steve Beattie
95d6ab1b1b Patch by jjohansen@suse.de
Acked-By: Steve Beattie <sbeattie@suse.de>

Add support for a distinction between write permission and append-only
permission.
2007-07-27 20:31:38 +00:00
Steve Beattie
86e5ed3109 Patch from jjohansen@suse.de
Fix debugging with CHANGE_PROFILE.
2007-07-27 20:25:59 +00:00
John Johansen
cd79c1ac77 update copyright dates 2007-04-11 08:12:51 +00:00
Andreas Gruenbacher
cd1eaa88a0 Add DFA table format README. 2007-04-03 13:53:24 +00:00
Andreas Gruenbacher
b379c2dcc3 Introduce reference counting for syntax tree nodes. Use that to share AcceptNodes, and split the bits in AcceptNodes to minimize the number of states. 2007-03-30 20:38:51 +00:00
Andreas Gruenbacher
b73d827660 Fix build: screwed up because the build dependencies are broken; changes to regexp.y don't trigger the appropriate rebuilds 2007-03-30 15:58:15 +00:00
Andreas Gruenbacher
212b828384 Comment out some dead code 2007-03-30 15:20:57 +00:00