Skip to content

Commit 74a96bb

Browse files
rlee287jrjohansen
authored andcommitted
apparmor: audit_cap dedup based on subj_cred instead of profile
The previous audit_cap cache deduping was based on the profile that was being audited. This could cause confusion due to the deduplication then occurring across multiple processes, which could happen if multiple instances of binaries matched the same profile attachment (and thus ran under the same profile) or a profile was attached to a container and its processes. Instead, perform audit_cap deduping over ad->subj_cred, which ensures the deduping only occurs across a single process, instead of across all processes that match the current one's profile. Signed-off-by: Ryan Lee <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent fee7a23 commit 74a96bb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

security/apparmor/capability.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct aa_sfs_entry aa_sfs_entry_caps[] = {
3131
};
3232

3333
struct audit_cache {
34-
struct aa_profile *profile;
34+
const struct cred *ad_subj_cred;
3535
/* Capabilities go from 0 to CAP_LAST_CAP */
3636
u64 ktime_ns_expiration[CAP_LAST_CAP+1];
3737
};
@@ -94,16 +94,14 @@ static int audit_caps(struct apparmor_audit_data *ad, struct aa_profile *profile
9494
/* Do simple duplicate message elimination */
9595
ent = &get_cpu_var(audit_cache);
9696
/* If the capability was never raised the timestamp check would also catch that */
97-
if (profile == ent->profile && ktime_get_ns() <= ent->ktime_ns_expiration[cap]) {
97+
if (ad->subj_cred == ent->ad_subj_cred && ktime_get_ns() <= ent->ktime_ns_expiration[cap]) {
9898
put_cpu_var(audit_cache);
9999
if (COMPLAIN_MODE(profile))
100100
return complain_error(error);
101101
return error;
102102
} else {
103-
aa_put_profile(ent->profile);
104-
if (profile != ent->profile)
105-
cap_clear(ent->caps);
106-
ent->profile = aa_get_profile(profile);
103+
put_cred(ent->ad_subj_cred);
104+
ent->ad_subj_cred = get_cred(ad->subj_cred);
107105
ent->ktime_ns_expiration[cap] = ktime_get_ns() + AUDIT_CACHE_TIMEOUT_NS;
108106
}
109107
put_cpu_var(audit_cache);

0 commit comments

Comments
 (0)