apparmor: don't check for vmalloc_addr if kvzalloc() failed
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / security / apparmor / match.c
index 90971a8c37898256b1d60b211bdf27865d1f75e4..10d824bc35772dbf13d51a67e4775713000da2d2 100644 (file)
@@ -45,6 +45,8 @@ static struct table_header *unpack_table(char *blob, size_t bsize)
         * it every time we use td_id as an index
         */
        th.td_id = be16_to_cpu(*(u16 *) (blob)) - 1;
+       if (th.td_id > YYTD_ID_MAX)
+               goto out;
        th.td_flags = be16_to_cpu(*(u16 *) (blob + 2));
        th.td_lolen = be32_to_cpu(*(u32 *) (blob + 8));
        blob += sizeof(struct table_header);
@@ -71,14 +73,14 @@ static struct table_header *unpack_table(char *blob, size_t bsize)
                                     u32, be32_to_cpu);
                else
                        goto fail;
+               /* if table was vmalloced make sure the page tables are synced
+                * before it is used, as it goes live to all cpus.
+                */
+               if (is_vmalloc_addr(table))
+                       vm_unmap_aliases();
        }
 
 out:
-       /* if table was vmalloced make sure the page tables are synced
-        * before it is used, as it goes live to all cpus.
-        */
-       if (is_vmalloc_addr(table))
-               vm_unmap_aliases();
        return table;
 fail:
        kvfree(table);