powerpc/mm: Validate address values against different region limits
authorAneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Wed, 17 Apr 2019 12:59:15 +0000 (18:29 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 21 Apr 2019 13:12:39 +0000 (23:12 +1000)
This adds an explicit check in various functions.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/mm/hash_utils_64.c
arch/powerpc/mm/pgtable-hash64.c
arch/powerpc/mm/pgtable-radix.c
arch/powerpc/mm/pgtable_64.c

index 9c4ae4aa133e57d08c0eef1d4e0eed64bc8df59a..f727197de7139a88c9acad8336974828c0415538 100644 (file)
@@ -781,9 +781,16 @@ int resize_hpt_for_hotplug(unsigned long new_mem_size)
 
 int hash__create_section_mapping(unsigned long start, unsigned long end, int nid)
 {
-       int rc = htab_bolt_mapping(start, end, __pa(start),
-                                  pgprot_val(PAGE_KERNEL), mmu_linear_psize,
-                                  mmu_kernel_ssize);
+       int rc;
+
+       if (end >= H_VMALLOC_START) {
+               pr_warn("Outisde the supported range\n");
+               return -1;
+       }
+
+       rc = htab_bolt_mapping(start, end, __pa(start),
+                              pgprot_val(PAGE_KERNEL), mmu_linear_psize,
+                              mmu_kernel_ssize);
 
        if (rc < 0) {
                int rc2 = htab_remove_mapping(start, end, mmu_linear_psize,
@@ -924,6 +931,11 @@ static void __init htab_initialize(void)
                DBG("creating mapping for region: %lx..%lx (prot: %lx)\n",
                    base, size, prot);
 
+               if ((base + size) >= H_VMALLOC_START) {
+                       pr_warn("Outisde the supported range\n");
+                       continue;
+               }
+
                BUG_ON(htab_bolt_mapping(base, base + size, __pa(base),
                                prot, mmu_linear_psize, mmu_kernel_ssize));
        }
index c08d49046a968971718af300959a90b790720086..d934de4e2b3a17f13a85be2c7acce1826df2f0e3 100644 (file)
@@ -112,9 +112,16 @@ int __meminit hash__vmemmap_create_mapping(unsigned long start,
                                       unsigned long page_size,
                                       unsigned long phys)
 {
-       int rc = htab_bolt_mapping(start, start + page_size, phys,
-                                  pgprot_val(PAGE_KERNEL),
-                                  mmu_vmemmap_psize, mmu_kernel_ssize);
+       int rc;
+
+       if ((start + page_size) >= H_VMEMMAP_END) {
+               pr_warn("Outisde the supported range\n");
+               return -1;
+       }
+
+       rc = htab_bolt_mapping(start, start + page_size, phys,
+                              pgprot_val(PAGE_KERNEL),
+                              mmu_vmemmap_psize, mmu_kernel_ssize);
        if (rc < 0) {
                int rc2 = htab_remove_mapping(start, start + page_size,
                                              mmu_vmemmap_psize,
index 4d9fa9e900d5ba924fe9173c4a2469e5d741663d..e6d5065b0bc818718a2fc793d623f092903ec029 100644 (file)
@@ -339,6 +339,12 @@ void __init radix_init_pgtable(void)
                 * page tables will be allocated within the range. No
                 * need or a node (which we don't have yet).
                 */
+
+               if ((reg->base + reg->size) >= RADIX_VMALLOC_START) {
+                       pr_warn("Outisde the supported range\n");
+                       continue;
+               }
+
                WARN_ON(create_physical_mapping(reg->base,
                                                reg->base + reg->size,
                                                -1));
@@ -895,6 +901,11 @@ static void __meminit remove_pagetable(unsigned long start, unsigned long end)
 
 int __meminit radix__create_section_mapping(unsigned long start, unsigned long end, int nid)
 {
+       if (end >= RADIX_VMALLOC_START) {
+               pr_warn("Outisde the supported range\n");
+               return -1;
+       }
+
        return create_physical_mapping(start, end, nid);
 }
 
@@ -922,6 +933,11 @@ int __meminit radix__vmemmap_create_mapping(unsigned long start,
        int nid = early_pfn_to_nid(phys >> PAGE_SHIFT);
        int ret;
 
+       if ((start + page_size) >= RADIX_VMEMMAP_END) {
+               pr_warn("Outisde the supported range\n");
+               return -1;
+       }
+
        ret = __map_kernel_page_nid(start, phys, __pgprot(flags), page_size, nid);
        BUG_ON(ret);
 
index 56068cac2a3cf52035620644bf52650055ffa093..72f58c076e26cccfee64dcfb3bc2d6a33fdff5c3 100644 (file)
@@ -121,6 +121,11 @@ void __iomem *__ioremap_at(phys_addr_t pa, void *ea, unsigned long size, pgprot_
        if (pgprot_val(prot) & H_PAGE_4K_PFN)
                return NULL;
 
+       if ((ea + size) >= (void *)IOREMAP_END) {
+               pr_warn("Outisde the supported range\n");
+               return NULL;
+       }
+
        WARN_ON(pa & ~PAGE_MASK);
        WARN_ON(((unsigned long)ea) & ~PAGE_MASK);
        WARN_ON(size & ~PAGE_MASK);