]> www.infradead.org Git - users/hch/block.git/commitdiff
apparmor: unpack transition table if dfa is not present
authorGeorgia Garcia <georgia.garcia@canonical.com>
Mon, 10 Jun 2024 12:51:48 +0000 (09:51 -0300)
committerJohn Johansen <john.johansen@canonical.com>
Wed, 24 Jul 2024 18:15:06 +0000 (11:15 -0700)
Due to a bug in earlier userspaces, a transition table may be present
even when the dfa is not. Commit 7572fea31e3e
("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: 7572fea31e3e ("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>
security/apparmor/policy_unpack.c

index 75452acd0e3523168ba23be2d4b21b7166148bbf..5a570235427d87cb8cc7513abb77a7891a7ab246 100644 (file)
@@ -747,34 +747,42 @@ static int unpack_pdb(struct aa_ext *e, struct aa_policydb **policy,
                        *info = "missing required dfa";
                        goto fail;
                }
-               goto out;
+       } else {
+               /*
+                * only unpack the following if a dfa is present
+                *
+                * sadly start was given different names for file and policydb
+                * but since it is optional we can try both
+                */
+               if (!aa_unpack_u32(e, &pdb->start[0], "start"))
+                       /* default start state */
+                       pdb->start[0] = DFA_START;
+               if (!aa_unpack_u32(e, &pdb->start[AA_CLASS_FILE], "dfa_start")) {
+                       /* default start state for xmatch and file dfa */
+                       pdb->start[AA_CLASS_FILE] = DFA_START;
+               }       /* setup class index */
+               for (i = AA_CLASS_FILE + 1; i <= AA_CLASS_LAST; i++) {
+                       pdb->start[i] = aa_dfa_next(pdb->dfa, pdb->start[0],
+                                                   i);
+               }
        }
 
        /*
-        * only unpack the following if a dfa is present
-        *
-        * sadly start was given different names for file and policydb
-        * but since it is optional we can try both
+        * Unfortunately due to a bug in earlier userspaces, a
+        * transition table may be present even when the dfa is
+        * not. For compatibility reasons unpack and discard.
         */
-       if (!aa_unpack_u32(e, &pdb->start[0], "start"))
-               /* default start state */
-               pdb->start[0] = DFA_START;
-       if (!aa_unpack_u32(e, &pdb->start[AA_CLASS_FILE], "dfa_start")) {
-               /* default start state for xmatch and file dfa */
-               pdb->start[AA_CLASS_FILE] = DFA_START;
-       }       /* setup class index */
-       for (i = AA_CLASS_FILE + 1; i <= AA_CLASS_LAST; i++) {
-               pdb->start[i] = aa_dfa_next(pdb->dfa, pdb->start[0],
-                                              i);
-       }
        if (!unpack_trans_table(e, &pdb->trans) && required_trans) {
                *info = "failed to unpack profile transition table";
                goto fail;
        }
 
+       if (!pdb->dfa && pdb->trans.table)
+               aa_free_str_table(&pdb->trans);
+
        /* TODO: move compat mapping here, requires dfa merging first */
        /* TODO: move verify here, it has to be done after compat mappings */
-out:
+
        *policy = pdb;
        return 0;