Skip to content

Commit 1106896

Browse files
stephensmalleypcmoore
authored andcommitted
selinux: 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. This change just introduces the basic support but does not yet further optimize the AVC or hook function logic when a type is both a permissive type and a dontaudit type. Suggested-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 17bd3c0 commit 1106896

5 files changed

Lines changed: 48 additions & 1 deletion

File tree

security/selinux/include/avc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ static inline u32 avc_audit_required(u32 requested, struct av_decision *avd,
6565
int result, u32 auditdeny, u32 *deniedp)
6666
{
6767
u32 denied, audited;
68+
69+
if (avd->flags & AVD_FLAGS_NEVERAUDIT)
70+
return 0;
71+
6872
denied = requested & ~avd->allowed;
6973
if (unlikely(denied)) {
7074
audited = denied & avd->auditdeny;

security/selinux/include/security.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747
#define POLICYDB_VERSION_GLBLUB 32
4848
#define POLICYDB_VERSION_COMP_FTRANS 33 /* compressed filename transitions */
4949
#define POLICYDB_VERSION_COND_XPERMS 34 /* extended permissions in conditional policies */
50+
#define POLICYDB_VERSION_NEVERAUDIT 35 /* neveraudit types */
5051

5152
/* Range of policy versions we understand*/
5253
#define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE
53-
#define POLICYDB_VERSION_MAX POLICYDB_VERSION_COND_XPERMS
54+
#define POLICYDB_VERSION_MAX POLICYDB_VERSION_NEVERAUDIT
5455

5556
/* Mask for just the mount related flags */
5657
#define SE_MNTMASK 0x0f
@@ -260,6 +261,7 @@ struct extended_perms {
260261

261262
/* definitions of av_decision.flags */
262263
#define AVD_FLAGS_PERMISSIVE 0x0001
264+
#define AVD_FLAGS_NEVERAUDIT 0x0002
263265

264266
void security_compute_av(u32 ssid, u32 tsid, u16 tclass,
265267
struct av_decision *avd,

security/selinux/ss/policydb.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ static const struct policydb_compat_info policydb_compat[] = {
160160
.sym_num = SYM_NUM,
161161
.ocon_num = OCON_NUM,
162162
},
163+
{
164+
.version = POLICYDB_VERSION_NEVERAUDIT,
165+
.sym_num = SYM_NUM,
166+
.ocon_num = OCON_NUM,
167+
},
163168
};
164169

165170
static const struct policydb_compat_info *
@@ -531,6 +536,7 @@ static void policydb_init(struct policydb *p)
531536
ebitmap_init(&p->filename_trans_ttypes);
532537
ebitmap_init(&p->policycaps);
533538
ebitmap_init(&p->permissive_map);
539+
ebitmap_init(&p->neveraudit_map);
534540
}
535541

536542
/*
@@ -852,6 +858,7 @@ void policydb_destroy(struct policydb *p)
852858
ebitmap_destroy(&p->filename_trans_ttypes);
853859
ebitmap_destroy(&p->policycaps);
854860
ebitmap_destroy(&p->permissive_map);
861+
ebitmap_destroy(&p->neveraudit_map);
855862
}
856863

857864
/*
@@ -2538,6 +2545,12 @@ int policydb_read(struct policydb *p, struct policy_file *fp)
25382545
goto bad;
25392546
}
25402547

2548+
if (p->policyvers >= POLICYDB_VERSION_NEVERAUDIT) {
2549+
rc = ebitmap_read(&p->neveraudit_map, fp);
2550+
if (rc)
2551+
goto bad;
2552+
}
2553+
25412554
rc = -EINVAL;
25422555
info = policydb_lookup_compat(p->policyvers);
25432556
if (!info) {
@@ -3723,6 +3736,12 @@ int policydb_write(struct policydb *p, struct policy_file *fp)
37233736
return rc;
37243737
}
37253738

3739+
if (p->policyvers >= POLICYDB_VERSION_NEVERAUDIT) {
3740+
rc = ebitmap_write(&p->neveraudit_map, fp);
3741+
if (rc)
3742+
return rc;
3743+
}
3744+
37263745
num_syms = info->sym_num;
37273746
for (i = 0; i < num_syms; i++) {
37283747
struct policy_data pd;

security/selinux/ss/policydb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ struct policydb {
300300

301301
struct ebitmap permissive_map;
302302

303+
struct ebitmap neveraudit_map;
304+
303305
/* length of this policy when it was loaded */
304306
size_t len;
305307

security/selinux/ss/services.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,14 @@ void security_compute_av(u32 ssid,
11531153
if (ebitmap_get_bit(&policydb->permissive_map, scontext->type))
11541154
avd->flags |= AVD_FLAGS_PERMISSIVE;
11551155

1156+
/* neveraudit domain? */
1157+
if (ebitmap_get_bit(&policydb->neveraudit_map, scontext->type))
1158+
avd->flags |= AVD_FLAGS_NEVERAUDIT;
1159+
1160+
/* both permissive and neveraudit => allow */
1161+
if (avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT))
1162+
goto allow;
1163+
11561164
tcontext = sidtab_search(sidtab, tsid);
11571165
if (!tcontext) {
11581166
pr_err("SELinux: %s: unrecognized SID %d\n",
@@ -1172,6 +1180,8 @@ void security_compute_av(u32 ssid,
11721180
policydb->allow_unknown);
11731181
out:
11741182
rcu_read_unlock();
1183+
if (avd->flags & AVD_FLAGS_NEVERAUDIT)
1184+
avd->auditallow = avd->auditdeny = 0;
11751185
return;
11761186
allow:
11771187
avd->allowed = 0xffffffff;
@@ -1208,6 +1218,14 @@ void security_compute_av_user(u32 ssid,
12081218
if (ebitmap_get_bit(&policydb->permissive_map, scontext->type))
12091219
avd->flags |= AVD_FLAGS_PERMISSIVE;
12101220

1221+
/* neveraudit domain? */
1222+
if (ebitmap_get_bit(&policydb->neveraudit_map, scontext->type))
1223+
avd->flags |= AVD_FLAGS_NEVERAUDIT;
1224+
1225+
/* both permissive and neveraudit => allow */
1226+
if (avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT))
1227+
goto allow;
1228+
12111229
tcontext = sidtab_search(sidtab, tsid);
12121230
if (!tcontext) {
12131231
pr_err("SELinux: %s: unrecognized SID %d\n",
@@ -1225,6 +1243,8 @@ void security_compute_av_user(u32 ssid,
12251243
NULL);
12261244
out:
12271245
rcu_read_unlock();
1246+
if (avd->flags & AVD_FLAGS_NEVERAUDIT)
1247+
avd->auditallow = avd->auditdeny = 0;
12281248
return;
12291249
allow:
12301250
avd->allowed = 0xffffffff;

0 commit comments

Comments
 (0)