+extern int erratic;
+
static int psccompare(struct policy_syscall *, struct policy_syscall *);
static int policycompare(struct policy *, struct policy *);
static int polnrcompare(struct policy *, struct policy *);
@@ -579,8 +581,14 @@ systrace_policyprocess(struct policy *po
snprintf(line, sizeof(line), "true then %s", rule);
rule = line;
}
- } else if (filter_parse_simple(rule, &action, &future) == 0)
- resolved = 1;
+ } else if (filter_parse_simple(rule, &action, &future) == 0) {
+ if (erratic) {
+ /* Need to make a real policy out of it */
+ snprintf(line, sizeof(line), "true then %s", rule);
+ rule = line;
+ } else
+ resolved = 1;
+ }
/* For now, everything that does not seem to be a valid syscall
* does not get fast kernel policies even though the aliasing
@@ -690,6 +698,7 @@ systrace_writepolicy(struct policy *poli
char tmpname[2*MAXPATHLEN];
char finalname[2*MAXPATHLEN];
struct filter *filter;
+ short action, future;
if ((p = systrace_policyfilename(policydir, policy->name)) == NULL)
return (-1);
@@ -717,8 +726,15 @@ systrace_writepolicy(struct policy *poli
filter->emulation, filter->name, filter->rule);
}
TAILQ_FOREACH(filter, &policy->filters, policy_next) {
+ if (erratic &&
+ !strncmp(filter->rule, "true then ", 10)) {
+ p = filter->rule + 10;
+ if (filter_parse_simple(p, &action, &future))
+ p = filter->rule;
+ } else
+ p = filter->rule;
fprintf(fp, "\t%s-%s: %s\n",
- filter->emulation, filter->name, filter->rule);
+ filter->emulation, filter->name, p);
}
}
fprintf(fp, "\n");
Index: systrace.1
===================================================================
RCS file: /cvsroot/src/bin/systrace/systrace.1,v
retrieving revision 1.25
diff -u -p -r1.25 systrace.1
--- systrace.1 2003/08/20 01:28:44 1.25
+++ systrace.1 2003/09/29 11:55:52
@@ -39,12 +39,13 @@
.Nd generate and enforce system call policies
.Sh SYNOPSIS
.Nm systrace
-.Op Fl AaitUu
+.Op Fl AaiktUu
.Op Fl c Ar uid:gid
.Op Fl d Ar policydir
.Op Fl f Ar file
.Op Fl g Ar gui
.Op Fl p Ar pid
+.Op Fl r Ar chance Ns Op Ar -seed
.Ar command ...
.Sh DESCRIPTION
The
@@ -108,6 +109,11 @@ knows about.
Specifies an alternative location for the notification user interface.
.It Fl i
Inherits the policy - child processes inherit policy of the parent binary.
+.It Fl k
+When used in conjunction with
+.Fl a ,
+operations not covered by policy result in the process being killed
+after the operation has been logged.
.It Fl p Ar pid
Specifies the pid of a process that
.Nm
@@ -115,6 +121,15 @@ should attach to.
The full path name of the corresponding binary has to be specified
as
.Ar command .
+.It Fl r Ar chance Ns Op Ar -seed
+Randomly cause operations to fail with a probability of one in
+.Ar chance .
+.Pp
+.Ar seed
+specifies the initial conditions for the random number generator used.
+By specifying the same
+.Ar seed
+for multiple invocations, test cases may be reproduced.
.It Fl t
Uses text mode to ask for interactive policy generation.
.It Fl U
Index: systrace.c
===================================================================
RCS file: /cvsroot/src/bin/systrace/systrace.c,v
retrieving revision 1.23
diff -u -p -r1.23 systrace.c
--- systrace.c 2003/08/25 09:12:46 1.23
+++ systrace.c 2003/09/29 11:55:52
@@ -35,6 +35,7 @@
#include <sys/wait.h>
#include <sys/tree.h>
#include <sys/socket.h>
+#include <sys/time.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
@@ -61,6 +62,8 @@ int allow = 0; /* Allow all and genera
int userpolicy = 1; /* Permit user defined policies */
int noalias = 0; /* Do not do system call aliasing */
int iamroot = 0; /* Set if we are running as root */
+int auto_kill = 0; /* Kill process when policy is violated */
+int erratic = 0; /* Probability of artificial syscall denial */
char cwd[MAXPATHLEN]; /* Current working directory */
char home[MAXPATHLEN]; /* Home directory of user */
char username[LOGIN_NAME_MAX]; /* Username: predicate match and expansion */
@@ -68,6 +71,8 @@ char username[LOGIN_NAME_MAX]; /* Userna
static void child_handler(int);
static void usage(void);
static int requestor_start(char *);
+static int erratic_failure(short *);
+static void seed_erratic(char *);