Skip to content

Commit f92d542

Browse files
stephensmalleypcmoore
authored andcommitted
selinux: fix avdcache auditing
The per-task avdcache was incorrectly saving and reusing the audited vector computed by avc_audit_required() rather than recomputing based on the currently requested permissions and distinguishing the denied versus allowed cases. As a result, some permission checks were not being audited, e.g. directory write checks after a previously cached directory search check. Cc: stable@vger.kernel.org Fixes: dde3a5d ("selinux: move avdcache to per-task security struct") Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com> [PM: line wrap tweaks] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 1e5a8ee commit f92d542

2 files changed

Lines changed: 14 additions & 21 deletions

File tree

security/selinux/hooks.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,15 +3209,13 @@ static inline int task_avdcache_search(struct task_security_struct *tsec,
32093209
* @tsec: the task's security state
32103210
* @isec: the inode associated with the cache entry
32113211
* @avd: the AVD to cache
3212-
* @audited: the permission audit bitmask to cache
32133212
*
3214-
* Update the AVD cache in @tsec with the @avdc and @audited info associated
3213+
* Update the AVD cache in @tsec with the @avd info associated
32153214
* with @isec.
32163215
*/
32173216
static inline void task_avdcache_update(struct task_security_struct *tsec,
32183217
struct inode_security_struct *isec,
3219-
struct av_decision *avd,
3220-
u32 audited)
3218+
struct av_decision *avd)
32213219
{
32223220
int spot;
32233221

@@ -3229,9 +3227,7 @@ static inline void task_avdcache_update(struct task_security_struct *tsec,
32293227
spot = (tsec->avdcache.dir_spot + 1) & (TSEC_AVDC_DIR_SIZE - 1);
32303228
tsec->avdcache.dir_spot = spot;
32313229
tsec->avdcache.dir[spot].isid = isec->sid;
3232-
tsec->avdcache.dir[spot].audited = audited;
3233-
tsec->avdcache.dir[spot].allowed = avd->allowed;
3234-
tsec->avdcache.dir[spot].permissive = avd->flags & AVD_FLAGS_PERMISSIVE;
3230+
tsec->avdcache.dir[spot].avd = *avd;
32353231
tsec->avdcache.permissive_neveraudit =
32363232
(avd->flags == (AVD_FLAGS_PERMISSIVE|AVD_FLAGS_NEVERAUDIT));
32373233
}
@@ -3252,6 +3248,7 @@ static int selinux_inode_permission(struct inode *inode, int requested)
32523248
struct task_security_struct *tsec;
32533249
struct inode_security_struct *isec;
32543250
struct avdc_entry *avdc;
3251+
struct av_decision avd, *avdp = &avd;
32553252
int rc, rc2;
32563253
u32 audited, denied;
32573254

@@ -3273,23 +3270,21 @@ static int selinux_inode_permission(struct inode *inode, int requested)
32733270
rc = task_avdcache_search(tsec, isec, &avdc);
32743271
if (likely(!rc)) {
32753272
/* Cache hit. */
3276-
audited = perms & avdc->audited;
3277-
denied = perms & ~avdc->allowed;
3278-
if (unlikely(denied && enforcing_enabled() &&
3279-
!avdc->permissive))
3273+
avdp = &avdc->avd;
3274+
denied = perms & ~avdp->allowed;
3275+
if (unlikely(denied) && enforcing_enabled() &&
3276+
!(avdp->flags & AVD_FLAGS_PERMISSIVE))
32803277
rc = -EACCES;
32813278
} else {
3282-
struct av_decision avd;
3283-
32843279
/* Cache miss. */
32853280
rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass,
3286-
perms, 0, &avd);
3287-
audited = avc_audit_required(perms, &avd, rc,
3288-
(requested & MAY_ACCESS) ? FILE__AUDIT_ACCESS : 0,
3289-
&denied);
3290-
task_avdcache_update(tsec, isec, &avd, audited);
3281+
perms, 0, avdp);
3282+
task_avdcache_update(tsec, isec, avdp);
32913283
}
32923284

3285+
audited = avc_audit_required(perms, avdp, rc,
3286+
(requested & MAY_ACCESS) ?
3287+
FILE__AUDIT_ACCESS : 0, &denied);
32933288
if (likely(!audited))
32943289
return rc;
32953290

security/selinux/include/objsec.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232

3333
struct avdc_entry {
3434
u32 isid; /* inode SID */
35-
u32 allowed; /* allowed permission bitmask */
36-
u32 audited; /* audited permission bitmask */
37-
bool permissive; /* AVC permissive flag */
35+
struct av_decision avd; /* av decision */
3836
};
3937

4038
struct cred_security_struct {

0 commit comments

Comments
 (0)