Skip to content

Commit e0ff0cf

Browse files
gegarciajrjohansen
authored andcommitted
apparmor: unpack transition table if dfa is not present
Due to a bug in earlier userspaces, a transition table may be present even when the dfa is not. Commit 7572fea ("apparmor: convert fperm lookup to use accept as an index") made the verification check more rigourous regressing old userspaces with the bug. For compatibility reasons allow the orphaned transition table during unpack and discard. Fixes: 7572fea ("apparmor: convert fperm lookup to use accept as an index") Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent f4fee21 commit e0ff0cf

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

security/apparmor/policy_unpack.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -747,34 +747,42 @@ static int unpack_pdb(struct aa_ext *e, struct aa_policydb **policy,
747747
*info = "missing required dfa";
748748
goto fail;
749749
}
750-
goto out;
750+
} else {
751+
/*
752+
* only unpack the following if a dfa is present
753+
*
754+
* sadly start was given different names for file and policydb
755+
* but since it is optional we can try both
756+
*/
757+
if (!aa_unpack_u32(e, &pdb->start[0], "start"))
758+
/* default start state */
759+
pdb->start[0] = DFA_START;
760+
if (!aa_unpack_u32(e, &pdb->start[AA_CLASS_FILE], "dfa_start")) {
761+
/* default start state for xmatch and file dfa */
762+
pdb->start[AA_CLASS_FILE] = DFA_START;
763+
} /* setup class index */
764+
for (i = AA_CLASS_FILE + 1; i <= AA_CLASS_LAST; i++) {
765+
pdb->start[i] = aa_dfa_next(pdb->dfa, pdb->start[0],
766+
i);
767+
}
751768
}
752769

753770
/*
754-
* only unpack the following if a dfa is present
755-
*
756-
* sadly start was given different names for file and policydb
757-
* but since it is optional we can try both
771+
* Unfortunately due to a bug in earlier userspaces, a
772+
* transition table may be present even when the dfa is
773+
* not. For compatibility reasons unpack and discard.
758774
*/
759-
if (!aa_unpack_u32(e, &pdb->start[0], "start"))
760-
/* default start state */
761-
pdb->start[0] = DFA_START;
762-
if (!aa_unpack_u32(e, &pdb->start[AA_CLASS_FILE], "dfa_start")) {
763-
/* default start state for xmatch and file dfa */
764-
pdb->start[AA_CLASS_FILE] = DFA_START;
765-
} /* setup class index */
766-
for (i = AA_CLASS_FILE + 1; i <= AA_CLASS_LAST; i++) {
767-
pdb->start[i] = aa_dfa_next(pdb->dfa, pdb->start[0],
768-
i);
769-
}
770775
if (!unpack_trans_table(e, &pdb->trans) && required_trans) {
771776
*info = "failed to unpack profile transition table";
772777
goto fail;
773778
}
774779

780+
if (!pdb->dfa && pdb->trans.table)
781+
aa_free_str_table(&pdb->trans);
782+
775783
/* TODO: move compat mapping here, requires dfa merging first */
776784
/* TODO: move verify here, it has to be done after compat mappings */
777-
out:
785+
778786
*policy = pdb;
779787
return 0;
780788

0 commit comments

Comments
 (0)