Skip to content

Commit b17ec22

Browse files
Al Viropcmoore
authored andcommitted
selinux: slow_avc_audit has become non-blocking
dump_common_audit_data() is safe to use under rcu_read_lock() now; no need for AVC_NONBLOCKING and games around it Signed-off-by: Al Viro <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent d0a8331 commit b17ec22

File tree

3 files changed

+10
-35
lines changed

3 files changed

+10
-35
lines changed

security/selinux/avc.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,11 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
759759
}
760760
}
761761

762-
/* This is the slow part of avc audit with big stack footprint */
762+
/*
763+
* This is the slow part of avc audit with big stack footprint.
764+
* Note that it is non-blocking and can be called from under
765+
* rcu_read_lock().
766+
*/
763767
noinline int slow_avc_audit(struct selinux_state *state,
764768
u32 ssid, u32 tsid, u16 tclass,
765769
u32 requested, u32 audited, u32 denied, int result,
@@ -826,7 +830,7 @@ int __init avc_add_callback(int (*callback)(u32 event), u32 events)
826830
* @ssid,@tsid,@tclass : identifier of an AVC entry
827831
* @seqno : sequence number when decision was made
828832
* @xpd: extended_perms_decision to be added to the node
829-
* @flags: the AVC_* flags, e.g. AVC_NONBLOCKING, AVC_EXTENDED_PERMS, or 0.
833+
* @flags: the AVC_* flags, e.g. AVC_EXTENDED_PERMS, or 0.
830834
*
831835
* if a valid AVC entry doesn't exist,this function returns -ENOENT.
832836
* if kmalloc() called internal returns NULL, this function returns -ENOMEM.
@@ -845,21 +849,6 @@ static int avc_update_node(struct selinux_avc *avc,
845849
struct hlist_head *head;
846850
spinlock_t *lock;
847851

848-
/*
849-
* If we are in a non-blocking code path, e.g. VFS RCU walk,
850-
* then we must not add permissions to a cache entry
851-
* because we will not audit the denial. Otherwise,
852-
* during the subsequent blocking retry (e.g. VFS ref walk), we
853-
* will find the permissions already granted in the cache entry
854-
* and won't audit anything at all, leading to silent denials in
855-
* permissive mode that only appear when in enforcing mode.
856-
*
857-
* See the corresponding handling of MAY_NOT_BLOCK in avc_audit()
858-
* and selinux_inode_permission().
859-
*/
860-
if (flags & AVC_NONBLOCKING)
861-
return 0;
862-
863852
node = avc_alloc_node(avc);
864853
if (!node) {
865854
rc = -ENOMEM;
@@ -1120,7 +1109,7 @@ int avc_has_extended_perms(struct selinux_state *state,
11201109
* @tsid: target security identifier
11211110
* @tclass: target security class
11221111
* @requested: requested permissions, interpreted based on @tclass
1123-
* @flags: AVC_STRICT, AVC_NONBLOCKING, or 0
1112+
* @flags: AVC_STRICT or 0
11241113
* @avd: access vector decisions
11251114
*
11261115
* Check the AVC to determine whether the @requested permissions are granted
@@ -1205,8 +1194,7 @@ int avc_has_perm_flags(struct selinux_state *state,
12051194
struct av_decision avd;
12061195
int rc, rc2;
12071196

1208-
rc = avc_has_perm_noaudit(state, ssid, tsid, tclass, requested,
1209-
(flags & MAY_NOT_BLOCK) ? AVC_NONBLOCKING : 0,
1197+
rc = avc_has_perm_noaudit(state, ssid, tsid, tclass, requested, 0,
12101198
&avd);
12111199

12121200
rc2 = avc_audit(state, ssid, tsid, tclass, requested, &avd, rc,

security/selinux/hooks.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,17 +3164,13 @@ static noinline int audit_inode_permission(struct inode *inode,
31643164
{
31653165
struct common_audit_data ad;
31663166
struct inode_security_struct *isec = selinux_inode(inode);
3167-
int rc;
31683167

31693168
ad.type = LSM_AUDIT_DATA_INODE;
31703169
ad.u.inode = inode;
31713170

3172-
rc = slow_avc_audit(&selinux_state,
3171+
return slow_avc_audit(&selinux_state,
31733172
current_sid(), isec->sid, isec->sclass, perms,
31743173
audited, denied, result, &ad);
3175-
if (rc)
3176-
return rc;
3177-
return 0;
31783174
}
31793175

31803176
static int selinux_inode_permission(struct inode *inode, int mask)
@@ -3209,19 +3205,14 @@ static int selinux_inode_permission(struct inode *inode, int mask)
32093205
return PTR_ERR(isec);
32103206

32113207
rc = avc_has_perm_noaudit(&selinux_state,
3212-
sid, isec->sid, isec->sclass, perms,
3213-
no_block ? AVC_NONBLOCKING : 0,
3208+
sid, isec->sid, isec->sclass, perms, 0,
32143209
&avd);
32153210
audited = avc_audit_required(perms, &avd, rc,
32163211
from_access ? FILE__AUDIT_ACCESS : 0,
32173212
&denied);
32183213
if (likely(!audited))
32193214
return rc;
32203215

3221-
/* fall back to ref-walk if we have to generate audit */
3222-
if (no_block)
3223-
return -ECHILD;
3224-
32253216
rc2 = audit_inode_permission(inode, perms, audited, denied, rc);
32263217
if (rc2)
32273218
return rc2;

security/selinux/include/avc.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,13 @@ static inline int avc_audit(struct selinux_state *state,
134134
audited = avc_audit_required(requested, avd, result, 0, &denied);
135135
if (likely(!audited))
136136
return 0;
137-
/* fall back to ref-walk if we have to generate audit */
138-
if (flags & MAY_NOT_BLOCK)
139-
return -ECHILD;
140137
return slow_avc_audit(state, ssid, tsid, tclass,
141138
requested, audited, denied, result,
142139
a);
143140
}
144141

145142
#define AVC_STRICT 1 /* Ignore permissive mode. */
146143
#define AVC_EXTENDED_PERMS 2 /* update extended permissions */
147-
#define AVC_NONBLOCKING 4 /* non blocking */
148144
int avc_has_perm_noaudit(struct selinux_state *state,
149145
u32 ssid, u32 tsid,
150146
u16 tclass, u32 requested,

0 commit comments

Comments
 (0)