if (unlikely(AUDIT_MODE(profile) == AUDIT_ALL))
mask = 0xffff;
/* mask off perms that are not being force audited */
ad.request &= mask;
if (likely(!ad.request)) return 0;
type = AUDIT_APPARMOR_AUDIT;
} else { /* only report permissions that were denied */
ad.request = ad.request & ~perms->allow;
AA_BUG(!ad.request);
if (ad.request & perms->kill)
type = AUDIT_APPARMOR_KILL;
/* quiet known rejects, assumes quiet and kill do not overlap */ if ((ad.request & perms->quiet) &&
AUDIT_MODE(profile) != AUDIT_NOQUIET &&
AUDIT_MODE(profile) != AUDIT_ALL)
ad.request &= ~perms->quiet;
struct aa_perms default_perms = {}; /** * aa_lookup_condperms - convert dfa compressed perms to internal perms * @subj_uid: uid to use for subject owner test * @rules: the aa_policydb to lookup perms for (NOT NULL) * @state: state in dfa * @cond: conditions to consider (NOT NULL) * * TODO: convert from dfa + state to permission entry * * Returns: a pointer to a file permission set
*/ struct aa_perms *aa_lookup_condperms(kuid_t subj_uid, struct aa_policydb *rules,
aa_state_t state, struct path_cond *cond)
{ unsignedint index = ACCEPT_TABLE(rules->dfa)[state];
if (!(rules->perms)) return &default_perms;
if ((ACCEPT_TABLE2(rules->dfa)[state] & ACCEPT_FLAG_OWNER)) { if (uid_eq(subj_uid, cond->uid)) return &(rules->perms[index]); return &(rules->perms[index + 1]);
}
return &(rules->perms[index]);
}
/** * aa_str_perms - find permission that match @name * @file_rules: the aa_policydb to match against (NOT NULL) * @start: state to start matching in * @name: string to match against dfa (NOT NULL) * @cond: conditions to consider for permission set computation (NOT NULL) * @perms: Returns - the permissions found when matching @name * * Returns: the final state in @dfa when beginning @start and walking @name
*/
aa_state_t aa_str_perms(struct aa_policydb *file_rules, aa_state_t start, constchar *name, struct path_cond *cond, struct aa_perms *perms)
{
aa_state_t state;
state = aa_dfa_match(file_rules->dfa, start, name);
*perms = *(aa_lookup_condperms(current_fsuid(), file_rules, state,
cond));
return state;
}
int __aa_path_perm(constchar *op, conststruct cred *subj_cred, struct aa_profile *profile, constchar *name,
u32 request, struct path_cond *cond, int flags, struct aa_perms *perms)
{ struct aa_ruleset *rules = profile->label.rules[0]; int e = 0;
/** * xindex_is_subset - helper for aa_path_link * @link: link permission set * @target: target permission set * * test target x permissions are equal OR a subset of link x permissions * this is done as part of the subset test, where a hardlink must have * a subset of permissions that the target has. * * Returns: true if subset else false
*/ staticinlinebool xindex_is_subset(u32 link, u32 target)
{ if (((link & ~AA_X_UNSAFE) != (target & ~AA_X_UNSAFE)) ||
((link & AA_X_UNSAFE) && !(target & AA_X_UNSAFE))) returnfalse;
/* buffer2 freed below, tname is pointer in buffer2 */
error = path_name(OP_LINK, subj_cred, &profile->label, target,
profile->path_flags,
buffer2, &tname, cond, AA_MAY_LINK); if (error) goto audit;
error = -EACCES; /* aa_str_perms - handles the case of the dfa being NULL */
state = aa_str_perms(rules->file,
rules->file->start[AA_CLASS_FILE], lname,
cond, &lperms);
if (!(lperms.allow & AA_MAY_LINK)) goto audit;
/* test to see if target can be paired with link */
state = aa_dfa_null_transition(rules->file->dfa, state);
aa_str_perms(rules->file, state, tname, cond, &perms);
/* force audit/quiet masks for link are stored in the second entry * in the link pair.
*/
lperms.audit = perms.audit;
lperms.quiet = perms.quiet;
lperms.kill = perms.kill;
if (!(perms.allow & AA_MAY_LINK)) {
info = "target restricted";
lperms = perms; goto audit;
}
/* done if link subset test is not required */ if (!(perms.allow & AA_LINK_SUBSET)) goto done_tests;
/* Do link perm subset test requiring allowed permission on link are * a subset of the allowed permissions on target.
*/
aa_str_perms(rules->file, rules->file->start[AA_CLASS_FILE],
tname, cond, &perms);
/* AA_MAY_LINK is not considered in the subset test */
request = lperms.allow & ~AA_MAY_LINK;
lperms.allow &= perms.allow | AA_MAY_LINK;
request |= AA_AUDIT_FILE_MASK & (lperms.allow & ~perms.allow); if (request & ~lperms.allow) { goto audit;
} elseif ((lperms.allow & MAY_EXEC) &&
!xindex_is_subset(lperms.xindex, perms.xindex)) {
lperms.allow &= ~MAY_EXEC;
request |= MAY_EXEC;
info = "link not subset of target"; goto audit;
}
/** * aa_path_link - Handle hard link permission check * @subj_cred: subject cred * @label: the label being enforced (NOT NULL) * @old_dentry: the target dentry (NOT NULL) * @new_dir: directory the new link will be created in (NOT NULL) * @new_dentry: the link being created (NOT NULL) * * Handle the permission test for a link & target pair. Permission * is encoded as a pair where the link permission is determined * first, and if allowed, the target is tested. The target test * is done from the point of the link match (not start of DFA) * making the target permission dependent on the link permission match. * * The subset test if required forces that permissions granted * on link are a subset of the permission granted to target. * * Returns: %0 if allowed else error
*/ int aa_path_link(conststruct cred *subj_cred, struct aa_label *label, struct dentry *old_dentry, conststruct path *new_dir, struct dentry *new_dentry)
{ struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry }; struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry }; struct inode *inode = d_backing_inode(old_dentry);
vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_idmap(target.mnt), inode); struct path_cond cond = {
.uid = vfsuid_into_kuid(vfsuid),
.mode = inode->i_mode,
}; char *buffer = NULL, *buffer2 = NULL; struct aa_profile *profile; int error;
/* buffer freed below, lname is pointer in buffer */
buffer = aa_get_buffer(false);
buffer2 = aa_get_buffer(false);
error = -ENOMEM; if (!buffer || !buffer2) goto out;
/* revalidation due to label out of date. No revocation at this time */ if (!denied && aa_label_is_subset(flabel, label)) /* TODO: check for revocation on stale profiles */ return 0;
/* check every profile in task label not in current cache */
error = fn_for_each_not_in_set(flabel, label, profile,
profile_path_perm(op, subj_cred, profile,
&file->f_path, buffer,
request, &cond, flags, &perms)); if (denied && !error) { /* * check every profile in file label that was not tested * in the initial check above. * * TODO: cache full perms so this only happens because of * conditionals * TODO: don't audit here
*/ if (label == flabel)
error = fn_for_each(label, profile,
profile_path_perm(op, subj_cred,
profile, &file->f_path,
buffer, request, &cond, flags,
&perms)); else
error = fn_for_each_not_in_set(label, flabel, profile,
profile_path_perm(op, subj_cred,
profile, &file->f_path,
buffer, request, &cond, flags,
&perms));
} if (!error)
update_file_ctx(file_ctx(file), label, request);
/* revalidation due to label out of date. No revocation at this time */ if (!denied && aa_label_is_subset(flabel, label)) return 0;
/* TODO: improve to skip profiles cached in flabel */
error = aa_sock_file_perm(subj_cred, label, op, request, file); if (denied) { /* TODO: improve to skip profiles checked above */ /* check every profile in file label to is cached */
last_error(error, aa_sock_file_perm(subj_cred, flabel, op,
request, file));
} if (!error)
update_file_ctx(file_ctx(file), label, request);
return error;
}
/* for now separate fn to indicate semantics of the check */ staticbool __file_is_delegated(struct aa_label *obj_label)
{ return unconfined(obj_label);
}
/* revalidate access, if task is unconfined, or the cached cred * doesn't match or if the request is for more permissions than * was granted. * * Note: the test for !unconfined(flabel) is to handle file * delegation from unconfined tasks
*/
denied = request & ~fctx->allow; if (unconfined(label) || __file_is_delegated(flabel) ||
__unix_needs_revalidation(file, label, request) ||
(!denied && __aa_subj_label_is_cached(label, flabel))) {
rcu_read_unlock(); goto done;
}
/* Revalidate access to inherited open files. */
n = iterate_fd(files, 0, match_file, &cl); if (!n) /* none found? */ goto out;
devnull = dentry_open(&aa_null, O_RDWR, cred); if (IS_ERR(devnull))
devnull = NULL; /* replace all the matching ones with this */ do {
replace_fd(n - 1, devnull, 0);
} while ((n = iterate_fd(files, n, match_file, &cl)) != 0); if (devnull)
fput(devnull);
out:
aa_put_label(label);
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.