Skip to content

Commit b824b5f

Browse files
canonical-rlee287jrjohansen
authored andcommitted
apparmor: include conflicting attachment info for confined ix/ux fallback
Instead of silently overwriting the conflicting profile attachment string, include that information in the ix/ux fallback string that gets set as info instead. Also add a warning print if some other info is set that would be overwritten by the ix/ux fallback string or by the profile not found error. Signed-off-by: Ryan Lee <ryan.lee@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent e76d733 commit b824b5f

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

security/apparmor/domain.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include "include/policy_ns.h"
3030

3131
static const char * const CONFLICTING_ATTACH_STR = "conflicting profile attachments";
32+
static const char * const CONFLICTING_ATTACH_STR_IX =
33+
"conflicting profile attachments - ix fallback";
34+
static const char * const CONFLICTING_ATTACH_STR_UX =
35+
"conflicting profile attachments - ux fallback";
3236

3337
/**
3438
* may_change_ptraced_domain - check if can change profile on ptraced task
@@ -577,6 +581,8 @@ static struct aa_label *x_to_label(struct aa_profile *profile,
577581
struct aa_label *stack = NULL;
578582
struct aa_ns *ns = profile->ns;
579583
u32 xtype = xindex & AA_X_TYPE_MASK;
584+
/* Used for info checks during fallback handling */
585+
const char *old_info = NULL;
580586

581587
switch (xtype) {
582588
case AA_X_NONE:
@@ -613,12 +619,32 @@ static struct aa_label *x_to_label(struct aa_profile *profile,
613619
/* (p|c|n)ix - don't change profile but do
614620
* use the newest version
615621
*/
616-
*info = "ix fallback";
622+
if (*info == CONFLICTING_ATTACH_STR) {
623+
*info = CONFLICTING_ATTACH_STR_IX;
624+
} else {
625+
old_info = *info;
626+
*info = "ix fallback";
627+
}
617628
/* no profile && no error */
618629
new = aa_get_newest_label(&profile->label);
619630
} else if (xindex & AA_X_UNCONFINED) {
620631
new = aa_get_newest_label(ns_unconfined(profile->ns));
621-
*info = "ux fallback";
632+
if (*info == CONFLICTING_ATTACH_STR) {
633+
*info = CONFLICTING_ATTACH_STR_UX;
634+
} else {
635+
old_info = *info;
636+
*info = "ux fallback";
637+
}
638+
}
639+
/* We set old_info on the code paths above where overwriting
640+
* could have happened, so now check if info was set by
641+
* find_attach as well (i.e. whether we actually overwrote)
642+
* and warn accordingly.
643+
*/
644+
if (old_info && old_info != CONFLICTING_ATTACH_STR) {
645+
pr_warn_ratelimited(
646+
"AppArmor: find_attach (from profile %s) audit info \"%s\" dropped",
647+
profile->base.hname, old_info);
622648
}
623649
}
624650

@@ -706,6 +732,11 @@ static struct aa_label *profile_transition(const struct cred *subj_cred,
706732
/* hack ix fallback - improve how this is detected */
707733
goto audit;
708734
} else if (!new) {
735+
if (info) {
736+
pr_warn_ratelimited(
737+
"AppArmor: %s (from profile %s) audit info \"%s\" dropped on missing transition",
738+
__func__, profile->base.hname, info);
739+
}
709740
info = "profile transition not found";
710741
/* remove MAY_EXEC to audit as failure or complaint */
711742
perms.allow &= ~MAY_EXEC;

0 commit comments

Comments
 (0)