2006-04-11 21:52:54 +00:00
|
|
|
/*
|
2007-04-11 08:12:51 +00:00
|
|
|
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
|
|
|
|
* NOVELL (All rights reserved)
|
2006-04-11 21:52:54 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of version 2 of the GNU General Public
|
|
|
|
* License published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, contact Novell, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <libintl.h>
|
|
|
|
#define _(s) gettext(s)
|
|
|
|
|
|
|
|
#include "parser.h"
|
|
|
|
|
[https://bugzilla.novell.com/show_bug.cgi?id=172061]
This (updated) patch to trunk adds support for Px and Ux (toggle
bprm_secure on exec) in the parser, As requested, lowercase p and u
corresponds to an unfiltered environmnet on exec, uppercase will filter
the environment. It applies after the 'm' patch.
As a side effect, I tried to reduce the use of hardcoded characters in
the debugging statements -- there are still a few warnings that have
hard coded letters in them; not sure I can fix them all.
This version issues a warning for every unsafe ux and issues a single
warning for the first 'R', 'W', 'X', 'L', and 'I' it encounters,
except when the "-q" or "--quiet" flag , "--remove" profile flag, or
"-N" report names flags are passed. Unfortunately, it made the logic
somewhat more convoluted. Wordsmithing improvements welcome.
2006-08-04 17:14:49 +00:00
|
|
|
|
2006-04-11 21:52:54 +00:00
|
|
|
static int file_comp(const void *c1, const void *c2)
|
|
|
|
{
|
|
|
|
struct cod_entry **e1, **e2;
|
|
|
|
e1 = (struct cod_entry **)c1;
|
|
|
|
e2 = (struct cod_entry **)c2;
|
2007-11-16 09:18:48 +00:00
|
|
|
int res = 0;
|
|
|
|
|
2006-04-11 21:52:54 +00:00
|
|
|
//PERROR("strcmp %s %s\n", (*e1)->name, (*e2)->name);
|
2007-11-16 09:18:48 +00:00
|
|
|
if ((*e1)->namespace) {
|
|
|
|
if ((*e2)->namespace)
|
|
|
|
res = strcmp((*e1)->namespace, (*e2)->namespace);
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
} else if ((*e2)->namespace) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
2007-12-20 12:58:59 +00:00
|
|
|
if ((*e1)->link_name) {
|
|
|
|
if ((*e2)->link_name)
|
|
|
|
res = strcmp((*e1)->link_name, (*e2)->link_name);
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
} else if ((*e2)->link_name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
2008-03-13 16:49:10 +00:00
|
|
|
if ((*e1)->link_name)
|
|
|
|
res = (*e2)->subset - (*e1)->subset;
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
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
|
|
|
if ((*e1)->deny != (*e2)->deny)
|
|
|
|
return (*e1)->deny < (*e2)->deny ? -1 : 1;
|
|
|
|
|
2008-04-09 23:56:31 +00:00
|
|
|
/* rules with ptrace and change_profile can only merge with
|
|
|
|
* rules with exact same perm */
|
|
|
|
if (((*e1)->mode & (AA_CHANGE_PROFILE | AA_PTRACE_PERMS)) !=
|
|
|
|
((*e2)->mode & (AA_CHANGE_PROFILE | AA_PTRACE_PERMS)))
|
|
|
|
return 1;
|
|
|
|
|
2006-04-11 21:52:54 +00:00
|
|
|
return strcmp((*e1)->name, (*e2)->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int process_file_entries(struct codomain *cod)
|
|
|
|
{
|
|
|
|
int n, count;
|
|
|
|
struct cod_entry *flist, *cur, *next;
|
|
|
|
struct cod_entry **table;
|
|
|
|
|
|
|
|
for (flist = cod->entries, n = 0; flist; flist = flist->next)
|
|
|
|
n++;
|
|
|
|
|
|
|
|
count = n;
|
|
|
|
if (count < 2)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
table = malloc(sizeof(struct cod_entry *) * (count + 1));
|
|
|
|
if (!table) {
|
|
|
|
PERROR(_("Couldn't merge entries. Out of Memory\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
for (flist = cod->entries; flist; flist = flist->next) {
|
|
|
|
table[n] = flist;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(table, count, sizeof(struct cod_entry *), file_comp);
|
|
|
|
table[count] = NULL;
|
|
|
|
|
[https://bugzilla.novell.com/show_bug.cgi?id=172061]
This (updated) patch to trunk adds support for Px and Ux (toggle
bprm_secure on exec) in the parser, As requested, lowercase p and u
corresponds to an unfiltered environmnet on exec, uppercase will filter
the environment. It applies after the 'm' patch.
As a side effect, I tried to reduce the use of hardcoded characters in
the debugging statements -- there are still a few warnings that have
hard coded letters in them; not sure I can fix them all.
This version issues a warning for every unsafe ux and issues a single
warning for the first 'R', 'W', 'X', 'L', and 'I' it encounters,
except when the "-q" or "--quiet" flag , "--remove" profile flag, or
"-N" report names flags are passed. Unfortunately, it made the logic
somewhat more convoluted. Wordsmithing improvements welcome.
2006-08-04 17:14:49 +00:00
|
|
|
|
2006-04-11 21:52:54 +00:00
|
|
|
/* walk the sorted table merging similar entries */
|
|
|
|
for (cur = table[0], next = table[1], n = 1; next != NULL; n++, next = table[n]) {
|
|
|
|
if (file_comp(&cur, &next) == 0) {
|
|
|
|
/* check for merged x consistency */
|
2007-11-16 09:35:57 +00:00
|
|
|
if (!is_merged_x_consistent(cur->mode, next->mode)) {
|
2011-02-22 03:47:03 -08:00
|
|
|
PERROR(_("profile %s: has merged rule %s with "
|
2011-02-23 14:40:07 -08:00
|
|
|
"conflicting x modifiers\n"),
|
2011-02-22 03:47:03 -08:00
|
|
|
cod->name, cur->name);
|
2006-04-11 21:52:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
//if (next->audit)
|
|
|
|
//fprintf(stderr, "warning: merging rule 0x%x %s\n", next->audit, next->name);
|
2007-11-16 09:27:34 +00:00
|
|
|
cur->mode |= next->mode;
|
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
|
|
|
cur->audit |= next->audit;
|
2006-04-11 21:52:54 +00:00
|
|
|
free(next->name);
|
2007-11-16 09:37:31 +00:00
|
|
|
if (next->link_name)
|
|
|
|
free(next->link_name);
|
2006-04-11 21:52:54 +00:00
|
|
|
free(next);
|
|
|
|
table[n] = NULL;
|
|
|
|
} else {
|
|
|
|
cur = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rebuild the file_entry chain */
|
|
|
|
cur = table[0];
|
|
|
|
for (n = 1; n < count; n++) {
|
|
|
|
if (table[n] != NULL) {
|
|
|
|
cur->next = table[n];
|
|
|
|
cur = table[n];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur->next = NULL;
|
|
|
|
cod->entries = table[0];
|
|
|
|
|
|
|
|
free(table);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int codomain_merge_rules(struct codomain *cod)
|
|
|
|
{
|
|
|
|
if (!process_file_entries(cod))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* XXX return error from this */
|
|
|
|
merge_hat_rules(cod);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
|
|
|
return 0;
|
|
|
|
}
|