Skip to content
/ linux Public

Commit 15c3eb8

Browse files
m-pellizzergregkh
authored andcommitted
apparmor: validate DFA start states are in bounds in unpack_pdb
commit 9063d7e upstream. Start states are read from untrusted data and used as indexes into the DFA state tables. The aa_dfa_next() function call in unpack_pdb() will access dfa->tables[YYTD_ID_BASE][start], and if the start state exceeds the number of states in the DFA, this results in an out-of-bound read. ================================================================== BUG: KASAN: slab-out-of-bounds in aa_dfa_next+0x2a1/0x360 Read of size 4 at addr ffff88811956fb90 by task su/1097 ... Reject policies with out-of-bounds start states during unpacking to prevent the issue. Fixes: ad5ff3d ("AppArmor: Add ability to load extended policy") Reported-by: Qualys Security Advisory <qsa@qualys.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Reviewed-by: Georgia Garcia <georgia.garcia@canonical.com> Reviewed-by: Cengiz Can <cengiz.can@canonical.com> Signed-off-by: Massimiliano Pellizzer <massimiliano.pellizzer@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 524ce8b commit 15c3eb8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

security/apparmor/policy_unpack.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,17 @@ static int unpack_pdb(struct aa_ext *e, struct aa_policydb **policy,
762762
if (!aa_unpack_u32(e, &pdb->start[AA_CLASS_FILE], "dfa_start")) {
763763
/* default start state for xmatch and file dfa */
764764
pdb->start[AA_CLASS_FILE] = DFA_START;
765-
} /* setup class index */
765+
}
766+
767+
size_t state_count = pdb->dfa->tables[YYTD_ID_BASE]->td_lolen;
768+
769+
if (pdb->start[0] >= state_count ||
770+
pdb->start[AA_CLASS_FILE] >= state_count) {
771+
*info = "invalid dfa start state";
772+
goto fail;
773+
}
774+
775+
/* setup class index */
766776
for (i = AA_CLASS_FILE + 1; i <= AA_CLASS_LAST; i++) {
767777
pdb->start[i] = aa_dfa_next(pdb->dfa, pdb->start[0],
768778
i);

0 commit comments

Comments
 (0)