Skip to content

Commit 201588a

Browse files
libsepol,checkpolicy: introduce neveraudit types
Introduce neveraudit types i.e. types that should never trigger audit messages. This allows the AVC to skip all audit-related processing for such types. Note that neveraudit differs from dontaudit not only wrt being applied for all checks with a given source type but also in that it disables all auditing, not just permission denials. When a type is both a permissive type and a neveraudit type, the security server can short-circuit the security_compute_av() logic, allowing all permissions and not auditing any permissions. Signed-off-by: Stephen Smalley <[email protected]>
1 parent 50bafc3 commit 201588a

38 files changed

+495
-18
lines changed

checkpolicy/policy_define.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,49 @@ int define_permissive(void)
257257
return rc;
258258
}
259259

260+
int define_neveraudit(void)
261+
{
262+
char *type = NULL;
263+
struct type_datum *t;
264+
int rc = 0;
265+
266+
type = queue_remove(id_queue);
267+
268+
if (!type) {
269+
yyerror2("forgot to include type in neveraudit definition?");
270+
rc = -1;
271+
goto out;
272+
}
273+
274+
if (pass == 1)
275+
goto out;
276+
277+
if (!is_id_in_scope(SYM_TYPES, type)) {
278+
yyerror2("type %s is not within scope", type);
279+
rc = -1;
280+
goto out;
281+
}
282+
283+
t = hashtab_search(policydbp->p_types.table, type);
284+
if (!t) {
285+
yyerror2("type is not defined: %s", type);
286+
rc = -1;
287+
goto out;
288+
}
289+
290+
if (t->flavor == TYPE_ATTRIB) {
291+
yyerror2("attributes may not be neveraudit: %s", type);
292+
rc = -1;
293+
goto out;
294+
}
295+
296+
t->flags |= TYPE_FLAGS_NEVERAUDIT;
297+
298+
out:
299+
free(type);
300+
return rc;
301+
}
302+
260303
int define_polcap(void)
261304
{
262305
char *id = 0;

checkpolicy/policy_define.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int define_ipv6_cidr_node_context(void);
4545
int define_level(void);
4646
int define_netif_context(void);
4747
int define_permissive(void);
48+
int define_neveraudit(void);
4849
int define_polcap(void);
4950
int define_ibpkey_context(unsigned int low, unsigned int high);
5051
int define_ibendport_context(unsigned int port);

checkpolicy/policy_parse.y

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ typedef int (* require_func_t)(int pass);
152152
%token MODULE VERSION_IDENTIFIER REQUIRE OPTIONAL
153153
%token POLICYCAP
154154
%token PERMISSIVE
155+
%token NEVERAUDIT
155156
%token FILESYSTEM
156157
%token DEFAULT_USER DEFAULT_ROLE DEFAULT_TYPE DEFAULT_RANGE
157158
%token LOW_HIGH LOW HIGH GLBLUB
@@ -330,6 +331,7 @@ te_decl : attribute_def
330331
| range_trans_def
331332
| te_avtab_def
332333
| permissive_def
334+
| neveraudit_def
333335
;
334336
attribute_def : ATTRIBUTE identifier ';'
335337
{ if (define_attrib()) YYABORT;}
@@ -934,6 +936,8 @@ policycap_def : POLICYCAP identifier ';'
934936
;
935937
permissive_def : PERMISSIVE identifier ';'
936938
{if (define_permissive()) YYABORT;}
939+
neveraudit_def : NEVERAUDIT identifier ';'
940+
{if (define_neveraudit()) YYABORT;}
937941

938942
/*********** module grammar below ***********/
939943

checkpolicy/policy_scan.l

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ policycap |
271271
POLICYCAP { return(POLICYCAP); }
272272
permissive |
273273
PERMISSIVE { return(PERMISSIVE); }
274+
neveraudit |
275+
NEVERAUDIT { return(NEVERAUDIT); }
274276
default_user |
275277
DEFAULT_USER { return(DEFAULT_USER); }
276278
default_role |

checkpolicy/tests/policy_allonce.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ auditallowxperm TYPE1 TYPE2 : CLASS1 ioctl 0x2;
4545
dontauditxperm TYPE1 TYPE2 : CLASS1 ioctl 0x3;
4646
neverallowxperm TYPE1 TYPE2 : CLASS1 ioctl 0x4;
4747
permissive TYPE1;
48+
neveraudit TYPE1;
4849
attribute_role ROLE_ATTR1;
4950
role ROLE1;
5051
role ROLE3;

checkpolicy/tests/policy_allonce.expected.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typealias TYPE4 alias TYPEALIAS4;
3131
typebounds TYPE4 TYPE3;
3232
typeattribute TYPE4 ATTR2;
3333
permissive TYPE1;
34+
neveraudit TYPE1;
3435
allow TYPE1 self:CLASS1 { PERM1 };
3536
allow TYPE1 self:CLASS2 { CPERM1 };
3637
auditallow TYPE1 TYPE3:CLASS1 { PERM1 };

checkpolicy/tests/policy_allonce.expected_opt.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typealias TYPE4 alias TYPEALIAS4;
3131
typebounds TYPE4 TYPE3;
3232
typeattribute TYPE4 ATTR2;
3333
permissive TYPE1;
34+
neveraudit TYPE1;
3435
allow TYPE1 self:CLASS1 { PERM1 };
3536
allow TYPE1 self:CLASS2 { CPERM1 };
3637
auditallow TYPE1 TYPE3:CLASS1 { PERM1 };

checkpolicy/tests/policy_allonce_mls.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ auditallowxperm TYPE1 TYPE2 : CLASS1 ioctl 0x2;
5353
dontauditxperm TYPE1 TYPE2 : CLASS1 ioctl 0x3;
5454
neverallowxperm TYPE1 TYPE2 : CLASS1 ioctl 0x4;
5555
permissive TYPE1;
56+
neveraudit TYPE1;
5657
attribute_role ROLE_ATTR1;
5758
role ROLE1;
5859
role ROLE3;

checkpolicy/tests/policy_allonce_mls.expected.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ typealias TYPE4 alias TYPEALIAS4;
3939
typebounds TYPE4 TYPE3;
4040
typeattribute TYPE4 ATTR2;
4141
permissive TYPE1;
42+
neveraudit TYPE1;
4243
allow TYPE1 self:CLASS1 { PERM1 };
4344
allow TYPE1 self:CLASS2 { CPERM1 };
4445
auditallow TYPE1 TYPE3:CLASS1 { PERM1 };

checkpolicy/tests/policy_allonce_mls.expected_opt.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ typealias TYPE4 alias TYPEALIAS4;
3939
typebounds TYPE4 TYPE3;
4040
typeattribute TYPE4 ATTR2;
4141
permissive TYPE1;
42+
neveraudit TYPE1;
4243
allow TYPE1 self:CLASS1 { PERM1 };
4344
allow TYPE1 self:CLASS2 { CPERM1 };
4445
auditallow TYPE1 TYPE3:CLASS1 { PERM1 };

0 commit comments

Comments
 (0)